Loading cc/cc.go +5 −0 Original line number Diff line number Diff line Loading @@ -592,6 +592,11 @@ func IsStaticDepTag(depTag blueprint.DependencyTag) bool { return ok && ccLibDepTag.static() } func IsHeaderDepTag(depTag blueprint.DependencyTag) bool { ccLibDepTag, ok := depTag.(libraryDependencyTag) return ok && ccLibDepTag.header() } func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool { ccDepTag, ok := depTag.(dependencyTag) return ok && ccDepTag == runtimeDepTag Loading cc/linkable.go +4 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,10 @@ func StaticDepTag() blueprint.DependencyTag { return libraryDependencyTag{Kind: staticLibraryDependency} } func HeaderDepTag() blueprint.DependencyTag { return libraryDependencyTag{Kind: headerLibraryDependency} } type SharedLibraryInfo struct { SharedLibrary android.Path UnstrippedSharedLibrary android.Path Loading rust/protobuf.go +45 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ package rust import ( "fmt" "strings" "android/soong/android" ) Loading @@ -22,6 +25,10 @@ var ( defaultProtobufFlags = []string{""} ) const ( grpcSuffix = "_grpc" ) type PluginType int const ( Loading @@ -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 { Loading Loading @@ -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") Loading @@ -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{} Loading Loading @@ -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 } Loading rust/protobuf_test.go +51 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,16 @@ func TestRustProtobuf(t *testing.T) { proto: "buf.proto", crate_name: "rust_proto", 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. Loading @@ -43,6 +53,13 @@ func TestRustProtobuf(t *testing.T) { 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) { Loading @@ -52,6 +69,16 @@ func TestRustGrpcio(t *testing.T) { proto: "buf.proto", crate_name: "rust_grpcio", 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"], } `) Loading @@ -61,10 +88,33 @@ func TestRustGrpcio(t *testing.T) { 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. 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 if w := "protoc-gen-grpc"; !strings.Contains(cmd, w) { 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) } } rust/rust.go +8 −0 Original line number Diff line number Diff line Loading @@ -229,6 +229,7 @@ type Deps struct { ProcMacros []string SharedLibs []string StaticLibs []string HeaderLibs []string CrtBegin, CrtEnd string } Loading Loading @@ -838,6 +839,11 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { directSharedLibDeps = append(directSharedLibDeps, ccDep) mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName) 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: depPaths.CrtBegin = linkObject case depTag == cc.CrtEndDepTag: Loading Loading @@ -983,6 +989,8 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { blueprint.Variation{Mutator: "link", Variation: "static"}), cc.StaticDepTag(), deps.StaticLibs...) actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) crtVariations := cc.GetCrtVariations(ctx, mod) if deps.CrtBegin != "" { actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin) Loading Loading
cc/cc.go +5 −0 Original line number Diff line number Diff line Loading @@ -592,6 +592,11 @@ func IsStaticDepTag(depTag blueprint.DependencyTag) bool { return ok && ccLibDepTag.static() } func IsHeaderDepTag(depTag blueprint.DependencyTag) bool { ccLibDepTag, ok := depTag.(libraryDependencyTag) return ok && ccLibDepTag.header() } func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool { ccDepTag, ok := depTag.(dependencyTag) return ok && ccDepTag == runtimeDepTag Loading
cc/linkable.go +4 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,10 @@ func StaticDepTag() blueprint.DependencyTag { return libraryDependencyTag{Kind: staticLibraryDependency} } func HeaderDepTag() blueprint.DependencyTag { return libraryDependencyTag{Kind: headerLibraryDependency} } type SharedLibraryInfo struct { SharedLibrary android.Path UnstrippedSharedLibrary android.Path Loading
rust/protobuf.go +45 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,9 @@ package rust import ( "fmt" "strings" "android/soong/android" ) Loading @@ -22,6 +25,10 @@ var ( defaultProtobufFlags = []string{""} ) const ( grpcSuffix = "_grpc" ) type PluginType int const ( Loading @@ -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 { Loading Loading @@ -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") Loading @@ -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{} Loading Loading @@ -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 } Loading
rust/protobuf_test.go +51 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,16 @@ func TestRustProtobuf(t *testing.T) { proto: "buf.proto", crate_name: "rust_proto", 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. Loading @@ -43,6 +53,13 @@ func TestRustProtobuf(t *testing.T) { 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) { Loading @@ -52,6 +69,16 @@ func TestRustGrpcio(t *testing.T) { proto: "buf.proto", crate_name: "rust_grpcio", 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"], } `) Loading @@ -61,10 +88,33 @@ func TestRustGrpcio(t *testing.T) { 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. 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 if w := "protoc-gen-grpc"; !strings.Contains(cmd, w) { 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) } }
rust/rust.go +8 −0 Original line number Diff line number Diff line Loading @@ -229,6 +229,7 @@ type Deps struct { ProcMacros []string SharedLibs []string StaticLibs []string HeaderLibs []string CrtBegin, CrtEnd string } Loading Loading @@ -838,6 +839,11 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { directSharedLibDeps = append(directSharedLibDeps, ccDep) mod.Properties.AndroidMkSharedLibs = append(mod.Properties.AndroidMkSharedLibs, depName) 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: depPaths.CrtBegin = linkObject case depTag == cc.CrtEndDepTag: Loading Loading @@ -983,6 +989,8 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { blueprint.Variation{Mutator: "link", Variation: "static"}), cc.StaticDepTag(), deps.StaticLibs...) actx.AddVariationDependencies(nil, cc.HeaderDepTag(), deps.HeaderLibs...) crtVariations := cc.GetCrtVariations(ctx, mod) if deps.CrtBegin != "" { actx.AddVariationDependencies(crtVariations, cc.CrtBeginDepTag, deps.CrtBegin) Loading