summaryrefslogtreecommitdiff
path: root/rust/rust.go
diff options
context:
space:
mode:
Diffstat (limited to 'rust/rust.go')
-rw-r--r--rust/rust.go72
1 files changed, 46 insertions, 26 deletions
diff --git a/rust/rust.go b/rust/rust.go
index c465cb609..b3e543ee9 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -156,13 +156,15 @@ type Module struct {
sourceProvider SourceProvider
subAndroidMkOnce map[SubAndroidMkProvider]bool
- // Unstripped output. This is usually used when this module is linked to another module
- // as a library. The stripped output which is used for installation can be found via
- // compiler.strippedOutputFile if it exists.
- unstrippedOutputFile android.OptionalPath
- docTimestampFile android.OptionalPath
+ // Output file to be installed, may be stripped or unstripped.
+ outputFile android.OptionalPath
+
+ docTimestampFile android.OptionalPath
hideApexVariantFromMake bool
+
+ // For apex variants, this is set as apex.min_sdk_version
+ apexSdkVersion android.ApiLevel
}
func (mod *Module) Header() bool {
@@ -281,8 +283,8 @@ func (mod *Module) Object() bool {
func (mod *Module) Toc() android.OptionalPath {
if mod.compiler != nil {
- if _, ok := mod.compiler.(libraryInterface); ok {
- return android.OptionalPath{}
+ if lib, ok := mod.compiler.(libraryInterface); ok {
+ return lib.toc()
}
}
panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName()))
@@ -465,6 +467,7 @@ type compiler interface {
stdLinkage(ctx *depsContext) RustLinkage
+ unstrippedOutputFilePath() android.Path
strippedOutputFilePath() android.OptionalPath
}
@@ -593,8 +596,8 @@ func (mod *Module) CcLibraryInterface() bool {
}
func (mod *Module) UnstrippedOutputFile() android.Path {
- if mod.unstrippedOutputFile.Valid() {
- return mod.unstrippedOutputFile.Path()
+ if mod.compiler != nil {
+ return mod.compiler.unstrippedOutputFilePath()
}
return nil
}
@@ -651,10 +654,7 @@ func (mod *Module) Module() android.Module {
}
func (mod *Module) OutputFile() android.OptionalPath {
- if mod.compiler != nil && mod.compiler.strippedOutputFilePath().Valid() {
- return mod.compiler.strippedOutputFilePath()
- }
- return mod.unstrippedOutputFile
+ return mod.outputFile
}
func (mod *Module) CoverageFiles() android.Paths {
@@ -678,6 +678,10 @@ func (mod *Module) installable(apexInfo android.ApexInfo) bool {
return mod.OutputFile().Valid() && !mod.Properties.PreventInstall
}
+func (ctx moduleContext) apexVariationName() string {
+ return ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
+}
+
var _ cc.LinkableInterface = (*Module)(nil)
func (mod *Module) Init() android.Module {
@@ -885,9 +889,12 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
if mod.compiler != nil && !mod.compiler.Disabled() {
mod.compiler.initialize(ctx)
- unstrippedOutputFile := mod.compiler.compile(ctx, flags, deps)
- mod.unstrippedOutputFile = android.OptionalPathForPath(unstrippedOutputFile)
- bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), mod.unstrippedOutputFile)
+ outputFile := mod.compiler.compile(ctx, flags, deps)
+ if ctx.Failed() {
+ return
+ }
+ mod.outputFile = android.OptionalPathForPath(outputFile)
+ bloaty.MeasureSizeForPaths(ctx, mod.compiler.strippedOutputFilePath(), android.OptionalPathForPath(mod.compiler.unstrippedOutputFilePath()))
mod.docTimestampFile = mod.compiler.rustdoc(ctx, flags, deps)
@@ -1023,6 +1030,20 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
directSrcProvidersDeps := []*Module{}
directSrcDeps := [](android.SourceFileProducer){}
+ // For the dependency from platform to apex, use the latest stubs
+ mod.apexSdkVersion = android.FutureApiLevel
+ apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
+ if !apexInfo.IsForPlatform() {
+ mod.apexSdkVersion = apexInfo.MinSdkVersion
+ }
+
+ if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
+ // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
+ // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
+ // (b/144430859)
+ mod.apexSdkVersion = android.FutureApiLevel
+ }
+
ctx.VisitDirectDeps(func(dep android.Module) {
depName := ctx.OtherModuleName(dep)
depTag := ctx.OtherModuleDependencyTag(dep)
@@ -1083,13 +1104,8 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
}
if depTag == dylibDepTag || depTag == rlibDepTag || depTag == procMacroDepTag {
- linkFile := rustDep.unstrippedOutputFile
- if !linkFile.Valid() {
- ctx.ModuleErrorf("Invalid output file when adding dep %q to %q",
- depName, ctx.ModuleName())
- return
- }
- linkDir := linkPathFromFilePath(linkFile.Path())
+ linkFile := rustDep.UnstrippedOutputFile()
+ linkDir := linkPathFromFilePath(linkFile)
if lib, ok := mod.compiler.(exportedFlagsProducer); ok {
lib.exportLinkDirs(linkDir)
}
@@ -1198,15 +1214,15 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
var rlibDepFiles RustLibraries
for _, dep := range directRlibDeps {
- rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
+ rlibDepFiles = append(rlibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
}
var dylibDepFiles RustLibraries
for _, dep := range directDylibDeps {
- dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
+ dylibDepFiles = append(dylibDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
}
var procMacroDepFiles RustLibraries
for _, dep := range directProcMacroDeps {
- procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.unstrippedOutputFile.Path(), CrateName: dep.CrateName()})
+ procMacroDepFiles = append(procMacroDepFiles, RustLibrary{Path: dep.UnstrippedOutputFile(), CrateName: dep.CrateName()})
}
var staticLibDepFiles android.Paths
@@ -1273,6 +1289,10 @@ func (mod *Module) InstallInRecovery() bool {
return mod.InRecovery()
}
+func (mod *Module) InstallBypassMake() bool {
+ return true
+}
+
func linkPathFromFilePath(filepath android.Path) string {
return strings.Split(filepath.String(), filepath.Base())[0]
}