rust_grpcio well known types support, default deps
The usage of the well known type Empty requires a hack in the module above the grpc implementation, this is now the generated stem_mod.rs This also adds additional implicit dependencies that are required by the grpc protobuf generated code. This includes the addition of a 'header_libs' property for library dependencies which export include paths required by protos. We also now include both the protos and the grpcio in the library variant via the mod_stem.rs. Bug: 172592789 Bug: 171504899 Test: m nothing Test: Example rust_grpcio module build command includes dependencies, include paths. Change-Id: I187a13cd5cdea991828a1020314de16727e4f74e
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
package rust
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
)
|
||||
|
||||
@@ -22,6 +25,10 @@ var (
|
||||
defaultProtobufFlags = []string{""}
|
||||
)
|
||||
|
||||
const (
|
||||
grpcSuffix = "_grpc"
|
||||
)
|
||||
|
||||
type PluginType int
|
||||
|
||||
const (
|
||||
@@ -44,6 +51,9 @@ type ProtobufProperties struct {
|
||||
|
||||
// List of additional flags to pass to aprotoc
|
||||
Proto_flags []string `android:"arch_variant"`
|
||||
|
||||
// List of libraries which export include paths required for this module
|
||||
Header_libs []string `android:"arch_variant"`
|
||||
}
|
||||
|
||||
type protobufDecorator struct {
|
||||
@@ -72,6 +82,11 @@ func (proto *protobufDecorator) GenerateSource(ctx ModuleContext, deps PathDeps)
|
||||
ctx.PropertyErrorf("proto", "invalid path to proto file")
|
||||
}
|
||||
|
||||
// Add exported dependency include paths
|
||||
for _, include := range deps.depIncludePaths {
|
||||
protoFlags.Flags = append(protoFlags.Flags, "-I"+include.String())
|
||||
}
|
||||
|
||||
stem := proto.BaseSourceProvider.getStem(ctx)
|
||||
// rust protobuf-codegen output <stem>.rs
|
||||
stemFile := android.PathForModuleOut(ctx, stem+".rs")
|
||||
@@ -79,17 +94,39 @@ func (proto *protobufDecorator) GenerateSource(ctx ModuleContext, deps PathDeps)
|
||||
modFile := android.PathForModuleOut(ctx, "mod_"+stem+".rs")
|
||||
// mod_<stem>.rs is the main/first output file to be included/compiled
|
||||
outputs := android.WritablePaths{modFile, stemFile}
|
||||
if proto.plugin == Grpc {
|
||||
outputs = append(outputs, android.PathForModuleOut(ctx, stem+grpcSuffix+".rs"))
|
||||
}
|
||||
depFile := android.PathForModuleOut(ctx, "mod_"+stem+".d")
|
||||
|
||||
rule := android.NewRuleBuilder()
|
||||
android.ProtoRule(ctx, rule, protoFile.Path(), protoFlags, protoFlags.Deps, outDir, depFile, outputs)
|
||||
rule.Command().Text("printf '// @generated\\npub mod %s;\\n' '" + stem + "' >").Output(modFile)
|
||||
rule.Command().Text("printf '" + proto.getModFileContents(ctx) + "' >").Output(modFile)
|
||||
rule.Build(pctx, ctx, "protoc_"+protoFile.Path().Rel(), "protoc "+protoFile.Path().Rel())
|
||||
|
||||
proto.BaseSourceProvider.OutputFiles = android.Paths{modFile, stemFile}
|
||||
return modFile
|
||||
}
|
||||
|
||||
func (proto *protobufDecorator) getModFileContents(ctx ModuleContext) string {
|
||||
stem := proto.BaseSourceProvider.getStem(ctx)
|
||||
lines := []string{
|
||||
"// @generated",
|
||||
fmt.Sprintf("pub mod %s;", stem),
|
||||
}
|
||||
|
||||
if proto.plugin == Grpc {
|
||||
lines = append(lines, fmt.Sprintf("pub mod %s%s;", stem, grpcSuffix))
|
||||
lines = append(
|
||||
lines,
|
||||
"pub mod empty {",
|
||||
" pub use protobuf::well_known_types::Empty;",
|
||||
"}")
|
||||
}
|
||||
|
||||
return strings.Join(lines, "\\n")
|
||||
}
|
||||
|
||||
func (proto *protobufDecorator) setupPlugin(ctx ModuleContext, protoFlags android.ProtoFlags, outDir android.ModuleOutPath) (android.Paths, android.ProtoFlags) {
|
||||
pluginPaths := []android.Path{}
|
||||
|
||||
@@ -118,6 +155,13 @@ func (proto *protobufDecorator) SourceProviderProps() []interface{} {
|
||||
func (proto *protobufDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) Deps {
|
||||
deps = proto.BaseSourceProvider.SourceProviderDeps(ctx, deps)
|
||||
deps.Rustlibs = append(deps.Rustlibs, "libprotobuf")
|
||||
deps.HeaderLibs = append(deps.SharedLibs, proto.Properties.Header_libs...)
|
||||
|
||||
if proto.plugin == Grpc {
|
||||
deps.Rustlibs = append(deps.Rustlibs, "libgrpcio", "libfutures")
|
||||
deps.HeaderLibs = append(deps.HeaderLibs, "libprotobuf-cpp-full")
|
||||
}
|
||||
|
||||
return deps
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user