blob: c449a87eaba4f6a37cd688c83b5fe56f63c1859d [file] [log] [blame]
Colin Cross38f794e2017-09-07 10:53:07 -07001// Copyright 2017 Google Inc. All rights reserved.
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
15package android
16
Colin Cross19878da2019-03-28 14:45:07 -070017import (
Spandan Dasc53767e2023-08-03 23:02:26 +000018 "path/filepath"
Colin Cross19878da2019-03-28 14:45:07 -070019 "strings"
Spandan Dasfc6e6452023-08-29 23:55:49 +000020 "sync"
Colin Cross19878da2019-03-28 14:45:07 -070021
Yu Liu2d136142022-08-18 14:46:13 -070022 "android/soong/bazel"
23
Colin Crossfe17f6f2019-03-28 19:30:56 -070024 "github.com/google/blueprint"
Colin Cross19878da2019-03-28 14:45:07 -070025 "github.com/google/blueprint/proptools"
26)
27
Liz Kammer12615db2021-09-28 09:19:17 -040028const (
29 canonicalPathFromRootDefault = true
30)
31
Colin Cross38f794e2017-09-07 10:53:07 -070032// TODO(ccross): protos are often used to communicate between multiple modules. If the only
33// way to convert a proto to source is to reference it as a source file, and external modules cannot
34// reference source files in other modules, then every module that owns a proto file will need to
35// export a library for every type of external user (lite vs. full, c vs. c++ vs. java). It would
36// be better to support a proto module type that exported a proto file along with some include dirs,
37// and then external modules could depend on the proto module but use their own settings to
38// generate the source.
39
Colin Cross19878da2019-03-28 14:45:07 -070040type ProtoFlags struct {
41 Flags []string
42 CanonicalPathFromRoot bool
43 Dir ModuleGenPath
44 SubDir ModuleGenPath
45 OutTypeFlag string
46 OutParams []string
Colin Crossfe17f6f2019-03-28 19:30:56 -070047 Deps Paths
48}
49
50type protoDependencyTag struct {
51 blueprint.BaseDependencyTag
52 name string
53}
54
55var ProtoPluginDepTag = protoDependencyTag{name: "plugin"}
56
57func ProtoDeps(ctx BottomUpMutatorContext, p *ProtoProperties) {
58 if String(p.Proto.Plugin) != "" && String(p.Proto.Type) != "" {
59 ctx.ModuleErrorf("only one of proto.type and proto.plugin can be specified.")
60 }
61
62 if plugin := String(p.Proto.Plugin); plugin != "" {
Colin Cross0f7d2ef2019-10-16 11:03:10 -070063 ctx.AddFarVariationDependencies(ctx.Config().BuildOSTarget.Variations(),
64 ProtoPluginDepTag, "protoc-gen-"+plugin)
Colin Crossfe17f6f2019-03-28 19:30:56 -070065 }
Colin Cross19878da2019-03-28 14:45:07 -070066}
Colin Crossa3b25002017-12-15 13:41:30 -080067
Colin Cross19878da2019-03-28 14:45:07 -070068func GetProtoFlags(ctx ModuleContext, p *ProtoProperties) ProtoFlags {
Colin Crossfe17f6f2019-03-28 19:30:56 -070069 var flags []string
70 var deps Paths
71
Colin Cross38f794e2017-09-07 10:53:07 -070072 if len(p.Proto.Local_include_dirs) > 0 {
73 localProtoIncludeDirs := PathsForModuleSrc(ctx, p.Proto.Local_include_dirs)
Colin Crossfe17f6f2019-03-28 19:30:56 -070074 flags = append(flags, JoinWithPrefix(localProtoIncludeDirs.Strings(), "-I"))
Colin Cross38f794e2017-09-07 10:53:07 -070075 }
76 if len(p.Proto.Include_dirs) > 0 {
77 rootProtoIncludeDirs := PathsForSource(ctx, p.Proto.Include_dirs)
Colin Crossfe17f6f2019-03-28 19:30:56 -070078 flags = append(flags, JoinWithPrefix(rootProtoIncludeDirs.Strings(), "-I"))
79 }
80
81 ctx.VisitDirectDepsWithTag(ProtoPluginDepTag, func(dep Module) {
82 if hostTool, ok := dep.(HostToolProvider); !ok || !hostTool.HostToolPath().Valid() {
83 ctx.PropertyErrorf("proto.plugin", "module %q is not a host tool provider",
84 ctx.OtherModuleName(dep))
85 } else {
86 plugin := String(p.Proto.Plugin)
87 deps = append(deps, hostTool.HostToolPath().Path())
88 flags = append(flags, "--plugin=protoc-gen-"+plugin+"="+hostTool.HostToolPath().String())
89 }
90 })
91
92 var protoOutFlag string
93 if plugin := String(p.Proto.Plugin); plugin != "" {
94 protoOutFlag = "--" + plugin + "_out"
Colin Cross38f794e2017-09-07 10:53:07 -070095 }
96
Colin Cross19878da2019-03-28 14:45:07 -070097 return ProtoFlags{
Colin Crossfe17f6f2019-03-28 19:30:56 -070098 Flags: flags,
99 Deps: deps,
100 OutTypeFlag: protoOutFlag,
Liz Kammer12615db2021-09-28 09:19:17 -0400101 CanonicalPathFromRoot: proptools.BoolDefault(p.Proto.Canonical_path_from_root, canonicalPathFromRootDefault),
Colin Cross19878da2019-03-28 14:45:07 -0700102 Dir: PathForModuleGen(ctx, "proto"),
103 SubDir: PathForModuleGen(ctx, "proto", ctx.ModuleDir()),
Dan Willemsenab9f4262018-02-14 13:58:34 -0800104 }
Colin Cross38f794e2017-09-07 10:53:07 -0700105}
106
107type ProtoProperties struct {
108 Proto struct {
109 // Proto generator type. C++: full or lite. Java: micro, nano, stream, or lite.
110 Type *string `android:"arch_variant"`
111
Colin Crossfe17f6f2019-03-28 19:30:56 -0700112 // Proto plugin to use as the generator. Must be a cc_binary_host module.
113 Plugin *string `android:"arch_variant"`
114
Colin Cross38f794e2017-09-07 10:53:07 -0700115 // list of directories that will be added to the protoc include paths.
116 Include_dirs []string
117
118 // list of directories relative to the bp file that will
119 // be added to the protoc include paths.
120 Local_include_dirs []string
Dan Willemsenab9f4262018-02-14 13:58:34 -0800121
122 // whether to identify the proto files from the root of the
123 // source tree (the original method in Android, useful for
124 // android-specific protos), or relative from where they were
125 // specified (useful for external/third party protos).
126 //
127 // This defaults to true today, but is expected to default to
128 // false in the future.
129 Canonical_path_from_root *bool
Colin Cross38f794e2017-09-07 10:53:07 -0700130 } `android:"arch_variant"`
131}
Colin Cross19878da2019-03-28 14:45:07 -0700132
Colin Crossf1a035e2020-11-16 17:32:30 -0800133func ProtoRule(rule *RuleBuilder, protoFile Path, flags ProtoFlags, deps Paths,
Colin Cross19878da2019-03-28 14:45:07 -0700134 outDir WritablePath, depFile WritablePath, outputs WritablePaths) {
135
136 var protoBase string
137 if flags.CanonicalPathFromRoot {
138 protoBase = "."
139 } else {
140 rel := protoFile.Rel()
141 protoBase = strings.TrimSuffix(protoFile.String(), rel)
142 }
143
144 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800145 BuiltTool("aprotoc").
Colin Cross19878da2019-03-28 14:45:07 -0700146 FlagWithArg(flags.OutTypeFlag+"=", strings.Join(flags.OutParams, ",")+":"+outDir.String()).
147 FlagWithDepFile("--dependency_out=", depFile).
148 FlagWithArg("-I ", protoBase).
149 Flags(flags.Flags).
150 Input(protoFile).
151 Implicits(deps).
152 ImplicitOutputs(outputs)
153
154 rule.Command().
Colin Crossf1a035e2020-11-16 17:32:30 -0800155 BuiltTool("dep_fixer").Flag(depFile.String())
Colin Cross19878da2019-03-28 14:45:07 -0700156}
Liz Kammer12615db2021-09-28 09:19:17 -0400157
158// Bp2buildProtoInfo contains information necessary to pass on to language specific conversion.
159type Bp2buildProtoInfo struct {
Spandan Dasec39d512023-08-15 22:08:18 +0000160 Type *string
161 Proto_libs bazel.LabelList
162 Transitive_proto_libs bazel.LabelList
Liz Kammer12615db2021-09-28 09:19:17 -0400163}
164
Yu Liu2aa806b2022-09-01 11:54:47 -0700165type ProtoAttrs struct {
Liz Kammer12615db2021-09-28 09:19:17 -0400166 Srcs bazel.LabelListAttribute
Spandan Dasc53767e2023-08-03 23:02:26 +0000167 Import_prefix *string
Liz Kammer12615db2021-09-28 09:19:17 -0400168 Strip_import_prefix *string
Yu Liu2d136142022-08-18 14:46:13 -0700169 Deps bazel.LabelListAttribute
170}
171
172// For each package in the include_dirs property a proto_library target should
173// be added to the BUILD file in that package and a mapping should be added here
174var includeDirsToProtoDeps = map[string]string{
175 "external/protobuf/src": "//external/protobuf:libprotobuf-proto",
Liz Kammer12615db2021-09-28 09:19:17 -0400176}
177
Spandan Dasc53767e2023-08-03 23:02:26 +0000178// Partitions srcs by the pkg it is in
179// srcs has been created using `TransformSubpackagePaths`
180// This function uses existence of Android.bp/BUILD files to create a label that is compatible with the package structure of bp2build workspace
181func partitionSrcsByPackage(currentDir string, srcs bazel.LabelList) map[string]bazel.LabelList {
182 getPackageFromLabel := func(label string) string {
183 // Remove any preceding //
184 label = strings.TrimPrefix(label, "//")
185 split := strings.Split(label, ":")
186 if len(split) == 1 {
187 // e.g. foo.proto
188 return currentDir
189 } else if split[0] == "" {
190 // e.g. :foo.proto
191 return currentDir
192 } else {
193 return split[0]
194 }
195 }
196
197 pkgToSrcs := map[string]bazel.LabelList{}
198 for _, src := range srcs.Includes {
199 pkg := getPackageFromLabel(src.Label)
200 list := pkgToSrcs[pkg]
201 list.Add(&src)
202 pkgToSrcs[pkg] = list
203 }
204 return pkgToSrcs
205}
206
Liz Kammer12615db2021-09-28 09:19:17 -0400207// Bp2buildProtoProperties converts proto properties, creating a proto_library and returning the
208// information necessary for language-specific handling.
Sam Delmericoc7681022022-02-04 21:01:20 +0000209func Bp2buildProtoProperties(ctx Bp2buildMutatorContext, m *ModuleBase, srcs bazel.LabelListAttribute) (Bp2buildProtoInfo, bool) {
Liz Kammer12615db2021-09-28 09:19:17 -0400210 var info Bp2buildProtoInfo
211 if srcs.IsEmpty() {
212 return info, false
213 }
Liz Kammer12615db2021-09-28 09:19:17 -0400214
Yu Liu2aa806b2022-09-01 11:54:47 -0700215 var protoLibraries bazel.LabelList
Spandan Dasec39d512023-08-15 22:08:18 +0000216 var transitiveProtoLibraries bazel.LabelList
Yu Liu2aa806b2022-09-01 11:54:47 -0700217 var directProtoSrcs bazel.LabelList
Liz Kammer12615db2021-09-28 09:19:17 -0400218
Yu Liu2aa806b2022-09-01 11:54:47 -0700219 // For filegroups that should be converted to proto_library just collect the
220 // labels of converted proto_library targets.
221 for _, protoSrc := range srcs.Value.Includes {
222 src := protoSrc.OriginalModuleName
223 if fg, ok := ToFileGroupAsLibrary(ctx, src); ok &&
224 fg.ShouldConvertToProtoLibrary(ctx) {
225 protoLibraries.Add(&bazel.Label{
226 Label: fg.GetProtoLibraryLabel(ctx),
227 })
228 } else {
229 directProtoSrcs.Add(&protoSrc)
Liz Kammer12615db2021-09-28 09:19:17 -0400230 }
231 }
232
Spandan Dasc53767e2023-08-03 23:02:26 +0000233 name := m.Name() + "_proto"
234
235 depsFromFilegroup := protoLibraries
Liz Kammer7dc6bcb2023-08-10 12:51:59 -0400236 var canonicalPathFromRoot bool
Yu Liu2aa806b2022-09-01 11:54:47 -0700237
238 if len(directProtoSrcs.Includes) > 0 {
Spandan Dasc53767e2023-08-03 23:02:26 +0000239 pkgToSrcs := partitionSrcsByPackage(ctx.ModuleDir(), directProtoSrcs)
Spandan Dasec39d512023-08-15 22:08:18 +0000240 protoIncludeDirs := []string{}
Spandan Dasc53767e2023-08-03 23:02:26 +0000241 for _, pkg := range SortedStringKeys(pkgToSrcs) {
242 srcs := pkgToSrcs[pkg]
243 attrs := ProtoAttrs{
244 Srcs: bazel.MakeLabelListAttribute(srcs),
245 }
246 attrs.Deps.Append(bazel.MakeLabelListAttribute(depsFromFilegroup))
Yu Liu2aa806b2022-09-01 11:54:47 -0700247
Spandan Dasc53767e2023-08-03 23:02:26 +0000248 for axis, configToProps := range m.GetArchVariantProperties(ctx, &ProtoProperties{}) {
249 for _, rawProps := range configToProps {
250 var props *ProtoProperties
251 var ok bool
252 if props, ok = rawProps.(*ProtoProperties); !ok {
253 ctx.ModuleErrorf("Could not cast ProtoProperties to expected type")
Yu Liu2aa806b2022-09-01 11:54:47 -0700254 }
Spandan Dasc53767e2023-08-03 23:02:26 +0000255 if axis == bazel.NoConfigAxis {
256 info.Type = props.Proto.Type
Yu Liu2aa806b2022-09-01 11:54:47 -0700257
Liz Kammer7dc6bcb2023-08-10 12:51:59 -0400258 canonicalPathFromRoot = proptools.BoolDefault(props.Proto.Canonical_path_from_root, canonicalPathFromRootDefault)
259 if !canonicalPathFromRoot {
Spandan Dasc53767e2023-08-03 23:02:26 +0000260 // an empty string indicates to strips the package path
261 path := ""
262 attrs.Strip_import_prefix = &path
Yu Liu2aa806b2022-09-01 11:54:47 -0700263 }
Spandan Dasc53767e2023-08-03 23:02:26 +0000264
265 for _, dir := range props.Proto.Include_dirs {
266 if dep, ok := includeDirsToProtoDeps[dir]; ok {
267 attrs.Deps.Add(bazel.MakeLabelAttribute(dep))
268 } else {
Spandan Dasec39d512023-08-15 22:08:18 +0000269 protoIncludeDirs = append(protoIncludeDirs, dir)
Spandan Dasc53767e2023-08-03 23:02:26 +0000270 }
271 }
Spandan Das4e5a1942023-08-22 19:20:39 +0000272
273 // proto.local_include_dirs are similar to proto.include_dirs, except that it is relative to the module directory
274 for _, dir := range props.Proto.Local_include_dirs {
275 relativeToTop := pathForModuleSrc(ctx, dir).String()
276 protoIncludeDirs = append(protoIncludeDirs, relativeToTop)
277 }
278
Spandan Dasc53767e2023-08-03 23:02:26 +0000279 } else if props.Proto.Type != info.Type && props.Proto.Type != nil {
280 ctx.ModuleErrorf("Cannot handle arch-variant types for protos at this time.")
Yu Liu2aa806b2022-09-01 11:54:47 -0700281 }
Yu Liu2aa806b2022-09-01 11:54:47 -0700282 }
283 }
Spandan Dasc53767e2023-08-03 23:02:26 +0000284
Spandan Dascb847632023-08-22 19:24:07 +0000285 if p, ok := m.module.(PkgPathInterface); ok && p.PkgPath(ctx) != nil {
286 // python_library with pkg_path
287 // proto_library for this module should have the pkg_path as the import_prefix
288 attrs.Import_prefix = p.PkgPath(ctx)
289 attrs.Strip_import_prefix = proptools.StringPtr("")
290 }
291
Chris Parsons6666d0f2023-09-22 16:21:53 +0000292 tags := ApexAvailableTagsWithoutTestApexes(ctx, ctx.Module())
Spandan Dasc53767e2023-08-03 23:02:26 +0000293
Liz Kammer7dc6bcb2023-08-10 12:51:59 -0400294 moduleDir := ctx.ModuleDir()
295 if !canonicalPathFromRoot {
296 // Since we are creating the proto_library in a subpackage, set the import_prefix relative to the current package
297 if rel, err := filepath.Rel(moduleDir, pkg); err != nil {
298 ctx.ModuleErrorf("Could not get relative path for %v %v", pkg, err)
299 } else if rel != "." {
300 attrs.Import_prefix = &rel
301 }
Spandan Dasc53767e2023-08-03 23:02:26 +0000302 }
303
Spandan Das215adb42023-08-14 16:52:24 +0000304 // TODO - b/246997908: Handle potential orphaned proto_library targets
305 // To create proto_library targets in the same package, we split the .proto files
306 // This means that if a proto_library in a subpackage imports another proto_library from the parent package
307 // (or a different subpackage), it will not find it.
308 // The CcProtoGen action itself runs fine because we construct the correct ProtoInfo,
309 // but the FileDescriptorSet of each proto_library might not be compile-able
Spandan Dase0f2ed52023-08-22 18:19:44 +0000310 //
311 // Add manual tag if either
312 // 1. .proto files are in more than one package
313 // 2. proto.include_dirs is not empty
314 if len(SortedStringKeys(pkgToSrcs)) > 1 || len(protoIncludeDirs) > 0 {
Spandan Das215adb42023-08-14 16:52:24 +0000315 tags.Append(bazel.MakeStringListAttribute([]string{"manual"}))
316 }
Spandan Dase0f2ed52023-08-22 18:19:44 +0000317
Spandan Dasc53767e2023-08-03 23:02:26 +0000318 ctx.CreateBazelTargetModule(
319 bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
320 CommonAttributes{Name: name, Dir: proptools.StringPtr(pkg), Tags: tags},
321 &attrs,
322 )
323
324 l := ""
Liz Kammer7dc6bcb2023-08-10 12:51:59 -0400325 if pkg == moduleDir { // same package that the original module lives in
Spandan Dasc53767e2023-08-03 23:02:26 +0000326 l = ":" + name
327 } else {
328 l = "//" + pkg + ":" + name
329 }
330 protoLibraries.Add(&bazel.Label{
331 Label: l,
332 })
Yu Liu2aa806b2022-09-01 11:54:47 -0700333 }
Spandan Dasf26ee152023-08-24 23:21:04 +0000334 // Partitioning by packages can create dupes of protoIncludeDirs, so dedupe it first.
335 protoLibrariesInIncludeDir := createProtoLibraryTargetsForIncludeDirs(ctx, SortedUniqueStrings(protoIncludeDirs))
Spandan Dasec39d512023-08-15 22:08:18 +0000336 transitiveProtoLibraries.Append(protoLibrariesInIncludeDir)
Yu Liu2aa806b2022-09-01 11:54:47 -0700337 }
338
339 info.Proto_libs = protoLibraries
Spandan Dasec39d512023-08-15 22:08:18 +0000340 info.Transitive_proto_libs = transitiveProtoLibraries
Liz Kammer12615db2021-09-28 09:19:17 -0400341
342 return info, true
343}
Spandan Dasec39d512023-08-15 22:08:18 +0000344
Spandan Dascb847632023-08-22 19:24:07 +0000345// PkgPathInterface is used as a type assertion in bp2build to get pkg_path property of python_library_host
346type PkgPathInterface interface {
347 PkgPath(ctx BazelConversionContext) *string
348}
349
Spandan Dasec39d512023-08-15 22:08:18 +0000350var (
351 protoIncludeDirGeneratedSuffix = ".include_dir_bp2build_generated_proto"
352 protoIncludeDirsBp2buildKey = NewOnceKey("protoIncludeDirsBp2build")
353)
354
Spandan Das43dfeb62023-08-30 22:20:54 +0000355func getProtoIncludeDirsBp2build(config Config) *sync.Map {
Spandan Dasec39d512023-08-15 22:08:18 +0000356 return config.Once(protoIncludeDirsBp2buildKey, func() interface{} {
Spandan Das43dfeb62023-08-30 22:20:54 +0000357 return &sync.Map{}
358 }).(*sync.Map)
Spandan Dasec39d512023-08-15 22:08:18 +0000359}
360
361// key for dynamically creating proto_library per proto.include_dirs
362type protoIncludeDirKey struct {
363 dir string
364 subpackgeInDir string
365}
366
367// createProtoLibraryTargetsForIncludeDirs creates additional proto_library targets for .proto files in includeDirs
368// Since Bazel imposes a constratint that the proto_library must be in the same package as the .proto file, this function
369// might create the targets in a subdirectory of `includeDir`
370// Returns the labels of the proto_library targets
371func createProtoLibraryTargetsForIncludeDirs(ctx Bp2buildMutatorContext, includeDirs []string) bazel.LabelList {
372 var ret bazel.LabelList
373 for _, dir := range includeDirs {
374 if exists, _, _ := ctx.Config().fs.Exists(filepath.Join(dir, "Android.bp")); !exists {
375 ctx.ModuleErrorf("TODO: Add support for proto.include_dir: %v. This directory does not contain an Android.bp file", dir)
376 }
377 dirMap := getProtoIncludeDirsBp2build(ctx.Config())
378 // Find all proto file targets in this dir
379 protoLabelsInDir := BazelLabelForSrcPatternExcludes(ctx, dir, "**/*.proto", []string{})
380 // Partition the labels by package and subpackage(s)
381 protoLabelelsPartitionedByPkg := partitionSrcsByPackage(dir, protoLabelsInDir)
382 for _, pkg := range SortedStringKeys(protoLabelelsPartitionedByPkg) {
383 label := strings.ReplaceAll(dir, "/", ".") + protoIncludeDirGeneratedSuffix
384 ret.Add(&bazel.Label{
385 Label: "//" + pkg + ":" + label,
386 })
387 key := protoIncludeDirKey{dir: dir, subpackgeInDir: pkg}
Spandan Das43dfeb62023-08-30 22:20:54 +0000388 if _, exists := dirMap.LoadOrStore(key, true); exists {
Spandan Dasec39d512023-08-15 22:08:18 +0000389 // A proto_library has already been created for this package relative to this include dir
390 continue
391 }
Spandan Dasec39d512023-08-15 22:08:18 +0000392 srcs := protoLabelelsPartitionedByPkg[pkg]
393 rel, err := filepath.Rel(dir, pkg)
394 if err != nil {
395 ctx.ModuleErrorf("Could not create a proto_library in pkg %v due to %v\n", pkg, err)
396 }
397 // Create proto_library
398 attrs := ProtoAttrs{
399 Srcs: bazel.MakeLabelListAttribute(srcs),
400 Strip_import_prefix: proptools.StringPtr(""),
401 }
402 if rel != "." {
403 attrs.Import_prefix = proptools.StringPtr(rel)
404 }
Spandan Dasf26ee152023-08-24 23:21:04 +0000405
406 // If a specific directory is listed in proto.include_dirs of two separate modules (one host-specific and another device-specific),
407 // we do not want to create the proto_library with target_compatible_with of the first visited of these two modules
408 // As a workarounds, delete `target_compatible_with`
409 alwaysEnabled := bazel.BoolAttribute{}
410 alwaysEnabled.Value = proptools.BoolPtr(true)
Spandan Dasab29f572023-09-01 19:43:56 +0000411 // Add android and linux explicitly so that fillcommonbp2buildmoduleattrs can override these configs
412 // When we extend b support for other os'es (darwin/windows), we should add those configs here as well
413 alwaysEnabled.SetSelectValue(bazel.OsConfigurationAxis, bazel.OsAndroid, proptools.BoolPtr(true))
414 alwaysEnabled.SetSelectValue(bazel.OsConfigurationAxis, bazel.OsLinux, proptools.BoolPtr(true))
415
Spandan Dasf26ee152023-08-24 23:21:04 +0000416 ctx.CreateBazelTargetModuleWithRestrictions(
Spandan Dasec39d512023-08-15 22:08:18 +0000417 bazel.BazelTargetModuleProperties{Rule_class: "proto_library"},
418 CommonAttributes{
419 Name: label,
420 Dir: proptools.StringPtr(pkg),
421 // This proto_library is used to construct a ProtoInfo
422 // But it might not be buildable on its own
423 Tags: bazel.MakeStringListAttribute([]string{"manual"}),
424 },
425 &attrs,
Spandan Dasf26ee152023-08-24 23:21:04 +0000426 alwaysEnabled,
Spandan Dasec39d512023-08-15 22:08:18 +0000427 )
428 }
429 }
430 return ret
431}