diff options
author | 2023-09-21 23:30:26 -0400 | |
---|---|---|
committer | 2023-09-27 20:53:54 -0400 | |
commit | d106efe76d0301de27868d3c714b5ba4a42a3fb1 (patch) | |
tree | 141ef6e5e5e8113497ade1f9d8d9f9a8c624f361 /rust/protobuf.go | |
parent | c5b9abba309e4bb65e6ae69c60b44d0f4b59e278 (diff) |
rust: Import protos from dependent rust_protobuf
rust_protobuf were unable to import protos from other rust_protobuf
modules. This CL adds support for that. rust_protobuf modules which are
listed in rustlibs will have their modules imported into the generated
protobuf stub. Additionally, rust_protobuf modules which define
"exported_include_dirs" will export those include paths to dependent
rust_protobuf modules.
Bug: 301266700
Test: m rust
Change-Id: I132edffa4d77e0ac80a7ac934f873374c8e94c1b
Diffstat (limited to 'rust/protobuf.go')
-rw-r--r-- | rust/protobuf.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/rust/protobuf.go b/rust/protobuf.go index c3aa8dc64..2982efdf2 100644 --- a/rust/protobuf.go +++ b/rust/protobuf.go @@ -20,6 +20,7 @@ import ( "android/soong/android" "android/soong/bazel" + "android/soong/cc" "github.com/google/blueprint/proptools" ) @@ -59,14 +60,18 @@ type ProtobufProperties struct { // Use protobuf version 3.x. This will be deleted once we migrate all current users // of protobuf off of 2.x. Use_protobuf3 *bool + + // List of exported include paths containing proto files for dependent rust_protobuf modules. + Exported_include_dirs []string } type protobufDecorator struct { *BaseSourceProvider - Properties ProtobufProperties - protoNames []string - grpcNames []string + Properties ProtobufProperties + protoNames []string + additionalCrates []string + grpcNames []string grpcProtoFlags android.ProtoFlags protoFlags android.ProtoFlags @@ -184,6 +189,10 @@ func (proto *protobufDecorator) GenerateSource(ctx ModuleContext, deps PathDeps) // stemFile must be first here as the first path in BaseSourceProvider.OutputFiles is the library entry-point. proto.BaseSourceProvider.OutputFiles = append(android.Paths{stemFile}, outputs.Paths()...) + ctx.SetProvider(cc.FlagExporterInfoProvider, cc.FlagExporterInfo{ + IncludeDirs: android.PathsForModuleSrc(ctx, proto.Properties.Exported_include_dirs), + }) + // mod_stem.rs is the entry-point for our library modules, so this is what we return. return stemFile } @@ -192,10 +201,16 @@ func (proto *protobufDecorator) genModFileContents() string { lines := []string{ "// @Soong generated Source", } + for _, protoName := range proto.protoNames { lines = append(lines, fmt.Sprintf("pub mod %s;", protoName)) } + for _, crate := range proto.additionalCrates { + lines = append(lines, fmt.Sprintf("pub use %s::*;", crate)) + + } + for _, grpcName := range proto.grpcNames { lines = append(lines, fmt.Sprintf("pub mod %s;", grpcName)) lines = append(lines, fmt.Sprintf("pub mod %s%s;", grpcName, grpcSuffix)) |