Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 1 | // Copyright 2020 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 rust |
| 16 | |
| 17 | import ( |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 18 | "fmt" |
| 19 | "strings" |
| 20 | |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 21 | "android/soong/android" |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 22 | "android/soong/bazel" |
| 23 | |
| 24 | "github.com/google/blueprint/proptools" |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | var ( |
| 28 | defaultProtobufFlags = []string{""} |
| 29 | ) |
| 30 | |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 31 | const ( |
| 32 | grpcSuffix = "_grpc" |
| 33 | ) |
| 34 | |
Ivan Lozano | 6a3d1e9 | 2020-11-02 15:06:26 -0500 | [diff] [blame] | 35 | type PluginType int |
| 36 | |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 37 | func init() { |
| 38 | android.RegisterModuleType("rust_protobuf", RustProtobufFactory) |
| 39 | android.RegisterModuleType("rust_protobuf_host", RustProtobufHostFactory) |
| 40 | } |
| 41 | |
| 42 | var _ SourceProvider = (*protobufDecorator)(nil) |
| 43 | |
| 44 | type ProtobufProperties struct { |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 45 | // List of relative paths to proto files that will be used to generate the source. |
| 46 | // Either this or grpc_protos must be defined. |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 47 | Protos []string `android:"path,arch_variant"` |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 48 | |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 49 | // List of relative paths to GRPC-containing proto files that will be used to generate the source. |
| 50 | // Either this or protos must be defined. |
| 51 | Grpc_protos []string `android:"path,arch_variant"` |
| 52 | |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 53 | // List of additional flags to pass to aprotoc |
| 54 | Proto_flags []string `android:"arch_variant"` |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 55 | |
| 56 | // List of libraries which export include paths required for this module |
Ivan Lozano | 9b44383 | 2020-11-17 13:39:30 -0500 | [diff] [blame] | 57 | Header_libs []string `android:"arch_variant,variant_prepend"` |
Jeff Vander Stoep | c1490ec | 2023-04-24 11:28:25 +0200 | [diff] [blame] | 58 | |
| 59 | // Use protobuf version 3.x. This will be deleted once we migrate all current users |
| 60 | // of protobuf off of 2.x. |
| 61 | Use_protobuf3 *bool |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | type protobufDecorator struct { |
| 65 | *BaseSourceProvider |
| 66 | |
| 67 | Properties ProtobufProperties |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 68 | protoNames []string |
| 69 | grpcNames []string |
| 70 | |
| 71 | grpcProtoFlags android.ProtoFlags |
| 72 | protoFlags android.ProtoFlags |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Jeff Vander Stoep | c1490ec | 2023-04-24 11:28:25 +0200 | [diff] [blame] | 75 | func (proto *protobufDecorator) useProtobuf3() bool { |
| 76 | return Bool(proto.Properties.Use_protobuf3) |
| 77 | } |
| 78 | |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 79 | func (proto *protobufDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) android.Path { |
| 80 | var protoFlags android.ProtoFlags |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 81 | var grpcProtoFlags android.ProtoFlags |
| 82 | var commonProtoFlags []string |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 83 | |
Ivan Lozano | 6a3d1e9 | 2020-11-02 15:06:26 -0500 | [diff] [blame] | 84 | outDir := android.PathForModuleOut(ctx) |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 85 | protoFiles := android.PathsForModuleSrc(ctx, proto.Properties.Protos) |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 86 | grpcFiles := android.PathsForModuleSrc(ctx, proto.Properties.Grpc_protos) |
Jeff Vander Stoep | c1490ec | 2023-04-24 11:28:25 +0200 | [diff] [blame] | 87 | |
| 88 | // For now protobuf2 (the deprecated version) remains the default. This will change in the |
| 89 | // future as we update the various users. |
Jeff Vander Stoep | 91c0466 | 2023-03-22 15:09:00 +0100 | [diff] [blame] | 90 | protoPluginPath := ctx.Config().HostToolPath(ctx, "protoc-gen-rust-deprecated") |
Jeff Vander Stoep | c1490ec | 2023-04-24 11:28:25 +0200 | [diff] [blame] | 91 | if proto.useProtobuf3() == true { |
| 92 | protoPluginPath = ctx.Config().HostToolPath(ctx, "protoc-gen-rust") |
| 93 | } |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 94 | |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 95 | commonProtoFlags = append(commonProtoFlags, defaultProtobufFlags...) |
| 96 | commonProtoFlags = append(commonProtoFlags, proto.Properties.Proto_flags...) |
| 97 | commonProtoFlags = append(commonProtoFlags, "--plugin=protoc-gen-rust="+protoPluginPath.String()) |
| 98 | |
| 99 | if len(protoFiles) > 0 { |
| 100 | protoFlags.OutTypeFlag = "--rust_out" |
| 101 | protoFlags.Flags = append(protoFlags.Flags, commonProtoFlags...) |
| 102 | |
| 103 | protoFlags.Deps = append(protoFlags.Deps, protoPluginPath) |
| 104 | } |
| 105 | |
| 106 | if len(grpcFiles) > 0 { |
| 107 | grpcPath := ctx.Config().HostToolPath(ctx, "grpc_rust_plugin") |
| 108 | |
| 109 | grpcProtoFlags.OutTypeFlag = "--rust_out" |
| 110 | grpcProtoFlags.Flags = append(grpcProtoFlags.Flags, "--grpc_out="+outDir.String()) |
| 111 | grpcProtoFlags.Flags = append(grpcProtoFlags.Flags, "--plugin=protoc-gen-grpc="+grpcPath.String()) |
| 112 | grpcProtoFlags.Flags = append(grpcProtoFlags.Flags, commonProtoFlags...) |
| 113 | |
| 114 | grpcProtoFlags.Deps = append(grpcProtoFlags.Deps, grpcPath, protoPluginPath) |
| 115 | } |
| 116 | |
| 117 | if len(protoFiles) == 0 && len(grpcFiles) == 0 { |
| 118 | ctx.PropertyErrorf("protos", |
| 119 | "at least one protobuf must be defined in either protos or grpc_protos.") |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 120 | } |
| 121 | |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 122 | // Add exported dependency include paths |
| 123 | for _, include := range deps.depIncludePaths { |
| 124 | protoFlags.Flags = append(protoFlags.Flags, "-I"+include.String()) |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 125 | grpcProtoFlags.Flags = append(grpcProtoFlags.Flags, "-I"+include.String()) |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Chih-Hung Hsieh | c49649c | 2020-10-01 21:25:05 -0700 | [diff] [blame] | 128 | stem := proto.BaseSourceProvider.getStem(ctx) |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 129 | |
| 130 | // The mod_stem.rs file is used to avoid collisions if this is not included as a crate. |
| 131 | stemFile := android.PathForModuleOut(ctx, "mod_"+stem+".rs") |
| 132 | |
| 133 | // stemFile must be first here as the first path in BaseSourceProvider.OutputFiles is the library entry-point. |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 134 | var outputs android.WritablePaths |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 135 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 136 | rule := android.NewRuleBuilder(pctx, ctx) |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 137 | |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 138 | for _, protoFile := range protoFiles { |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 139 | // Since we're iterating over the protoFiles already, make sure they're not redeclared in grpcFiles |
| 140 | if android.InList(protoFile.String(), grpcFiles.Strings()) { |
| 141 | ctx.PropertyErrorf("protos", |
| 142 | "A proto can only be added once to either grpc_protos or protos. %q is declared in both properties", |
| 143 | protoFile.String()) |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 144 | } |
| 145 | |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 146 | protoName := strings.TrimSuffix(protoFile.Base(), ".proto") |
| 147 | proto.protoNames = append(proto.protoNames, protoName) |
| 148 | |
| 149 | protoOut := android.PathForModuleOut(ctx, protoName+".rs") |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 150 | depFile := android.PathForModuleOut(ctx, protoName+".d") |
| 151 | |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 152 | ruleOutputs := android.WritablePaths{protoOut, depFile} |
| 153 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 154 | android.ProtoRule(rule, protoFile, protoFlags, protoFlags.Deps, outDir, depFile, ruleOutputs) |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 155 | outputs = append(outputs, ruleOutputs...) |
| 156 | } |
| 157 | |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 158 | for _, grpcFile := range grpcFiles { |
| 159 | grpcName := strings.TrimSuffix(grpcFile.Base(), ".proto") |
| 160 | proto.grpcNames = append(proto.grpcNames, grpcName) |
| 161 | |
| 162 | // GRPC protos produce two files, a proto.rs and a proto_grpc.rs |
| 163 | protoOut := android.WritablePath(android.PathForModuleOut(ctx, grpcName+".rs")) |
| 164 | grpcOut := android.WritablePath(android.PathForModuleOut(ctx, grpcName+grpcSuffix+".rs")) |
| 165 | depFile := android.PathForModuleOut(ctx, grpcName+".d") |
| 166 | |
| 167 | ruleOutputs := android.WritablePaths{protoOut, grpcOut, depFile} |
| 168 | |
| 169 | android.ProtoRule(rule, grpcFile, grpcProtoFlags, grpcProtoFlags.Deps, outDir, depFile, ruleOutputs) |
| 170 | outputs = append(outputs, ruleOutputs...) |
| 171 | } |
| 172 | |
| 173 | // Check that all proto base filenames are unique as outputs are written to the same directory. |
| 174 | baseFilenames := append(proto.protoNames, proto.grpcNames...) |
| 175 | if len(baseFilenames) != len(android.FirstUniqueStrings(baseFilenames)) { |
| 176 | ctx.PropertyErrorf("protos", "proto filenames must be unique across 'protos' and 'grpc_protos' "+ |
| 177 | "to be used in the same rust_protobuf module. For example, foo.proto and src/foo.proto will conflict.") |
| 178 | } |
| 179 | |
| 180 | android.WriteFileRule(ctx, stemFile, proto.genModFileContents()) |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 181 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 182 | rule.Build("protoc_"+ctx.ModuleName(), "protoc "+ctx.ModuleName()) |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 183 | |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 184 | // stemFile must be first here as the first path in BaseSourceProvider.OutputFiles is the library entry-point. |
| 185 | proto.BaseSourceProvider.OutputFiles = append(android.Paths{stemFile}, outputs.Paths()...) |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 186 | |
| 187 | // mod_stem.rs is the entry-point for our library modules, so this is what we return. |
| 188 | return stemFile |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 189 | } |
| 190 | |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 191 | func (proto *protobufDecorator) genModFileContents() string { |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 192 | lines := []string{ |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 193 | "// @Soong generated Source", |
| 194 | } |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 195 | for _, protoName := range proto.protoNames { |
Ivan Lozano | 57f434e | 2020-10-28 09:32:10 -0400 | [diff] [blame] | 196 | lines = append(lines, fmt.Sprintf("pub mod %s;", protoName)) |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 199 | for _, grpcName := range proto.grpcNames { |
| 200 | lines = append(lines, fmt.Sprintf("pub mod %s;", grpcName)) |
| 201 | lines = append(lines, fmt.Sprintf("pub mod %s%s;", grpcName, grpcSuffix)) |
| 202 | } |
| 203 | if len(proto.grpcNames) > 0 { |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 204 | lines = append( |
| 205 | lines, |
| 206 | "pub mod empty {", |
| 207 | " pub use protobuf::well_known_types::Empty;", |
David Duarte | b6be48d | 2022-01-04 08:51:21 +0000 | [diff] [blame] | 208 | "}", |
| 209 | "pub mod wrappers {", |
| 210 | " pub use protobuf::well_known_types::{", |
| 211 | " DoubleValue, FloatValue, Int64Value, UInt64Value, Int32Value, UInt32Value,", |
| 212 | " BoolValue, StringValue, BytesValue", |
| 213 | " };", |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 214 | "}") |
| 215 | } |
| 216 | |
Ivan Lozano | 9d74a52 | 2020-12-01 09:25:22 -0500 | [diff] [blame] | 217 | return strings.Join(lines, "\n") |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 218 | } |
| 219 | |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 220 | func (proto *protobufDecorator) SourceProviderProps() []interface{} { |
| 221 | return append(proto.BaseSourceProvider.SourceProviderProps(), &proto.Properties) |
| 222 | } |
| 223 | |
| 224 | func (proto *protobufDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) Deps { |
| 225 | deps = proto.BaseSourceProvider.SourceProviderDeps(ctx, deps) |
Jeff Vander Stoep | c1490ec | 2023-04-24 11:28:25 +0200 | [diff] [blame] | 226 | useProtobuf3 := proto.useProtobuf3() |
| 227 | if useProtobuf3 == true { |
| 228 | deps.Rustlibs = append(deps.Rustlibs, "libprotobuf") |
| 229 | } else { |
| 230 | deps.Rustlibs = append(deps.Rustlibs, "libprotobuf_deprecated") |
| 231 | } |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 232 | deps.HeaderLibs = append(deps.SharedLibs, proto.Properties.Header_libs...) |
| 233 | |
Ivan Lozano | 6eff900 | 2020-12-11 15:25:59 -0500 | [diff] [blame] | 234 | if len(proto.Properties.Grpc_protos) > 0 { |
Jeff Vander Stoep | c1490ec | 2023-04-24 11:28:25 +0200 | [diff] [blame] | 235 | if useProtobuf3 == true { |
| 236 | ctx.PropertyErrorf("protos", "rust_protobuf with grpc_protos defined must currently use "+ |
| 237 | "`use_protobuf3: false,` in the Android.bp file. This is temporary until the "+ |
| 238 | "grpcio crate is updated to use the current version of the protobuf crate.") |
| 239 | } |
Zach Johnson | 3df4e63 | 2020-11-06 11:56:27 -0800 | [diff] [blame] | 240 | deps.Rustlibs = append(deps.Rustlibs, "libgrpcio", "libfutures") |
| 241 | deps.HeaderLibs = append(deps.HeaderLibs, "libprotobuf-cpp-full") |
| 242 | } |
| 243 | |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 244 | return deps |
| 245 | } |
| 246 | |
| 247 | // rust_protobuf generates protobuf rust code from the provided proto file. This uses the protoc-gen-rust plugin for |
| 248 | // protoc. Additional flags to the protoc command can be passed via the proto_flags property. This module type will |
Vinh Tran | 4eeb2a9 | 2023-08-14 13:29:30 -0400 | [diff] [blame] | 249 | // create library variants that can be used as a crate dependency by adding it to the rlibs and rustlibs |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 250 | // properties of other modules. |
| 251 | func RustProtobufFactory() android.Module { |
| 252 | module, _ := NewRustProtobuf(android.HostAndDeviceSupported) |
| 253 | return module.Init() |
| 254 | } |
| 255 | |
| 256 | // A host-only variant of rust_protobuf. Refer to rust_protobuf for more details. |
| 257 | func RustProtobufHostFactory() android.Module { |
| 258 | module, _ := NewRustProtobuf(android.HostSupported) |
| 259 | return module.Init() |
| 260 | } |
| 261 | |
| 262 | func NewRustProtobuf(hod android.HostOrDeviceSupported) (*Module, *protobufDecorator) { |
| 263 | protobuf := &protobufDecorator{ |
| 264 | BaseSourceProvider: NewSourceProvider(), |
| 265 | Properties: ProtobufProperties{}, |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Matthew Maurer | e94f3e7 | 2022-08-10 20:25:50 +0000 | [diff] [blame] | 268 | module := NewSourceProviderModule(hod, protobuf, false, false) |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 269 | |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 270 | android.InitBazelModule(module) |
| 271 | |
Treehugger Robot | 588aae7 | 2020-08-21 10:01:58 +0000 | [diff] [blame] | 272 | return module, protobuf |
| 273 | } |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 274 | |
| 275 | type rustProtoAttributes struct { |
| 276 | Srcs bazel.LabelListAttribute |
| 277 | Crate_name bazel.StringAttribute |
| 278 | Deps bazel.LabelListAttribute |
| 279 | } |
| 280 | |
| 281 | type protoLibraryAttributes struct { |
| 282 | Srcs bazel.LabelListAttribute |
| 283 | } |
| 284 | |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame] | 285 | func protoLibraryBp2build(ctx android.Bp2buildMutatorContext, m *Module) { |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 286 | var protoFiles []string |
| 287 | |
| 288 | for _, propsInterface := range m.sourceProvider.SourceProviderProps() { |
| 289 | if possibleProps, ok := propsInterface.(*ProtobufProperties); ok { |
| 290 | protoFiles = possibleProps.Protos |
| 291 | break |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | protoLibraryName := m.Name() + "_proto" |
| 296 | |
| 297 | protoDeps := bazel.LabelListAttribute{ |
| 298 | Value: bazel.LabelList{ |
| 299 | Includes: []bazel.Label{ |
| 300 | { |
| 301 | Label: ":" + protoLibraryName, |
| 302 | OriginalModuleName: m.Name(), |
| 303 | }, |
| 304 | }, |
| 305 | }, |
| 306 | } |
| 307 | |
Vinh Tran | 47faaad | 2023-09-25 14:47:19 -0400 | [diff] [blame^] | 308 | // TODO(b/295918553): Remove androidRestriction after rust toolchain for android is checked in. |
| 309 | var androidRestriction bazel.BoolAttribute |
| 310 | androidRestriction.SetSelectValue(bazel.OsConfigurationAxis, "android", proptools.BoolPtr(false)) |
| 311 | |
| 312 | ctx.CreateBazelTargetModuleWithRestrictions( |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 313 | bazel.BazelTargetModuleProperties{ |
| 314 | Rule_class: "proto_library", |
| 315 | }, |
| 316 | android.CommonAttributes{ |
| 317 | Name: protoLibraryName, |
| 318 | }, |
| 319 | &protoLibraryAttributes{ |
| 320 | Srcs: bazel.MakeLabelListAttribute( |
| 321 | android.BazelLabelForModuleSrc(ctx, protoFiles), |
| 322 | ), |
| 323 | }, |
Vinh Tran | 47faaad | 2023-09-25 14:47:19 -0400 | [diff] [blame^] | 324 | androidRestriction, |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 325 | ) |
| 326 | |
Vinh Tran | 47faaad | 2023-09-25 14:47:19 -0400 | [diff] [blame^] | 327 | ctx.CreateBazelTargetModuleWithRestrictions( |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 328 | bazel.BazelTargetModuleProperties{ |
| 329 | Rule_class: "rust_proto_library", |
| 330 | Bzl_load_location: "@rules_rust//proto/protobuf:defs.bzl", |
| 331 | }, |
| 332 | android.CommonAttributes{ |
| 333 | Name: m.Name(), |
| 334 | }, |
| 335 | &rustProtoAttributes{ |
| 336 | Crate_name: bazel.StringAttribute{ |
| 337 | Value: proptools.StringPtr(m.CrateName()), |
| 338 | }, |
| 339 | Deps: protoDeps, |
| 340 | }, |
Vinh Tran | 47faaad | 2023-09-25 14:47:19 -0400 | [diff] [blame^] | 341 | androidRestriction, |
Vinh Tran | 0c4b9ec | 2023-08-24 11:10:01 -0400 | [diff] [blame] | 342 | ) |
| 343 | } |