summaryrefslogtreecommitdiff
path: root/rust/rust.go
diff options
context:
space:
mode:
Diffstat (limited to 'rust/rust.go')
-rw-r--r--rust/rust.go77
1 files changed, 19 insertions, 58 deletions
diff --git a/rust/rust.go b/rust/rust.go
index d4d33c71d..521f624a2 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -18,14 +18,12 @@ import (
"fmt"
"strings"
- "android/soong/bazel"
"android/soong/bloaty"
"android/soong/testing"
- "android/soong/ui/metrics/bp2build_metrics_proto"
-
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
+ "android/soong/aconfig"
"android/soong/android"
"android/soong/cc"
cc_config "android/soong/cc/config"
@@ -175,7 +173,8 @@ type Module struct {
transitiveAndroidMkSharedLibs *android.DepSet[string]
- android.BazelModuleBase
+ // Aconfig files for all transitive deps. Also exposed via TransitiveDeclarationsInfo
+ mergedAconfigFiles map[string]android.Paths
}
func (mod *Module) Header() bool {
@@ -510,7 +509,7 @@ func (flagExporter *flagExporter) exportLinkObjects(flags ...string) {
}
func (flagExporter *flagExporter) setProvider(ctx ModuleContext) {
- ctx.SetProvider(FlagExporterInfoProvider, FlagExporterInfo{
+ android.SetProvider(ctx, FlagExporterInfoProvider, FlagExporterInfo{
LinkDirs: flagExporter.linkDirs,
LinkObjects: flagExporter.linkObjects,
})
@@ -528,7 +527,7 @@ type FlagExporterInfo struct {
LinkObjects []string // TODO: this should be android.Paths
}
-var FlagExporterInfoProvider = blueprint.NewProvider(FlagExporterInfo{})
+var FlagExporterInfoProvider = blueprint.NewProvider[FlagExporterInfo]()
func (mod *Module) isCoverageVariant() bool {
return mod.coverage.Properties.IsCoverageVariant
@@ -748,7 +747,8 @@ func (mod *Module) installable(apexInfo android.ApexInfo) bool {
}
func (ctx moduleContext) apexVariationName() string {
- return ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
+ apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
+ return apexInfo.ApexVariationName
}
var _ cc.LinkableInterface = (*Module)(nil)
@@ -898,7 +898,7 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
ModuleContext: actx,
}
- apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ apexInfo, _ := android.ModuleProvider(actx, android.ApexInfoProvider)
if !apexInfo.IsForPlatform() {
mod.hideApexVariantFromMake = true
}
@@ -951,6 +951,7 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
sourceLib := sourceMod.(*Module).compiler.(*libraryDecorator)
mod.sourceProvider.setOutputFiles(sourceLib.sourceProvider.Srcs())
}
+ android.SetProvider(ctx, blueprint.SrcsFileProviderKey, blueprint.SrcsFileProviderData{SrcPaths: mod.sourceProvider.Srcs().Strings()})
}
if mod.compiler != nil && !mod.compiler.Disabled() {
@@ -978,7 +979,7 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
}
}
- apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ apexInfo, _ := android.ModuleProvider(actx, android.ApexInfoProvider)
if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() {
// If the module has been specifically configure to not be installed then
// hide from make as otherwise it will break when running inside make as the
@@ -1003,8 +1004,10 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
ctx.Phony("rust", ctx.RustModule().OutputFile().Path())
}
if mod.testModule {
- ctx.SetProvider(testing.TestModuleProviderKey, testing.TestModuleProviderData{})
+ android.SetProvider(ctx, testing.TestModuleProviderKey, testing.TestModuleProviderData{})
}
+
+ aconfig.CollectDependencyAconfigFiles(ctx, &mod.mergedAconfigFiles)
}
func (mod *Module) deps(ctx DepsContext) Deps {
@@ -1146,7 +1149,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// For the dependency from platform to apex, use the latest stubs
mod.apexSdkVersion = android.FutureApiLevel
- apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ apexInfo, _ := android.ModuleProvider(ctx, android.ApexInfoProvider)
if !apexInfo.IsForPlatform() {
mod.apexSdkVersion = apexInfo.MinSdkVersion
}
@@ -1165,7 +1168,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
ctx.VisitDirectDeps(func(dep android.Module) {
if dep.Name() == "api_imports" {
- apiImportInfo = ctx.OtherModuleProvider(dep, multitree.ApiImportsProvider).(multitree.ApiImportInfo)
+ apiImportInfo, _ = android.OtherModuleProvider(ctx, dep, multitree.ApiImportsProvider)
hasApiImportInfo = true
}
})
@@ -1276,7 +1279,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
//Append the dependencies exportedDirs, except for proc-macros which target a different arch/OS
if depTag != procMacroDepTag {
- exportedInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
+ exportedInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider)
depPaths.linkDirs = append(depPaths.linkDirs, exportedInfo.LinkDirs...)
depPaths.depFlags = append(depPaths.depFlags, exportedInfo.Flags...)
depPaths.linkObjects = append(depPaths.linkObjects, exportedInfo.LinkObjects...)
@@ -1292,7 +1295,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
if depTag == sourceDepTag {
if _, ok := mod.sourceProvider.(*protobufDecorator); ok && mod.Source() {
if _, ok := rustDep.sourceProvider.(*protobufDecorator); ok {
- exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
+ exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider)
depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
}
}
@@ -1345,7 +1348,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
depPaths.linkObjects = append(depPaths.linkObjects, linkObject.String())
depPaths.linkDirs = append(depPaths.linkDirs, linkPath)
- exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
+ exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider)
depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...)
@@ -1389,7 +1392,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
directAndroidMkSharedLibs = append(directAndroidMkSharedLibs, makeLibName)
exportDep = true
case cc.IsHeaderDepTag(depTag):
- exportedInfo := ctx.OtherModuleProvider(dep, cc.FlagExporterInfoProvider).(cc.FlagExporterInfo)
+ exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider)
depPaths.depIncludePaths = append(depPaths.depIncludePaths, exportedInfo.IncludeDirs...)
depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...)
depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...)
@@ -1849,48 +1852,6 @@ func (c *Module) Partition() string {
return ""
}
-func (m *Module) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
- if ctx.ModuleType() == "rust_library_host" || ctx.ModuleType() == "rust_library" {
- libraryBp2build(ctx, m)
- } else if ctx.ModuleType() == "rust_proc_macro" {
- procMacroBp2build(ctx, m)
- } else if ctx.ModuleType() == "rust_binary_host" {
- binaryBp2build(ctx, m)
- } else if ctx.ModuleType() == "rust_protobuf_host" || ctx.ModuleType() == "rust_protobuf" {
- protoLibraryBp2build(ctx, m)
- } else if ctx.ModuleType() == "rust_ffi_static" {
- ffiStaticBp2build(ctx, m)
- } else {
- ctx.MarkBp2buildUnconvertible(bp2build_metrics_proto.UnconvertedReasonType_TYPE_UNSUPPORTED, "")
- }
-}
-
-// This is a workaround by assuming the conventions that rust crate repos are structured
-// while waiting for the sandboxing work to complete.
-// TODO(b/297344471): When crate_root prop is set which enforces inputs sandboxing,
-// always use `srcs` and `compile_data` props to generate `srcs` and `compile_data` attributes
-// instead of using globs.
-func srcsAndCompileDataAttrs(ctx android.Bp2buildMutatorContext, c baseCompiler) (bazel.LabelList, bazel.LabelList) {
- var srcs bazel.LabelList
- var compileData bazel.LabelList
-
- if c.Properties.Srcs[0] == "src/lib.rs" {
- srcs = android.BazelLabelForModuleSrc(ctx, []string{"src/**/*.rs"})
- compileData = android.BazelLabelForModuleSrc(
- ctx,
- []string{
- "src/**/*.proto",
- "examples/**/*.rs",
- "**/*.md",
- },
- )
- } else {
- srcs = android.BazelLabelForModuleSrc(ctx, c.Properties.Srcs)
- }
-
- return srcs, compileData
-}
-
var Bool = proptools.Bool
var BoolDefault = proptools.BoolDefault
var String = proptools.String