rust: Add vendor and recovery dylib support.
Adds dylib support for vendor and recovery images. This changes the default linkage for vendor and recovery images to dylib, which matches the platform default linkage. This also means that by default, dylib-std variants are used for rlib dependencies. Bug: 204303985 Test: Soong tests. Test: m dist vendor-snapshot Test: RECOVERY_SNAPSHOT_VERSION=current m dist recovery-snapshot Change-Id: If84074b8615a70c45e7e162abeb853dc8c34d49a
This commit is contained in:
45
rust/rust.go
45
rust/rust.go
@@ -91,6 +91,8 @@ type BaseProperties struct {
|
||||
// Used by vendor snapshot to record dependencies from snapshot modules.
|
||||
SnapshotSharedLibs []string `blueprint:"mutated"`
|
||||
SnapshotStaticLibs []string `blueprint:"mutated"`
|
||||
SnapshotRlibs []string `blueprint:"mutated"`
|
||||
SnapshotDylibs []string `blueprint:"mutated"`
|
||||
|
||||
// Make this module available when building for ramdisk.
|
||||
// On device without a dedicated recovery partition, the module is only
|
||||
@@ -258,6 +260,15 @@ func (mod *Module) Dylib() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (mod *Module) RlibStd() bool {
|
||||
if mod.compiler != nil {
|
||||
if library, ok := mod.compiler.(libraryInterface); ok && library.rlib() {
|
||||
return library.rlibStd()
|
||||
}
|
||||
}
|
||||
panic(fmt.Errorf("RlibStd() called on non-rlib module: %q", mod.BaseModuleName()))
|
||||
}
|
||||
|
||||
func (mod *Module) Rlib() bool {
|
||||
if mod.compiler != nil {
|
||||
if library, ok := mod.compiler.(libraryInterface); ok {
|
||||
@@ -1225,6 +1236,8 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||
}
|
||||
directDylibDeps = append(directDylibDeps, rustDep)
|
||||
mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
|
||||
mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName))
|
||||
|
||||
case rlibDepTag:
|
||||
|
||||
rlib, ok := rustDep.compiler.(libraryInterface)
|
||||
@@ -1234,6 +1247,8 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||
}
|
||||
directRlibDeps = append(directRlibDeps, rustDep)
|
||||
mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
|
||||
mod.Properties.SnapshotRlibs = append(mod.Properties.SnapshotRlibs, cc.BaseLibName(depName))
|
||||
|
||||
case procMacroDepTag:
|
||||
directProcMacroDeps = append(directProcMacroDeps, rustDep)
|
||||
mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
|
||||
@@ -1518,10 +1533,10 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
}
|
||||
|
||||
// dylibs
|
||||
actx.AddVariationDependencies(
|
||||
append(commonDepVariations, []blueprint.Variation{
|
||||
{Mutator: "rust_libraries", Variation: dylibVariation}}...),
|
||||
dylibDepTag, deps.Dylibs...)
|
||||
dylibDepVariations := append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: dylibVariation})
|
||||
for _, lib := range deps.Dylibs {
|
||||
addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag)
|
||||
}
|
||||
|
||||
// rustlibs
|
||||
if deps.Rustlibs != nil && !mod.compiler.Disabled() {
|
||||
@@ -1536,8 +1551,11 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
// otherwise select the rlib variant.
|
||||
autoDepVariations := append(commonDepVariations,
|
||||
blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation})
|
||||
if actx.OtherModuleDependencyVariantExists(autoDepVariations, lib) {
|
||||
actx.AddVariationDependencies(autoDepVariations, autoDep.depTag, lib)
|
||||
|
||||
replacementLib := cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Dylibs)
|
||||
|
||||
if actx.OtherModuleDependencyVariantExists(autoDepVariations, replacementLib) {
|
||||
addDylibDependency(actx, lib, mod, &snapshotInfo, autoDepVariations, autoDep.depTag)
|
||||
} else {
|
||||
// If there's no dylib dependency available, try to add the rlib dependency instead.
|
||||
addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations)
|
||||
@@ -1549,16 +1567,14 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
if deps.Stdlibs != nil {
|
||||
if mod.compiler.stdLinkage(ctx) == RlibLinkage {
|
||||
for _, lib := range deps.Stdlibs {
|
||||
depTag := rlibDepTag
|
||||
lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
|
||||
|
||||
actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...),
|
||||
depTag, lib)
|
||||
rlibDepTag, lib)
|
||||
}
|
||||
} else {
|
||||
actx.AddVariationDependencies(
|
||||
append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}),
|
||||
dylibDepTag, deps.Stdlibs...)
|
||||
for _, lib := range deps.Stdlibs {
|
||||
addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1636,6 +1652,11 @@ func addRlibDependency(actx android.BottomUpMutatorContext, lib string, mod *Mod
|
||||
actx.AddVariationDependencies(variations, rlibDepTag, lib)
|
||||
}
|
||||
|
||||
func addDylibDependency(actx android.BottomUpMutatorContext, lib string, mod *Module, snapshotInfo **cc.SnapshotInfo, variations []blueprint.Variation, depTag dependencyTag) {
|
||||
lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, snapshotInfo, actx).Dylibs)
|
||||
actx.AddVariationDependencies(variations, depTag, lib)
|
||||
}
|
||||
|
||||
func BeginMutator(ctx android.BottomUpMutatorContext) {
|
||||
if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
|
||||
mod.beginMutator(ctx)
|
||||
|
Reference in New Issue
Block a user