summaryrefslogtreecommitdiff
path: root/rust/protobuf.go
diff options
context:
space:
mode:
author Vinh Tran <vinhdaitran@google.com> 2023-08-24 11:10:01 -0400
committer Vinh Tran <vinhdaitran@google.com> 2023-08-25 18:00:33 -0400
commit0c4b9ec5e0cb1235c8b418959a29385fe60b23a3 (patch)
tree1a9a9288f30699ec019eb9604d4c97e9db6eded2 /rust/protobuf.go
parent093a57edb2adff4f8aac32bc4a9197f4c6a17da9 (diff)
Implement bp2build converter for rust_protobuf_host
Test: go test Bug: 295925256 Change-Id: I43b7359da8fc19f4338e2583448b7617194df5e6
Diffstat (limited to 'rust/protobuf.go')
-rw-r--r--rust/protobuf.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/rust/protobuf.go b/rust/protobuf.go
index a14ebeaab..ae828442b 100644
--- a/rust/protobuf.go
+++ b/rust/protobuf.go
@@ -19,6 +19,9 @@ import (
"strings"
"android/soong/android"
+ "android/soong/bazel"
+
+ "github.com/google/blueprint/proptools"
)
var (
@@ -264,5 +267,71 @@ func NewRustProtobuf(hod android.HostOrDeviceSupported) (*Module, *protobufDecor
module := NewSourceProviderModule(hod, protobuf, false, false)
+ android.InitBazelModule(module)
+
return module, protobuf
}
+
+type rustProtoAttributes struct {
+ Srcs bazel.LabelListAttribute
+ Crate_name bazel.StringAttribute
+ Deps bazel.LabelListAttribute
+}
+
+type protoLibraryAttributes struct {
+ Srcs bazel.LabelListAttribute
+}
+
+func protoLibraryBp2build(ctx android.TopDownMutatorContext, m *Module) {
+ var protoFiles []string
+
+ for _, propsInterface := range m.sourceProvider.SourceProviderProps() {
+ if possibleProps, ok := propsInterface.(*ProtobufProperties); ok {
+ protoFiles = possibleProps.Protos
+ break
+ }
+ }
+
+ protoLibraryName := m.Name() + "_proto"
+
+ protoDeps := bazel.LabelListAttribute{
+ Value: bazel.LabelList{
+ Includes: []bazel.Label{
+ {
+ Label: ":" + protoLibraryName,
+ OriginalModuleName: m.Name(),
+ },
+ },
+ },
+ }
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "proto_library",
+ },
+ android.CommonAttributes{
+ Name: protoLibraryName,
+ },
+ &protoLibraryAttributes{
+ Srcs: bazel.MakeLabelListAttribute(
+ android.BazelLabelForModuleSrc(ctx, protoFiles),
+ ),
+ },
+ )
+
+ ctx.CreateBazelTargetModule(
+ bazel.BazelTargetModuleProperties{
+ Rule_class: "rust_proto_library",
+ Bzl_load_location: "@rules_rust//proto/protobuf:defs.bzl",
+ },
+ android.CommonAttributes{
+ Name: m.Name(),
+ },
+ &rustProtoAttributes{
+ Crate_name: bazel.StringAttribute{
+ Value: proptools.StringPtr(m.CrateName()),
+ },
+ Deps: protoDeps,
+ },
+ )
+}