| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 1 | // Copyright (C) 2018 The Android Open Source Project | 
|  | 2 | // | 
|  | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 4 | // you may not use this file except in compliance with the License. | 
|  | 5 | // You may obtain a copy of the License at | 
|  | 6 | // | 
|  | 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 8 | // | 
|  | 9 | // Unless required by applicable law or agreed to in writing, software | 
|  | 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 12 | // See the License for the specific language governing permissions and | 
|  | 13 | // limitations under the License. | 
|  | 14 |  | 
|  | 15 | package bpf | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "fmt" | 
|  | 19 | "io" | 
| Ken Chen | 5372a24 | 2022-07-07 17:48:06 +0800 | [diff] [blame] | 20 | "path/filepath" | 
| Connor O'Brien | 3e739cf | 2022-08-17 15:45:52 -0700 | [diff] [blame] | 21 | "runtime" | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 22 | "strings" | 
|  | 23 |  | 
|  | 24 | "android/soong/android" | 
| Zi Wang | b3cb38c | 2022-09-23 16:36:11 -0700 | [diff] [blame] | 25 | "android/soong/bazel" | 
| Zi Wang | aa981ed | 2022-10-04 16:59:31 -0700 | [diff] [blame] | 26 | "android/soong/bazel/cquery" | 
| Connor O'Brien | 6a288bc | 2022-11-10 13:58:48 -0800 | [diff] [blame] | 27 | "android/soong/cc" | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 28 |  | 
|  | 29 | "github.com/google/blueprint" | 
| Connor O'Brien | 2573965 | 2021-12-02 20:09:45 -0800 | [diff] [blame] | 30 | "github.com/google/blueprint/proptools" | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 31 | ) | 
|  | 32 |  | 
|  | 33 | func init() { | 
| Paul Duffin | 12c7eb8 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 34 | registerBpfBuildComponents(android.InitRegistrationContext) | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 35 | pctx.Import("android/soong/cc/config") | 
| Connor O'Brien | 6a288bc | 2022-11-10 13:58:48 -0800 | [diff] [blame] | 36 | pctx.StaticVariable("relPwd", cc.PwdPrefix()) | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
|  | 39 | var ( | 
|  | 40 | pctx = android.NewPackageContext("android/soong/bpf") | 
|  | 41 |  | 
| Ramy Medhat | 8ea054a | 2020-01-27 14:19:44 -0500 | [diff] [blame] | 42 | ccRule = pctx.AndroidRemoteStaticRule("ccRule", android.RemoteRuleSupports{Goma: true}, | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 43 | blueprint.RuleParams{ | 
|  | 44 | Depfile:     "${out}.d", | 
|  | 45 | Deps:        blueprint.DepsGCC, | 
| Connor O'Brien | 3e739cf | 2022-08-17 15:45:52 -0700 | [diff] [blame] | 46 | Command:     "$relPwd $ccCmd --target=bpf -c $cFlags -MD -MF ${out}.d -o $out $in", | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 47 | CommandDeps: []string{"$ccCmd"}, | 
|  | 48 | }, | 
|  | 49 | "ccCmd", "cFlags") | 
| Connor O'Brien | 2573965 | 2021-12-02 20:09:45 -0800 | [diff] [blame] | 50 |  | 
|  | 51 | stripRule = pctx.AndroidStaticRule("stripRule", | 
|  | 52 | blueprint.RuleParams{ | 
|  | 53 | Command: `$stripCmd --strip-unneeded --remove-section=.rel.BTF ` + | 
|  | 54 | `--remove-section=.rel.BTF.ext --remove-section=.BTF.ext $in -o $out`, | 
|  | 55 | CommandDeps: []string{"$stripCmd"}, | 
|  | 56 | }, | 
|  | 57 | "stripCmd") | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 58 | ) | 
|  | 59 |  | 
| Paul Duffin | 12c7eb8 | 2021-02-24 18:51:54 +0000 | [diff] [blame] | 60 | func registerBpfBuildComponents(ctx android.RegistrationContext) { | 
|  | 61 | ctx.RegisterModuleType("bpf", BpfFactory) | 
|  | 62 | } | 
|  | 63 |  | 
|  | 64 | var PrepareForTestWithBpf = android.FixtureRegisterWithContext(registerBpfBuildComponents) | 
|  | 65 |  | 
| markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 66 | // BpfModule interface is used by the apex package to gather information from a bpf module. | 
|  | 67 | type BpfModule interface { | 
|  | 68 | android.Module | 
|  | 69 |  | 
|  | 70 | OutputFiles(tag string) (android.Paths, error) | 
| Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 71 |  | 
|  | 72 | // Returns the sub install directory if the bpf module is included by apex. | 
|  | 73 | SubDir() string | 
| markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 74 | } | 
|  | 75 |  | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 76 | type BpfProperties struct { | 
| Zi Wang | 4877c72 | 2022-08-11 18:05:13 +0000 | [diff] [blame] | 77 | // source paths to the files. | 
|  | 78 | Srcs []string `android:"path"` | 
|  | 79 |  | 
|  | 80 | // additional cflags that should be used to build the bpf variant of | 
|  | 81 | // the C/C++ module. | 
|  | 82 | Cflags []string | 
|  | 83 |  | 
|  | 84 | // directories (relative to the root of the source tree) that will | 
|  | 85 | // be added to the include paths using -I. | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 86 | Include_dirs []string | 
| Zi Wang | 4877c72 | 2022-08-11 18:05:13 +0000 | [diff] [blame] | 87 |  | 
|  | 88 | // optional subdirectory under which this module is installed into. | 
|  | 89 | Sub_dir string | 
|  | 90 |  | 
|  | 91 | // if set to true, generate BTF debug info for maps & programs. | 
|  | 92 | Btf *bool | 
|  | 93 |  | 
| Steven Moreland | 606c5e9 | 2019-12-12 14:23:42 -0800 | [diff] [blame] | 94 | Vendor *bool | 
|  | 95 |  | 
|  | 96 | VendorInternal bool `blueprint:"mutated"` | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 97 | } | 
|  | 98 |  | 
|  | 99 | type bpf struct { | 
|  | 100 | android.ModuleBase | 
| Zi Wang | b3cb38c | 2022-09-23 16:36:11 -0700 | [diff] [blame] | 101 | android.BazelModuleBase | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 102 |  | 
|  | 103 | properties BpfProperties | 
|  | 104 |  | 
|  | 105 | objs android.Paths | 
|  | 106 | } | 
|  | 107 |  | 
| Steven Moreland | 606c5e9 | 2019-12-12 14:23:42 -0800 | [diff] [blame] | 108 | var _ android.ImageInterface = (*bpf)(nil) | 
|  | 109 |  | 
|  | 110 | func (bpf *bpf) ImageMutatorBegin(ctx android.BaseModuleContext) {} | 
|  | 111 |  | 
|  | 112 | func (bpf *bpf) CoreVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 113 | return !proptools.Bool(bpf.properties.Vendor) | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | func (bpf *bpf) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 117 | return false | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 | func (bpf *bpf) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 121 | return false | 
|  | 122 | } | 
|  | 123 |  | 
|  | 124 | func (bpf *bpf) DebugRamdiskVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 125 | return false | 
|  | 126 | } | 
|  | 127 |  | 
|  | 128 | func (bpf *bpf) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool { | 
|  | 129 | return false | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | func (bpf *bpf) ExtraImageVariations(ctx android.BaseModuleContext) []string { | 
|  | 133 | if proptools.Bool(bpf.properties.Vendor) { | 
|  | 134 | return []string{"vendor"} | 
|  | 135 | } | 
|  | 136 | return nil | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | func (bpf *bpf) SetImageVariation(ctx android.BaseModuleContext, variation string, module android.Module) { | 
|  | 140 | bpf.properties.VendorInternal = variation == "vendor" | 
|  | 141 | } | 
|  | 142 |  | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 143 | func (bpf *bpf) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 144 | cflags := []string{ | 
|  | 145 | "-nostdlibinc", | 
| Kousik Kumar | fb0e251 | 2020-03-25 15:01:27 -0700 | [diff] [blame] | 146 |  | 
|  | 147 | // Make paths in deps files relative | 
|  | 148 | "-no-canonical-prefixes", | 
|  | 149 |  | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 150 | "-O2", | 
|  | 151 | "-isystem bionic/libc/include", | 
|  | 152 | "-isystem bionic/libc/kernel/uapi", | 
|  | 153 | // The architecture doesn't matter here, but asm/types.h is included by linux/types.h. | 
|  | 154 | "-isystem bionic/libc/kernel/uapi/asm-arm64", | 
|  | 155 | "-isystem bionic/libc/kernel/android/uapi", | 
| Motomu Utsumi | 4459155 | 2023-08-22 12:03:16 +0900 | [diff] [blame] | 156 | "-I       packages/modules/Connectivity/staticlibs/native/bpf_headers/include/bpf", | 
| Maciej Żenczykowski | 79f6f75 | 2020-02-18 15:38:36 -0800 | [diff] [blame] | 157 | // TODO(b/149785767): only give access to specific file with AID_* constants | 
|  | 158 | "-I       system/core/libcutils/include", | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 159 | "-I " + ctx.ModuleDir(), | 
|  | 160 | } | 
|  | 161 |  | 
|  | 162 | for _, dir := range android.PathsForSource(ctx, bpf.properties.Include_dirs) { | 
|  | 163 | cflags = append(cflags, "-I "+dir.String()) | 
|  | 164 | } | 
|  | 165 |  | 
|  | 166 | cflags = append(cflags, bpf.properties.Cflags...) | 
|  | 167 |  | 
| Connor O'Brien | 2573965 | 2021-12-02 20:09:45 -0800 | [diff] [blame] | 168 | if proptools.Bool(bpf.properties.Btf) { | 
|  | 169 | cflags = append(cflags, "-g") | 
| Connor O'Brien | 3e739cf | 2022-08-17 15:45:52 -0700 | [diff] [blame] | 170 | if runtime.GOOS != "darwin" { | 
|  | 171 | cflags = append(cflags, "-fdebug-prefix-map=/proc/self/cwd=") | 
|  | 172 | } | 
| Connor O'Brien | 2573965 | 2021-12-02 20:09:45 -0800 | [diff] [blame] | 173 | } | 
|  | 174 |  | 
| Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 175 | srcs := android.PathsForModuleSrc(ctx, bpf.properties.Srcs) | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 176 |  | 
|  | 177 | for _, src := range srcs { | 
| Ken Chen | 5372a24 | 2022-07-07 17:48:06 +0800 | [diff] [blame] | 178 | if strings.ContainsRune(filepath.Base(src.String()), '_') { | 
|  | 179 | ctx.ModuleErrorf("invalid character '_' in source name") | 
|  | 180 | } | 
| Connor O'Brien | 2573965 | 2021-12-02 20:09:45 -0800 | [diff] [blame] | 181 | obj := android.ObjPathWithExt(ctx, "unstripped", src, "o") | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 182 |  | 
|  | 183 | ctx.Build(pctx, android.BuildParams{ | 
| Colin Cross | 815daf9 | 2019-05-14 16:05:20 -0700 | [diff] [blame] | 184 | Rule:   ccRule, | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 185 | Input:  src, | 
|  | 186 | Output: obj, | 
|  | 187 | Args: map[string]string{ | 
|  | 188 | "cFlags": strings.Join(cflags, " "), | 
|  | 189 | "ccCmd":  "${config.ClangBin}/clang", | 
|  | 190 | }, | 
|  | 191 | }) | 
|  | 192 |  | 
| Connor O'Brien | 2573965 | 2021-12-02 20:09:45 -0800 | [diff] [blame] | 193 | if proptools.Bool(bpf.properties.Btf) { | 
|  | 194 | objStripped := android.ObjPathWithExt(ctx, "", src, "o") | 
|  | 195 | ctx.Build(pctx, android.BuildParams{ | 
| Steven Moreland | 606c5e9 | 2019-12-12 14:23:42 -0800 | [diff] [blame] | 196 | Rule:   stripRule, | 
|  | 197 | Input:  obj, | 
| Connor O'Brien | 2573965 | 2021-12-02 20:09:45 -0800 | [diff] [blame] | 198 | Output: objStripped, | 
|  | 199 | Args: map[string]string{ | 
|  | 200 | "stripCmd": "${config.ClangBin}/llvm-strip", | 
|  | 201 | }, | 
|  | 202 | }) | 
|  | 203 | bpf.objs = append(bpf.objs, objStripped.WithoutRel()) | 
|  | 204 | } else { | 
|  | 205 | bpf.objs = append(bpf.objs, obj.WithoutRel()) | 
|  | 206 | } | 
|  | 207 |  | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 208 | } | 
|  | 209 | } | 
|  | 210 |  | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 211 | func (bpf *bpf) AndroidMk() android.AndroidMkData { | 
|  | 212 | return android.AndroidMkData{ | 
|  | 213 | Custom: func(w io.Writer, name, prefix, moduleDir string, data android.AndroidMkData) { | 
|  | 214 | var names []string | 
|  | 215 | fmt.Fprintln(w) | 
|  | 216 | fmt.Fprintln(w, "LOCAL_PATH :=", moduleDir) | 
|  | 217 | fmt.Fprintln(w) | 
| Steven Moreland | 606c5e9 | 2019-12-12 14:23:42 -0800 | [diff] [blame] | 218 | var localModulePath string | 
|  | 219 | if bpf.properties.VendorInternal { | 
|  | 220 | localModulePath = "LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_ETC)/bpf" | 
|  | 221 | } else { | 
|  | 222 | localModulePath = "LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/bpf" | 
|  | 223 | } | 
| Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 224 | if len(bpf.properties.Sub_dir) > 0 { | 
|  | 225 | localModulePath += "/" + bpf.properties.Sub_dir | 
|  | 226 | } | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 227 | for _, obj := range bpf.objs { | 
|  | 228 | objName := name + "_" + obj.Base() | 
|  | 229 | names = append(names, objName) | 
| Sasha Smundak | 5c4729d | 2022-12-01 10:49:23 -0800 | [diff] [blame] | 230 | fmt.Fprintln(w, "include $(CLEAR_VARS)", " # bpf.bpf.obj") | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 231 | fmt.Fprintln(w, "LOCAL_MODULE := ", objName) | 
|  | 232 | fmt.Fprintln(w, "LOCAL_PREBUILT_MODULE_FILE :=", obj.String()) | 
|  | 233 | fmt.Fprintln(w, "LOCAL_MODULE_STEM :=", obj.Base()) | 
|  | 234 | fmt.Fprintln(w, "LOCAL_MODULE_CLASS := ETC") | 
| Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 235 | fmt.Fprintln(w, localModulePath) | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 236 | fmt.Fprintln(w, "include $(BUILD_PREBUILT)") | 
|  | 237 | fmt.Fprintln(w) | 
|  | 238 | } | 
| Sasha Smundak | 5c4729d | 2022-12-01 10:49:23 -0800 | [diff] [blame] | 239 | fmt.Fprintln(w, "include $(CLEAR_VARS)", " # bpf.bpf") | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 240 | fmt.Fprintln(w, "LOCAL_MODULE := ", name) | 
| Sasha Smundak | dcb6129 | 2022-12-08 10:41:33 -0800 | [diff] [blame] | 241 | android.AndroidMkEmitAssignList(w, "LOCAL_REQUIRED_MODULES", names) | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 242 | fmt.Fprintln(w, "include $(BUILD_PHONY_PACKAGE)") | 
|  | 243 | }, | 
|  | 244 | } | 
|  | 245 | } | 
|  | 246 |  | 
| Zi Wang | aa981ed | 2022-10-04 16:59:31 -0700 | [diff] [blame] | 247 | var _ android.MixedBuildBuildable = (*bpf)(nil) | 
|  | 248 |  | 
|  | 249 | func (bpf *bpf) IsMixedBuildSupported(ctx android.BaseModuleContext) bool { | 
|  | 250 | return true | 
|  | 251 | } | 
|  | 252 |  | 
|  | 253 | func (bpf *bpf) QueueBazelCall(ctx android.BaseModuleContext) { | 
|  | 254 | bazelCtx := ctx.Config().BazelContext | 
|  | 255 | bazelCtx.QueueBazelRequest( | 
|  | 256 | bpf.GetBazelLabel(ctx, bpf), | 
|  | 257 | cquery.GetOutputFiles, | 
|  | 258 | android.GetConfigKey(ctx)) | 
|  | 259 | } | 
|  | 260 |  | 
|  | 261 | func (bpf *bpf) ProcessBazelQueryResponse(ctx android.ModuleContext) { | 
|  | 262 | bazelCtx := ctx.Config().BazelContext | 
|  | 263 | objPaths, err := bazelCtx.GetOutputFiles(bpf.GetBazelLabel(ctx, bpf), android.GetConfigKey(ctx)) | 
|  | 264 | if err != nil { | 
|  | 265 | ctx.ModuleErrorf(err.Error()) | 
|  | 266 | return | 
|  | 267 | } | 
|  | 268 |  | 
|  | 269 | bazelOuts := android.Paths{} | 
|  | 270 | for _, p := range objPaths { | 
|  | 271 | bazelOuts = append(bazelOuts, android.PathForBazelOut(ctx, p)) | 
|  | 272 | } | 
|  | 273 | bpf.objs = bazelOuts | 
|  | 274 | } | 
|  | 275 |  | 
| Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 276 | // Implements OutputFileFileProducer interface so that the obj output can be used in the data property | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 277 | // of other modules. | 
| Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 278 | func (bpf *bpf) OutputFiles(tag string) (android.Paths, error) { | 
|  | 279 | switch tag { | 
|  | 280 | case "": | 
|  | 281 | return bpf.objs, nil | 
|  | 282 | default: | 
|  | 283 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) | 
|  | 284 | } | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 285 | } | 
|  | 286 |  | 
| Ken Chen | fad7f9d | 2021-11-10 22:02:57 +0800 | [diff] [blame] | 287 | func (bpf *bpf) SubDir() string { | 
|  | 288 | return bpf.properties.Sub_dir | 
|  | 289 | } | 
|  | 290 |  | 
| Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 291 | var _ android.OutputFileProducer = (*bpf)(nil) | 
| Jaewoong Jung | 5f3fb4b | 2018-12-13 15:01:46 -0800 | [diff] [blame] | 292 |  | 
| markchien | 2f59ec9 | 2020-09-02 16:23:38 +0800 | [diff] [blame] | 293 | func BpfFactory() android.Module { | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 294 | module := &bpf{} | 
|  | 295 |  | 
|  | 296 | module.AddProperties(&module.properties) | 
|  | 297 |  | 
|  | 298 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibCommon) | 
| Zi Wang | b3cb38c | 2022-09-23 16:36:11 -0700 | [diff] [blame] | 299 | android.InitBazelModule(module) | 
| Colin Cross | 3840659 | 2018-05-17 11:17:01 -0700 | [diff] [blame] | 300 | return module | 
|  | 301 | } | 
| Zi Wang | b3cb38c | 2022-09-23 16:36:11 -0700 | [diff] [blame] | 302 |  | 
|  | 303 | type bazelBpfAttributes struct { | 
|  | 304 | Srcs              bazel.LabelListAttribute | 
|  | 305 | Copts             bazel.StringListAttribute | 
|  | 306 | Absolute_includes bazel.StringListAttribute | 
|  | 307 | Btf               *bool | 
|  | 308 | // TODO(b/249528391): Add support for sub_dir | 
|  | 309 | } | 
|  | 310 |  | 
|  | 311 | // bpf bp2build converter | 
| Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 312 | func (b *bpf) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { | 
| Zi Wang | b3cb38c | 2022-09-23 16:36:11 -0700 | [diff] [blame] | 313 | if ctx.ModuleType() != "bpf" { | 
|  | 314 | return | 
|  | 315 | } | 
|  | 316 |  | 
|  | 317 | srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, b.properties.Srcs)) | 
|  | 318 | copts := bazel.MakeStringListAttribute(b.properties.Cflags) | 
|  | 319 | absolute_includes := bazel.MakeStringListAttribute(b.properties.Include_dirs) | 
|  | 320 | btf := b.properties.Btf | 
|  | 321 |  | 
|  | 322 | attrs := bazelBpfAttributes{ | 
|  | 323 | Srcs:              srcs, | 
|  | 324 | Copts:             copts, | 
|  | 325 | Absolute_includes: absolute_includes, | 
|  | 326 | Btf:               btf, | 
|  | 327 | } | 
|  | 328 | props := bazel.BazelTargetModuleProperties{ | 
|  | 329 | Rule_class:        "bpf", | 
|  | 330 | Bzl_load_location: "//build/bazel/rules/bpf:bpf.bzl", | 
|  | 331 | } | 
|  | 332 |  | 
|  | 333 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: b.Name()}, &attrs) | 
|  | 334 | } |