Merge "rust_grpcio well known types support, default deps"
This commit is contained in:
commit
c0ea1701cb
6 changed files with 132 additions and 2 deletions
5
cc/cc.go
5
cc/cc.go
|
@ -592,6 +592,11 @@ func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
|
||||||
return ok && ccLibDepTag.static()
|
return ok && ccLibDepTag.static()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsHeaderDepTag(depTag blueprint.DependencyTag) bool {
|
||||||
|
ccLibDepTag, ok := depTag.(libraryDependencyTag)
|
||||||
|
return ok && ccLibDepTag.header()
|
||||||
|
}
|
||||||
|
|
||||||
func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
|
func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
|
||||||
ccDepTag, ok := depTag.(dependencyTag)
|
ccDepTag, ok := depTag.(dependencyTag)
|
||||||
return ok && ccDepTag == runtimeDepTag
|
return ok && ccDepTag == runtimeDepTag
|
||||||
|
|
|
@ -64,6 +64,10 @@ func StaticDepTag() blueprint.DependencyTag {
|
||||||
return libraryDependencyTag{Kind: staticLibraryDependency}
|
return libraryDependencyTag{Kind: staticLibraryDependency}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HeaderDepTag() blueprint.DependencyTag {
|
||||||
|
return libraryDependencyTag{Kind: headerLibraryDependency}
|
||||||
|
}
|
||||||
|
|
||||||
type SharedLibraryInfo struct {
|
type SharedLibraryInfo struct {
|
||||||
SharedLibrary android.Path
|
SharedLibrary android.Path
|
||||||
UnstrippedSharedLibrary android.Path
|
UnstrippedSharedLibrary android.Path
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
package rust
|
package rust
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -22,6 +25,10 @@ var (
|
||||||
defaultProtobufFlags = []string{""}
|
defaultProtobufFlags = []string{""}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
grpcSuffix = "_grpc"
|
||||||
|
)
|
||||||
|
|
||||||
type PluginType int
|
type PluginType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -44,6 +51,9 @@ type ProtobufProperties struct {
|
||||||
|
|
||||||
// List of additional flags to pass to aprotoc
|
// List of additional flags to pass to aprotoc
|
||||||
Proto_flags []string `android:"arch_variant"`
|
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 {
|
type protobufDecorator struct {
|
||||||
|
@ -72,6 +82,11 @@ func (proto *protobufDecorator) GenerateSource(ctx ModuleContext, deps PathDeps)
|
||||||
ctx.PropertyErrorf("proto", "invalid path to proto file")
|
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)
|
stem := proto.BaseSourceProvider.getStem(ctx)
|
||||||
// rust protobuf-codegen output <stem>.rs
|
// rust protobuf-codegen output <stem>.rs
|
||||||
stemFile := android.PathForModuleOut(ctx, 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")
|
modFile := android.PathForModuleOut(ctx, "mod_"+stem+".rs")
|
||||||
// mod_<stem>.rs is the main/first output file to be included/compiled
|
// mod_<stem>.rs is the main/first output file to be included/compiled
|
||||||
outputs := android.WritablePaths{modFile, stemFile}
|
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")
|
depFile := android.PathForModuleOut(ctx, "mod_"+stem+".d")
|
||||||
|
|
||||||
rule := android.NewRuleBuilder()
|
rule := android.NewRuleBuilder()
|
||||||
android.ProtoRule(ctx, rule, protoFile.Path(), protoFlags, protoFlags.Deps, outDir, depFile, outputs)
|
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())
|
rule.Build(pctx, ctx, "protoc_"+protoFile.Path().Rel(), "protoc "+protoFile.Path().Rel())
|
||||||
|
|
||||||
proto.BaseSourceProvider.OutputFiles = android.Paths{modFile, stemFile}
|
proto.BaseSourceProvider.OutputFiles = android.Paths{modFile, stemFile}
|
||||||
return modFile
|
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) {
|
func (proto *protobufDecorator) setupPlugin(ctx ModuleContext, protoFlags android.ProtoFlags, outDir android.ModuleOutPath) (android.Paths, android.ProtoFlags) {
|
||||||
pluginPaths := []android.Path{}
|
pluginPaths := []android.Path{}
|
||||||
|
|
||||||
|
@ -118,6 +155,13 @@ func (proto *protobufDecorator) SourceProviderProps() []interface{} {
|
||||||
func (proto *protobufDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) Deps {
|
func (proto *protobufDecorator) SourceProviderDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
deps = proto.BaseSourceProvider.SourceProviderDeps(ctx, deps)
|
deps = proto.BaseSourceProvider.SourceProviderDeps(ctx, deps)
|
||||||
deps.Rustlibs = append(deps.Rustlibs, "libprotobuf")
|
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
|
return deps
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,16 @@ func TestRustProtobuf(t *testing.T) {
|
||||||
proto: "buf.proto",
|
proto: "buf.proto",
|
||||||
crate_name: "rust_proto",
|
crate_name: "rust_proto",
|
||||||
source_stem: "buf",
|
source_stem: "buf",
|
||||||
|
shared_libs: ["libfoo_shared"],
|
||||||
|
static_libs: ["libfoo_static"],
|
||||||
|
}
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libfoo_shared",
|
||||||
|
export_include_dirs: ["shared_include"],
|
||||||
|
}
|
||||||
|
cc_library_static {
|
||||||
|
name: "libfoo_static",
|
||||||
|
export_include_dirs: ["static_include"],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
// Check that libprotobuf is added as a dependency.
|
// Check that libprotobuf is added as a dependency.
|
||||||
|
@ -43,6 +53,13 @@ func TestRustProtobuf(t *testing.T) {
|
||||||
t.Errorf("expected %q in %q", w, cmd)
|
t.Errorf("expected %q in %q", w, cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check exported include directories
|
||||||
|
if w := "-Ishared_include"; !strings.Contains(cmd, w) {
|
||||||
|
t.Errorf("expected %q in %q", w, cmd)
|
||||||
|
}
|
||||||
|
if w := "-Istatic_include"; !strings.Contains(cmd, w) {
|
||||||
|
t.Errorf("expected %q in %q", w, cmd)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRustGrpcio(t *testing.T) {
|
func TestRustGrpcio(t *testing.T) {
|
||||||
|
@ -52,6 +69,16 @@ func TestRustGrpcio(t *testing.T) {
|
||||||
proto: "buf.proto",
|
proto: "buf.proto",
|
||||||
crate_name: "rust_grpcio",
|
crate_name: "rust_grpcio",
|
||||||
source_stem: "buf",
|
source_stem: "buf",
|
||||||
|
shared_libs: ["libfoo_shared"],
|
||||||
|
static_libs: ["libfoo_static"],
|
||||||
|
}
|
||||||
|
cc_library_shared {
|
||||||
|
name: "libfoo_shared",
|
||||||
|
export_include_dirs: ["shared_include"],
|
||||||
|
}
|
||||||
|
cc_library_static {
|
||||||
|
name: "libfoo_static",
|
||||||
|
export_include_dirs: ["static_include"],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
@ -61,10 +88,33 @@ func TestRustGrpcio(t *testing.T) {
|
||||||
t.Errorf("libprotobuf dependency missing for rust_grpcio (dependency missing from AndroidMkDylibs)")
|
t.Errorf("libprotobuf dependency missing for rust_grpcio (dependency missing from AndroidMkDylibs)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that libgrpcio is added as a dependency.
|
||||||
|
if !android.InList("libgrpcio", librust_grpcio_module.Properties.AndroidMkDylibs) {
|
||||||
|
t.Errorf("libgrpcio dependency missing for rust_grpcio (dependency missing from AndroidMkDylibs)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that libfutures is added as a dependency.
|
||||||
|
if !android.InList("libfutures", librust_grpcio_module.Properties.AndroidMkDylibs) {
|
||||||
|
t.Errorf("libfutures dependency missing for rust_grpcio (dependency missing from AndroidMkDylibs)")
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure the correct plugin is being used.
|
// Make sure the correct plugin is being used.
|
||||||
librust_grpcio_out := ctx.ModuleForTests("librust_grpcio", "android_arm64_armv8-a_source").Output("buf.rs")
|
librust_grpcio_out := ctx.ModuleForTests("librust_grpcio", "android_arm64_armv8-a_source").Output("buf_grpc.rs")
|
||||||
cmd := librust_grpcio_out.RuleParams.Command
|
cmd := librust_grpcio_out.RuleParams.Command
|
||||||
if w := "protoc-gen-grpc"; !strings.Contains(cmd, w) {
|
if w := "protoc-gen-grpc"; !strings.Contains(cmd, w) {
|
||||||
t.Errorf("expected %q in %q", w, cmd)
|
t.Errorf("expected %q in %q", w, cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check exported include directories
|
||||||
|
if w := "-Ishared_include"; !strings.Contains(cmd, w) {
|
||||||
|
t.Errorf("expected %q in %q", w, cmd)
|
||||||
|
}
|
||||||
|
if w := "-Istatic_include"; !strings.Contains(cmd, w) {
|
||||||
|
t.Errorf("expected %q in %q", w, cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that we're including the exported directory from libprotobuf-cpp-full
|
||||||
|
if w := "-Ilibprotobuf-cpp-full-includes"; !strings.Contains(cmd, w) {
|
||||||
|
t.Errorf("expected %q in %q", w, cmd)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,6 +229,7 @@ type Deps struct {
|
||||||
ProcMacros []string
|
ProcMacros []string
|
||||||
SharedLibs []string
|
SharedLibs []string
|
||||||
StaticLibs []string
|
StaticLibs []string
|
||||||
|
HeaderLibs []string
|
||||||
|
|
||||||
CrtBegin, CrtEnd string
|
CrtBegin, CrtEnd string
|
||||||
}
|
}
|
||||||
|
@ -838,6 +839,11 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||||
directSharedLibDeps = append(directSharedLibDeps, ccDep)
|
directSharedLibDeps = append(directSharedLibDeps, ccDep)
|
||||||
mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
|
mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName)
|
||||||
exportDep = true
|
exportDep = true
|
||||||
|
case cc.IsHeaderDepTag(depTag):
|
||||||
|
exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
|
||||||
|
depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
|
||||||
|
depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
|
||||||
|
depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
|
||||||
case depTag == cc.CrtBeginDepTag:
|
case depTag == cc.CrtBeginDepTag:
|
||||||
depPaths.CrtBegin = linkObject
|
depPaths.CrtBegin = linkObject
|
||||||
case depTag == cc.CrtEndDepTag:
|
case depTag == cc.CrtEndDepTag:
|
||||||
|
@ -983,6 +989,8 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||||
blueprint.Variation{Mutator: "link", Variation: "static"}),
|
blueprint.Variation{Mutator: "link", Variation: "static"}),
|
||||||
cc.StaticDepTag(), deps.StaticLibs...)
|
cc.StaticDepTag(), deps.StaticLibs...)
|
||||||
|
|
||||||
|
actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...)
|
||||||
|
|
||||||
crtVariations := cc.GetCrtVariations(ctx, mod)
|
crtVariations := cc.GetCrtVariations(ctx, mod)
|
||||||
if deps.CrtBegin != "" {
|
if deps.CrtBegin != "" {
|
||||||
actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin)
|
actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin)
|
||||||
|
|
|
@ -79,6 +79,13 @@ func GatherRequiredDepsForTest() string {
|
||||||
nocrt: true,
|
nocrt: true,
|
||||||
system_shared_libs: [],
|
system_shared_libs: [],
|
||||||
}
|
}
|
||||||
|
cc_library {
|
||||||
|
name: "libprotobuf-cpp-full",
|
||||||
|
no_libcrt: true,
|
||||||
|
nocrt: true,
|
||||||
|
system_shared_libs: [],
|
||||||
|
export_include_dirs: ["libprotobuf-cpp-full-includes"],
|
||||||
|
}
|
||||||
rust_library {
|
rust_library {
|
||||||
name: "libstd",
|
name: "libstd",
|
||||||
crate_name: "std",
|
crate_name: "std",
|
||||||
|
@ -103,6 +110,18 @@ func GatherRequiredDepsForTest() string {
|
||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
host_supported: true,
|
host_supported: true,
|
||||||
}
|
}
|
||||||
|
rust_library {
|
||||||
|
name: "libgrpcio",
|
||||||
|
crate_name: "grpcio",
|
||||||
|
srcs: ["foo.rs"],
|
||||||
|
host_supported: true,
|
||||||
|
}
|
||||||
|
rust_library {
|
||||||
|
name: "libfutures",
|
||||||
|
crate_name: "futures",
|
||||||
|
srcs: ["foo.rs"],
|
||||||
|
host_supported: true,
|
||||||
|
}
|
||||||
|
|
||||||
` + cc.GatherRequiredDepsForTest(android.NoOsType)
|
` + cc.GatherRequiredDepsForTest(android.NoOsType)
|
||||||
return bp
|
return bp
|
||||||
|
|
Loading…
Reference in a new issue