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
This commit is contained in:
Ivan Lozano
2023-09-21 23:30:26 -04:00
parent c5b9abba30
commit d106efe76d
3 changed files with 131 additions and 23 deletions

View File

@@ -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))