diff options
Diffstat (limited to 'rust/rust.go')
-rw-r--r-- | rust/rust.go | 88 |
1 files changed, 63 insertions, 25 deletions
diff --git a/rust/rust.go b/rust/rust.go index 81c33e688..7a7b1064c 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -495,6 +495,10 @@ type PathDeps struct { depFlags []string depLinkFlags []string + // track cc static-libs that have Rlib dependencies + reexportedCcRlibDeps []cc.RustRlibDep + ccRlibDeps []cc.RustRlibDep + // linkDirs are link paths passed via -L to rustc. linkObjects are objects passed directly to the linker // Both of these are exported and propagate to dependencies. linkDirs []string @@ -573,8 +577,8 @@ func (flagExporter *flagExporter) exportWholeStaticLibs(flags ...string) { flagExporter.wholeStaticLibObjects = android.FirstUniqueStrings(append(flagExporter.wholeStaticLibObjects, flags...)) } -func (flagExporter *flagExporter) setProvider(ctx ModuleContext) { - android.SetProvider(ctx, FlagExporterInfoProvider, FlagExporterInfo{ +func (flagExporter *flagExporter) setRustProvider(ctx ModuleContext) { + android.SetProvider(ctx, RustFlagExporterInfoProvider, RustFlagExporterInfo{ LinkDirs: flagExporter.linkDirs, RustLibObjects: flagExporter.rustLibPaths, StaticLibObjects: flagExporter.staticLibObjects, @@ -589,7 +593,7 @@ func NewFlagExporter() *flagExporter { return &flagExporter{} } -type FlagExporterInfo struct { +type RustFlagExporterInfo struct { Flags []string LinkDirs []string RustLibObjects []string @@ -598,7 +602,7 @@ type FlagExporterInfo struct { SharedLibPaths []string } -var FlagExporterInfoProvider = blueprint.NewProvider[FlagExporterInfo]() +var RustFlagExporterInfoProvider = blueprint.NewProvider[RustFlagExporterInfo]() func (mod *Module) isCoverageVariant() bool { return mod.coverage.Properties.IsCoverageVariant @@ -1199,10 +1203,11 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { // Define the linker info if compiler != nil because Rust currently // does compilation and linking in one step. If this changes in the future, // move this as appropriate. + baseCompilerProps := mod.compiler.baseCompilerProps() ccInfo.LinkerInfo = &cc.LinkerInfo{ - WholeStaticLibs: mod.compiler.baseCompilerProps().Whole_static_libs, - StaticLibs: mod.compiler.baseCompilerProps().Static_libs, - SharedLibs: mod.compiler.baseCompilerProps().Shared_libs, + WholeStaticLibs: baseCompilerProps.Whole_static_libs.GetOrDefault(ctx, nil), + StaticLibs: baseCompilerProps.Static_libs.GetOrDefault(ctx, nil), + SharedLibs: baseCompilerProps.Shared_libs.GetOrDefault(ctx, nil), } android.SetProvider(ctx, cc.CcInfoProvider, ccInfo) @@ -1530,6 +1535,13 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { } } + if !mod.Rlib() { + depPaths.ccRlibDeps = append(depPaths.ccRlibDeps, exportedInfo.RustRlibDeps...) + } else { + // rlibs need to reexport these + depPaths.reexportedCcRlibDeps = append(depPaths.reexportedCcRlibDeps, exportedInfo.RustRlibDeps...) + } + case depTag == procMacroDepTag: directProcMacroDeps = append(directProcMacroDeps, linkableInfo) mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName) @@ -1573,7 +1585,7 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { directSrcProvidersDeps = append(directSrcProvidersDeps, &dep) } - exportedInfo, _ := android.OtherModuleProvider(ctx, dep, FlagExporterInfoProvider) + exportedInfo, _ := android.OtherModuleProvider(ctx, dep, RustFlagExporterInfoProvider) //Append the dependencies exported objects, except for proc-macros which target a different arch/OS if depTag != procMacroDepTag { @@ -1650,8 +1662,8 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { } else { // Otherwise add to staticLibObjects, which only propagate through rlibs to their dependents. depPaths.staticLibObjects = append(depPaths.staticLibObjects, ccLibPath.String()) - } + depPaths.linkDirs = append(depPaths.linkDirs, linkPath) exportedInfo, _ := android.OtherModuleProvider(ctx, dep, cc.FlagExporterInfoProvider) @@ -1659,6 +1671,14 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { depPaths.depSystemIncludePaths = append(depPaths.depSystemIncludePaths, exportedInfo.SystemIncludeDirs...) depPaths.depClangFlags = append(depPaths.depClangFlags, exportedInfo.Flags...) depPaths.depGeneratedHeaders = append(depPaths.depGeneratedHeaders, exportedInfo.GeneratedHeaders...) + + if !mod.Rlib() { + // rlibs don't need to build the generated static library, so they don't need to track these. + depPaths.ccRlibDeps = append(depPaths.ccRlibDeps, exportedInfo.RustRlibDeps...) + } else { + depPaths.reexportedCcRlibDeps = append(depPaths.reexportedCcRlibDeps, exportedInfo.RustRlibDeps...) + } + directStaticLibDeps = append(directStaticLibDeps, linkableInfo) // Record baseLibName for snapshots. @@ -1814,6 +1834,8 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps { depPaths.depIncludePaths = android.FirstUniquePaths(depPaths.depIncludePaths) depPaths.depSystemIncludePaths = android.FirstUniquePaths(depPaths.depSystemIncludePaths) depPaths.depLinkFlags = android.FirstUniqueStrings(depPaths.depLinkFlags) + depPaths.reexportedCcRlibDeps = android.FirstUniqueFunc(depPaths.reexportedCcRlibDeps, cc.EqRustRlibDeps) + depPaths.ccRlibDeps = android.FirstUniqueFunc(depPaths.ccRlibDeps, cc.EqRustRlibDeps) return depPaths } @@ -2063,26 +2085,23 @@ func (mod *Module) MinSdkVersion() string { } // Implements android.ApexModule -func (mod *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion android.ApiLevel) error { +func (mod *Module) MinSdkVersionSupported(ctx android.BaseModuleContext) android.ApiLevel { minSdkVersion := mod.MinSdkVersion() if minSdkVersion == "apex_inherit" { - return nil + return android.MinApiLevel } + if minSdkVersion == "" { - return fmt.Errorf("min_sdk_version is not specificed") + return android.NoneApiLevel } - // Not using nativeApiLevelFromUser because the context here is not // necessarily a native context. - ver, err := android.ApiLevelFromUser(ctx, minSdkVersion) + ver, err := android.ApiLevelFromUserWithConfig(ctx.Config(), minSdkVersion) if err != nil { - return err + return android.NoneApiLevel } - if ver.GreaterThan(sdkVersion) { - return fmt.Errorf("newer SDK(%v)", ver) - } - return nil + return ver } // Implements android.ApexModule @@ -2093,12 +2112,28 @@ func (mod *Module) AlwaysRequiresPlatformApexVariant() bool { } // Implements android.ApexModule -func (mod *Module) OutgoingDepIsInSameApex(depTag blueprint.DependencyTag) bool { +type RustDepInSameApexChecker struct { + Static bool + HasStubsVariants bool + ApexExclude bool + Host bool +} + +func (mod *Module) GetDepInSameApexChecker() android.DepInSameApexChecker { + return RustDepInSameApexChecker{ + Static: mod.Static(), + HasStubsVariants: mod.HasStubsVariants(), + ApexExclude: mod.ApexExclude(), + Host: mod.Host(), + } +} + +func (r RustDepInSameApexChecker) OutgoingDepIsInSameApex(depTag blueprint.DependencyTag) bool { if depTag == procMacroDepTag || depTag == customBindgenDepTag { return false } - if mod.Static() && cc.IsSharedDepTag(depTag) { + if r.Static && cc.IsSharedDepTag(depTag) { // shared_lib dependency from a static lib is considered as crossing // the APEX boundary because the dependency doesn't actually is // linked; the dependency is used only during the compilation phase. @@ -2115,20 +2150,23 @@ func (mod *Module) OutgoingDepIsInSameApex(depTag blueprint.DependencyTag) bool } // TODO(b/362509506): remove once all apex_exclude uses are switched to stubs. - if mod.ApexExclude() { + if r.ApexExclude { return false } return true } -func (mod *Module) IncomingDepIsInSameApex(depTag blueprint.DependencyTag) bool { +func (r RustDepInSameApexChecker) IncomingDepIsInSameApex(depTag blueprint.DependencyTag) bool { + if r.Host { + return false + } // TODO(b/362509506): remove once all apex_exclude uses are switched to stubs. - if mod.ApexExclude() { + if r.ApexExclude { return false } - if mod.HasStubsVariants() { + if r.HasStubsVariants { if cc.IsSharedDepTag(depTag) && !cc.IsExplicitImplSharedDepTag(depTag) { // dynamic dep to a stubs lib crosses APEX boundary return false |