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:
Ivan Lozano 2023-07-13 11:01:41 -04:00
parent e3c11d0aad
commit add122a828
14 changed files with 378 additions and 147 deletions

View file

@ -10553,6 +10553,7 @@ func TestTrimmedApex(t *testing.T) {
src: "libc.so", src: "libc.so",
min_sdk_version: "29", min_sdk_version: "29",
recovery_available: true, recovery_available: true,
vendor_available: true,
} }
api_imports { api_imports {
name: "api_imports", name: "api_imports",

View file

@ -1079,6 +1079,10 @@ func (c *Module) CcLibraryInterface() bool {
return false return false
} }
func (c *Module) RlibStd() bool {
panic(fmt.Errorf("RlibStd called on non-Rust module: %q", c.BaseModuleName()))
}
func (c *Module) RustLibraryInterface() bool { func (c *Module) RustLibraryInterface() bool {
return false return false
} }

View file

@ -87,6 +87,12 @@ type Snapshottable interface {
// SnapshotStaticLibs returns the list of static library dependencies for this module. // SnapshotStaticLibs returns the list of static library dependencies for this module.
SnapshotStaticLibs() []string SnapshotStaticLibs() []string
// SnapshotDylibs returns the list of dylib library dependencies for this module.
SnapshotDylibs() []string
// SnapshotRlibs returns the list of rlib library dependencies for this module.
SnapshotRlibs() []string
// IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt. // IsSnapshotPrebuilt returns true if this module is a snapshot prebuilt.
IsSnapshotPrebuilt() bool IsSnapshotPrebuilt() bool
} }
@ -239,6 +245,9 @@ type LinkableInterface interface {
// Dylib returns true if this is an dylib module. // Dylib returns true if this is an dylib module.
Dylib() bool Dylib() bool
// RlibStd returns true if this is an rlib which links against an rlib libstd.
RlibStd() bool
// Static returns true if this is a static library module. // Static returns true if this is a static library module.
Static() bool Static() bool

View file

@ -100,6 +100,7 @@ const (
snapshotBinarySuffix = "_binary." snapshotBinarySuffix = "_binary."
snapshotObjectSuffix = "_object." snapshotObjectSuffix = "_object."
SnapshotRlibSuffix = "_rlib." SnapshotRlibSuffix = "_rlib."
SnapshotDylibSuffix = "_dylib."
) )
type SnapshotProperties struct { type SnapshotProperties struct {
@ -107,6 +108,7 @@ type SnapshotProperties struct {
Static_libs []string `android:"arch_variant"` Static_libs []string `android:"arch_variant"`
Shared_libs []string `android:"arch_variant"` Shared_libs []string `android:"arch_variant"`
Rlibs []string `android:"arch_variant"` Rlibs []string `android:"arch_variant"`
Dylibs []string `android:"arch_variant"`
Vndk_libs []string `android:"arch_variant"` Vndk_libs []string `android:"arch_variant"`
Binaries []string `android:"arch_variant"` Binaries []string `android:"arch_variant"`
Objects []string `android:"arch_variant"` Objects []string `android:"arch_variant"`
@ -186,6 +188,7 @@ func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) {
staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, SnapshotStaticSuffix) staticLibs := collectSnapshotMap(s.properties.Static_libs, snapshotSuffix, SnapshotStaticSuffix)
sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, SnapshotSharedSuffix) sharedLibs := collectSnapshotMap(s.properties.Shared_libs, snapshotSuffix, SnapshotSharedSuffix)
rlibs := collectSnapshotMap(s.properties.Rlibs, snapshotSuffix, SnapshotRlibSuffix) rlibs := collectSnapshotMap(s.properties.Rlibs, snapshotSuffix, SnapshotRlibSuffix)
dylibs := collectSnapshotMap(s.properties.Dylibs, snapshotSuffix, SnapshotDylibSuffix)
vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix) vndkLibs := collectSnapshotMap(s.properties.Vndk_libs, "", vndkSuffix)
for k, v := range vndkLibs { for k, v := range vndkLibs {
sharedLibs[k] = v sharedLibs[k] = v
@ -198,11 +201,12 @@ func (s *snapshotModule) DepsMutator(ctx android.BottomUpMutatorContext) {
StaticLibs: staticLibs, StaticLibs: staticLibs,
SharedLibs: sharedLibs, SharedLibs: sharedLibs,
Rlibs: rlibs, Rlibs: rlibs,
Dylibs: dylibs,
}) })
} }
type SnapshotInfo struct { type SnapshotInfo struct {
HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs map[string]string HeaderLibs, Binaries, Objects, StaticLibs, SharedLibs, Rlibs, Dylibs map[string]string
} }
var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps") var SnapshotInfoProvider = blueprint.NewMutatorProvider(SnapshotInfo{}, "deps")

View file

@ -57,6 +57,14 @@ func (m *Module) SnapshotStaticLibs() []string {
return m.Properties.SnapshotStaticLibs return m.Properties.SnapshotStaticLibs
} }
func (m *Module) SnapshotRlibs() []string {
return []string{}
}
func (m *Module) SnapshotDylibs() []string {
return []string{}
}
// snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots. // snapshotLibraryInterface is an interface for libraries captured to VNDK / vendor snapshots.
type snapshotLibraryInterface interface { type snapshotLibraryInterface interface {
libraryInterface libraryInterface

View file

@ -108,10 +108,10 @@ func isSnapshotAware(cfg android.DeviceConfig, m LinkableInterface, inProprietar
return false return false
} }
} }
if sanitizable.Static() { if sanitizable.Static() || sanitizable.Rlib() {
return sanitizable.OutputFile().Valid() && !isPrivate(image, m) return sanitizable.OutputFile().Valid() && !isPrivate(image, m)
} }
if sanitizable.Shared() || sanitizable.Rlib() { if sanitizable.Shared() || sanitizable.Dylib() {
if !sanitizable.OutputFile().Valid() { if !sanitizable.OutputFile().Valid() {
return false return false
} }
@ -153,6 +153,8 @@ type snapshotJsonFlags struct {
SharedLibs []string `json:",omitempty"` SharedLibs []string `json:",omitempty"`
StaticLibs []string `json:",omitempty"` StaticLibs []string `json:",omitempty"`
RuntimeLibs []string `json:",omitempty"` RuntimeLibs []string `json:",omitempty"`
Dylibs []string `json:",omitempty"`
Rlibs []string `json:",omitempty"`
// extra config files // extra config files
InitRc []string `json:",omitempty"` InitRc []string `json:",omitempty"`
@ -283,8 +285,17 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS
if m.Shared() { if m.Shared() {
prop.SharedLibs = m.SnapshotSharedLibs() prop.SharedLibs = m.SnapshotSharedLibs()
} }
// static libs dependencies are required to collect the NOTICE files.
// dylibs collect both shared and dylib dependencies.
if m.Dylib() {
prop.SharedLibs = m.SnapshotSharedLibs()
prop.Dylibs = m.SnapshotDylibs()
}
// static and rlib libs dependencies are required to collect the NOTICE files.
prop.StaticLibs = m.SnapshotStaticLibs() prop.StaticLibs = m.SnapshotStaticLibs()
prop.Rlibs = m.SnapshotRlibs()
if sanitizable, ok := m.(PlatformSanitizeable); ok { if sanitizable, ok := m.(PlatformSanitizeable); ok {
if sanitizable.Static() && sanitizable.SanitizePropDefined() { if sanitizable.Static() && sanitizable.SanitizePropDefined() {
prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded() prop.SanitizeMinimalDep = sanitizable.MinimalRuntimeDep() || sanitizable.MinimalRuntimeNeeded()
@ -299,13 +310,15 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS
libType = "shared" libType = "shared"
} else if m.Rlib() { } else if m.Rlib() {
libType = "rlib" libType = "rlib"
} else if m.Dylib() {
libType = "dylib"
} else { } else {
libType = "header" libType = "header"
} }
var stem string var stem string
// install .a or .so // install .a, .rlib, .dylib.so, or .so
if libType != "header" { if libType != "header" {
libPath := m.OutputFile().Path() libPath := m.OutputFile().Path()
stem = libPath.Base() stem = libPath.Base()
@ -328,6 +341,12 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS
} }
} }
} }
if m.Rlib() && m.RlibStd() {
// rlibs produce both rlib-std and dylib-std variants
ext := filepath.Ext(stem)
stem = strings.TrimSuffix(stem, ext) + ".rlib-std" + ext
prop.ModuleName += ".rlib-std"
}
snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, m.RelativeInstallPath(), stem) snapshotLibOut := filepath.Join(snapshotArchDir, targetArch, libType, m.RelativeInstallPath(), stem)
ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake)) ret = append(ret, copyFile(ctx, libPath, snapshotLibOut, fake))
} else { } else {
@ -341,8 +360,12 @@ var ccSnapshotAction snapshot.GenerateSnapshotAction = func(s snapshot.SnapshotS
prop.StaticExecutable = m.StaticExecutable() prop.StaticExecutable = m.StaticExecutable()
prop.InstallInRoot = m.InstallInRoot() prop.InstallInRoot = m.InstallInRoot()
prop.SharedLibs = m.SnapshotSharedLibs() prop.SharedLibs = m.SnapshotSharedLibs()
// static libs dependencies are required to collect the NOTICE files. prop.Dylibs = m.SnapshotDylibs()
// static and rlib dependencies are required to collect the NOTICE files.
prop.StaticLibs = m.SnapshotStaticLibs() prop.StaticLibs = m.SnapshotStaticLibs()
prop.Rlibs = m.SnapshotRlibs()
// install bin // install bin
binPath := m.OutputFile().Path() binPath := m.OutputFile().Path()
snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base()) snapshotBinOut := filepath.Join(snapshotArchDir, targetArch, "binary", binPath.Base())

View file

@ -158,9 +158,6 @@ func (binary *binaryDecorator) autoDep(ctx android.BottomUpMutatorContext) autoD
// Binaries default to dylib dependencies for device, rlib for host. // Binaries default to dylib dependencies for device, rlib for host.
if binary.preferRlib() { if binary.preferRlib() {
return rlibAutoDep return rlibAutoDep
} else if mod, ok := ctx.Module().(*Module); ok && mod.InVendor() {
// Vendor Rust binaries should prefer rlibs.
return rlibAutoDep
} else if ctx.Device() { } else if ctx.Device() {
return dylibAutoDep return dylibAutoDep
} else { } else {
@ -171,8 +168,6 @@ func (binary *binaryDecorator) autoDep(ctx android.BottomUpMutatorContext) autoD
func (binary *binaryDecorator) stdLinkage(ctx *depsContext) RustLinkage { func (binary *binaryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
if binary.preferRlib() { if binary.preferRlib() {
return RlibLinkage return RlibLinkage
} else if ctx.RustModule().InVendor() {
return RlibLinkage
} }
return binary.baseCompiler.stdLinkage(ctx) return binary.baseCompiler.stdLinkage(ctx)
} }

View file

@ -220,9 +220,6 @@ func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant stri
} }
func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) { func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
// Rust does not support installing to the product image yet.
vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
if Bool(mod.VendorProperties.Double_loadable) { if Bool(mod.VendorProperties.Double_loadable) {
mctx.PropertyErrorf("double_loadable", mctx.PropertyErrorf("double_loadable",
"Rust modules do not yet support double loading") "Rust modules do not yet support double loading")
@ -232,11 +229,6 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
mctx.PropertyErrorf("vendor_ramdisk_available", "cannot be set for rust_ffi or rust_ffi_shared modules.") mctx.PropertyErrorf("vendor_ramdisk_available", "cannot be set for rust_ffi or rust_ffi_shared modules.")
} }
} }
if vendorSpecific {
if lib, ok := mod.compiler.(libraryInterface); ok && lib.buildDylib() {
mctx.PropertyErrorf("vendor", "Vendor-only dylibs are not yet supported, use rust_library_rlib.")
}
}
if mctx.ProductSpecific() { if mctx.ProductSpecific() {
if lib, ok := mod.compiler.(libraryInterface); ok && lib.buildDylib() { if lib, ok := mod.compiler.(libraryInterface); ok && lib.buildDylib() {
mctx.PropertyErrorf("product", "Product-only dylibs are not yet supported, use rust_library_rlib.") mctx.PropertyErrorf("product", "Product-only dylibs are not yet supported, use rust_library_rlib.")

View file

@ -21,7 +21,6 @@ import (
"android/soong/android" "android/soong/android"
"android/soong/cc" "android/soong/cc"
"android/soong/snapshot"
) )
var ( var (
@ -236,10 +235,7 @@ func (library *libraryDecorator) setSource() {
} }
func (library *libraryDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep { func (library *libraryDecorator) autoDep(ctx android.BottomUpMutatorContext) autoDep {
if ctx.Module().(*Module).InVendor() { if library.preferRlib() {
// Vendor modules should statically link libstd.
return rlibAutoDep
} else if library.preferRlib() {
return rlibAutoDep return rlibAutoDep
} else if library.rlib() || library.static() { } else if library.rlib() || library.static() {
return rlibAutoDep return rlibAutoDep
@ -251,10 +247,7 @@ func (library *libraryDecorator) autoDep(ctx android.BottomUpMutatorContext) aut
} }
func (library *libraryDecorator) stdLinkage(ctx *depsContext) RustLinkage { func (library *libraryDecorator) stdLinkage(ctx *depsContext) RustLinkage {
if ctx.RustModule().InVendor() { if library.static() || library.MutatedProperties.VariantIsStaticStd {
// Vendor modules should statically link libstd.
return RlibLinkage
} else if library.static() || library.MutatedProperties.VariantIsStaticStd {
return RlibLinkage return RlibLinkage
} else if library.baseCompiler.preferRlib() { } else if library.baseCompiler.preferRlib() {
return RlibLinkage return RlibLinkage
@ -693,24 +686,6 @@ func LibraryMutator(mctx android.BottomUpMutatorContext) {
v.(*Module).Disable() v.(*Module).Disable()
} }
variation := v.(*Module).ModuleBase.ImageVariation().Variation
if strings.HasPrefix(variation, cc.VendorVariationPrefix) {
// TODO(b/204303985)
// Disable vendor dylibs until they are supported
v.(*Module).Disable()
}
if strings.HasPrefix(variation, cc.VendorVariationPrefix) &&
m.HasVendorVariant() &&
!snapshot.IsVendorProprietaryModule(mctx) &&
strings.TrimPrefix(variation, cc.VendorVariationPrefix) == mctx.DeviceConfig().VndkVersion() {
// cc.MutateImage runs before LibraryMutator, so vendor variations which are meant for rlibs only are
// produced for Dylibs; however, dylibs should not be enabled for boardVndkVersion for
// non-vendor proprietary modules.
v.(*Module).Disable()
}
case "source": case "source":
v.(*Module).compiler.(libraryInterface).setSource() v.(*Module).compiler.(libraryInterface).setSource()
// The source variant does not produce any library. // The source variant does not produce any library.
@ -747,10 +722,9 @@ func LibstdMutator(mctx android.BottomUpMutatorContext) {
dylib := modules[1].(*Module) dylib := modules[1].(*Module)
rlib.compiler.(libraryInterface).setRlibStd() rlib.compiler.(libraryInterface).setRlibStd()
dylib.compiler.(libraryInterface).setDylibStd() dylib.compiler.(libraryInterface).setDylibStd()
if dylib.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation || if dylib.ModuleBase.ImageVariation().Variation == android.VendorRamdiskVariation {
strings.HasPrefix(dylib.ModuleBase.ImageVariation().Variation, cc.VendorVariationPrefix) {
// TODO(b/165791368) // TODO(b/165791368)
// Disable rlibs that link against dylib-std on vendor and vendor ramdisk variations until those dylib // Disable rlibs that link against dylib-std on vendor ramdisk variations until those dylib
// variants are properly supported. // variants are properly supported.
dylib.Disable() dylib.Disable()
} }

View file

@ -91,6 +91,8 @@ type BaseProperties struct {
// Used by vendor snapshot to record dependencies from snapshot modules. // Used by vendor snapshot to record dependencies from snapshot modules.
SnapshotSharedLibs []string `blueprint:"mutated"` SnapshotSharedLibs []string `blueprint:"mutated"`
SnapshotStaticLibs []string `blueprint:"mutated"` SnapshotStaticLibs []string `blueprint:"mutated"`
SnapshotRlibs []string `blueprint:"mutated"`
SnapshotDylibs []string `blueprint:"mutated"`
// Make this module available when building for ramdisk. // Make this module available when building for ramdisk.
// On device without a dedicated recovery partition, the module is only // On device without a dedicated recovery partition, the module is only
@ -258,6 +260,15 @@ func (mod *Module) Dylib() bool {
return false 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 { func (mod *Module) Rlib() bool {
if mod.compiler != nil { if mod.compiler != nil {
if library, ok := mod.compiler.(libraryInterface); ok { if library, ok := mod.compiler.(libraryInterface); ok {
@ -1225,6 +1236,8 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
} }
directDylibDeps = append(directDylibDeps, rustDep) directDylibDeps = append(directDylibDeps, rustDep)
mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName) mod.Properties.AndroidMkDylibs = append(mod.Properties.AndroidMkDylibs, makeLibName)
mod.Properties.SnapshotDylibs = append(mod.Properties.SnapshotDylibs, cc.BaseLibName(depName))
case rlibDepTag: case rlibDepTag:
rlib, ok := rustDep.compiler.(libraryInterface) rlib, ok := rustDep.compiler.(libraryInterface)
@ -1234,6 +1247,8 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
} }
directRlibDeps = append(directRlibDeps, rustDep) directRlibDeps = append(directRlibDeps, rustDep)
mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName) mod.Properties.AndroidMkRlibs = append(mod.Properties.AndroidMkRlibs, makeLibName)
mod.Properties.SnapshotRlibs = append(mod.Properties.SnapshotRlibs, cc.BaseLibName(depName))
case procMacroDepTag: case procMacroDepTag:
directProcMacroDeps = append(directProcMacroDeps, rustDep) directProcMacroDeps = append(directProcMacroDeps, rustDep)
mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName) mod.Properties.AndroidMkProcMacroLibs = append(mod.Properties.AndroidMkProcMacroLibs, makeLibName)
@ -1518,10 +1533,10 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
} }
// dylibs // dylibs
actx.AddVariationDependencies( dylibDepVariations := append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: dylibVariation})
append(commonDepVariations, []blueprint.Variation{ for _, lib := range deps.Dylibs {
{Mutator: "rust_libraries", Variation: dylibVariation}}...), addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag)
dylibDepTag, deps.Dylibs...) }
// rustlibs // rustlibs
if deps.Rustlibs != nil && !mod.compiler.Disabled() { if deps.Rustlibs != nil && !mod.compiler.Disabled() {
@ -1536,8 +1551,11 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
// otherwise select the rlib variant. // otherwise select the rlib variant.
autoDepVariations := append(commonDepVariations, autoDepVariations := append(commonDepVariations,
blueprint.Variation{Mutator: "rust_libraries", Variation: autoDep.variation}) 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 { } else {
// If there's no dylib dependency available, try to add the rlib dependency instead. // If there's no dylib dependency available, try to add the rlib dependency instead.
addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations) addRlibDependency(actx, lib, mod, &snapshotInfo, rlibDepVariations)
@ -1549,16 +1567,14 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
if deps.Stdlibs != nil { if deps.Stdlibs != nil {
if mod.compiler.stdLinkage(ctx) == RlibLinkage { if mod.compiler.stdLinkage(ctx) == RlibLinkage {
for _, lib := range deps.Stdlibs { for _, lib := range deps.Stdlibs {
depTag := rlibDepTag
lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs) lib = cc.GetReplaceModuleName(lib, cc.GetSnapshot(mod, &snapshotInfo, actx).Rlibs)
actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...), actx.AddVariationDependencies(append(commonDepVariations, []blueprint.Variation{{Mutator: "rust_libraries", Variation: "rlib"}}...),
depTag, lib) rlibDepTag, lib)
} }
} else { } else {
actx.AddVariationDependencies( for _, lib := range deps.Stdlibs {
append(commonDepVariations, blueprint.Variation{Mutator: "rust_libraries", Variation: "dylib"}), addDylibDependency(actx, lib, mod, &snapshotInfo, dylibDepVariations, dylibDepTag)
dylibDepTag, deps.Stdlibs...) }
} }
} }
@ -1636,6 +1652,11 @@ func addRlibDependency(actx android.BottomUpMutatorContext, lib string, mod *Mod
actx.AddVariationDependencies(variations, rlibDepTag, lib) 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) { func BeginMutator(ctx android.BottomUpMutatorContext) {
if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() { if mod, ok := ctx.Module().(*Module); ok && mod.Enabled() {
mod.beginMutator(ctx) mod.beginMutator(ctx)

View file

@ -81,8 +81,12 @@ func testRustVndk(t *testing.T, bp string) *android.TestContext {
const ( const (
sharedVendorVariant = "android_vendor.29_arm64_armv8-a_shared" sharedVendorVariant = "android_vendor.29_arm64_armv8-a_shared"
rlibVendorVariant = "android_vendor.29_arm64_armv8-a_rlib_rlib-std" rlibVendorVariant = "android_vendor.29_arm64_armv8-a_rlib_rlib-std"
rlibDylibStdVendorVariant = "android_vendor.29_arm64_armv8-a_rlib_rlib-std"
dylibVendorVariant = "android_vendor.29_arm64_armv8-a_dylib"
sharedRecoveryVariant = "android_recovery_arm64_armv8-a_shared" sharedRecoveryVariant = "android_recovery_arm64_armv8-a_shared"
rlibRecoveryVariant = "android_recovery_arm64_armv8-a_rlib_rlib-std" rlibRecoveryVariant = "android_recovery_arm64_armv8-a_rlib_dylib-std"
rlibRlibStdRecoveryVariant = "android_recovery_arm64_armv8-a_rlib_rlib-std"
dylibRecoveryVariant = "android_recovery_arm64_armv8-a_dylib"
binaryCoreVariant = "android_arm64_armv8-a" binaryCoreVariant = "android_arm64_armv8-a"
binaryVendorVariant = "android_vendor.29_arm64_armv8-a" binaryVendorVariant = "android_vendor.29_arm64_armv8-a"
binaryProductVariant = "android_product.29_arm64_armv8-a" binaryProductVariant = "android_product.29_arm64_armv8-a"

View file

@ -21,10 +21,6 @@ import (
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
) )
const (
snapshotRlibSuffix = "_rlib."
)
type snapshotLibraryDecorator struct { type snapshotLibraryDecorator struct {
cc.BaseSnapshotDecorator cc.BaseSnapshotDecorator
*libraryDecorator *libraryDecorator
@ -44,6 +40,8 @@ func init() {
func registerRustSnapshotModules(ctx android.RegistrationContext) { func registerRustSnapshotModules(ctx android.RegistrationContext) {
cc.VendorSnapshotImageSingleton.RegisterAdditionalModule(ctx, cc.VendorSnapshotImageSingleton.RegisterAdditionalModule(ctx,
"vendor_snapshot_rlib", VendorSnapshotRlibFactory) "vendor_snapshot_rlib", VendorSnapshotRlibFactory)
cc.VendorSnapshotImageSingleton.RegisterAdditionalModule(ctx,
"vendor_snapshot_dylib", VendorSnapshotDylibFactory)
cc.RecoverySnapshotImageSingleton.RegisterAdditionalModule(ctx, cc.RecoverySnapshotImageSingleton.RegisterAdditionalModule(ctx,
"recovery_snapshot_rlib", RecoverySnapshotRlibFactory) "recovery_snapshot_rlib", RecoverySnapshotRlibFactory)
} }
@ -77,12 +75,11 @@ func (library *snapshotLibraryDecorator) compile(ctx ModuleContext, flags Flags,
variant = cc.SnapshotSharedSuffix variant = cc.SnapshotSharedSuffix
} else if library.rlib() { } else if library.rlib() {
variant = cc.SnapshotRlibSuffix variant = cc.SnapshotRlibSuffix
} else if library.dylib() {
variant = cc.SnapshotDylibSuffix
} }
if !library.dylib() {
// TODO(184042776): Remove this check when dylibs are supported in snapshots.
library.SetSnapshotAndroidMkSuffix(ctx, variant) library.SetSnapshotAndroidMkSuffix(ctx, variant)
}
if !library.MatchesWithDevice(ctx.DeviceConfig()) { if !library.MatchesWithDevice(ctx.DeviceConfig()) {
return buildOutput{} return buildOutput{}
@ -107,6 +104,17 @@ func VendorSnapshotRlibFactory() android.Module {
return module.Init() return module.Init()
} }
// vendor_snapshot_dylib is a special prebuilt dylib library which is auto-generated by
// development/vendor_snapshot/update.py. As a part of vendor snapshot, vendor_snapshot_dylib
// overrides the vendor variant of the rust dylib library with the same name, if BOARD_VNDK_VERSION
// is set.
func VendorSnapshotDylibFactory() android.Module {
module, prebuilt := snapshotLibraryFactory(cc.VendorSnapshotImageSingleton, cc.SnapshotDylibSuffix)
prebuilt.libraryDecorator.BuildOnlyDylib()
prebuilt.libraryDecorator.setNoStdlibs()
return module.Init()
}
func RecoverySnapshotRlibFactory() android.Module { func RecoverySnapshotRlibFactory() android.Module {
module, prebuilt := snapshotLibraryFactory(cc.RecoverySnapshotImageSingleton, cc.SnapshotRlibSuffix) module, prebuilt := snapshotLibraryFactory(cc.RecoverySnapshotImageSingleton, cc.SnapshotRlibSuffix)
prebuilt.libraryDecorator.BuildOnlyRlib() prebuilt.libraryDecorator.BuildOnlyRlib()

View file

@ -42,8 +42,7 @@ func (mod *Module) ExcludeFromRecoverySnapshot() bool {
func (mod *Module) IsSnapshotLibrary() bool { func (mod *Module) IsSnapshotLibrary() bool {
if lib, ok := mod.compiler.(libraryInterface); ok { if lib, ok := mod.compiler.(libraryInterface); ok {
// Rust-native dylibs are not snapshot supported yet. Only snapshot the rlib-std variants of rlibs. return lib.shared() || lib.static() || lib.rlib() || lib.dylib()
return lib.shared() || lib.static() || (lib.rlib() && lib.rlibStd())
} }
return false return false
} }
@ -61,6 +60,14 @@ func (mod *Module) SnapshotStaticLibs() []string {
return mod.Properties.SnapshotStaticLibs return mod.Properties.SnapshotStaticLibs
} }
func (mod *Module) SnapshotRlibs() []string {
return mod.Properties.SnapshotRlibs
}
func (mod *Module) SnapshotDylibs() []string {
return mod.Properties.SnapshotDylibs
}
func (mod *Module) Symlinks() []string { func (mod *Module) Symlinks() []string {
// TODO update this to return the list of symlinks when Rust supports defining symlinks // TODO update this to return the list of symlinks when Rust supports defining symlinks
return nil return nil

View file

@ -48,15 +48,13 @@ func TestVendorSnapshotCapture(t *testing.T) {
crate_name: "rustvendor_available", crate_name: "rustvendor_available",
srcs: ["lib.rs"], srcs: ["lib.rs"],
vendor_available: true, vendor_available: true,
include_dirs: ["rust_headers/"],
} }
rust_library_rlib { rust_library {
name: "librustvendor", name: "librustvendor",
crate_name: "rustvendor", crate_name: "rustvendor",
srcs: ["lib.rs"], srcs: ["lib.rs"],
vendor: true, vendor: true,
include_dirs: ["rust_headers/"],
} }
rust_binary { rust_binary {
@ -116,7 +114,7 @@ func TestVendorSnapshotCapture(t *testing.T) {
filepath.Join(staticDir, "libffivendor.a.json")) filepath.Join(staticDir, "libffivendor.a.json"))
// For rlib libraries, all vendor:true and vendor_available modules (including VNDK) are captured. // For rlib libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant) rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib", rlibDir, rlibVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib", rlibDir, rlibVariant)
@ -125,6 +123,25 @@ func TestVendorSnapshotCapture(t *testing.T) {
jsonFiles = append(jsonFiles, jsonFiles = append(jsonFiles,
filepath.Join(rlibDir, "librustvendor.rlib.json")) filepath.Join(rlibDir, "librustvendor.rlib.json"))
// For rlib libraries, all rlib-std variants vendor:true and vendor_available modules (including VNDK) are captured.
rlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib-std.rlib", rlibDir, rlibStdVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.rlib-std.rlib", rlibDir, rlibStdVariant)
jsonFiles = append(jsonFiles,
filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
jsonFiles = append(jsonFiles,
filepath.Join(rlibDir, "librustvendor.rlib.json"))
// For dylib libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.dylib.so", dylibDir, dylibVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor", "librustvendor.dylib.so", dylibDir, dylibVariant)
jsonFiles = append(jsonFiles,
filepath.Join(dylibDir, "librustvendor_available.dylib.so.json"))
jsonFiles = append(jsonFiles,
filepath.Join(dylibDir, "librustvendor.dylib.so.json"))
// For binary executables, all vendor:true and vendor_available modules are captured. // For binary executables, all vendor:true and vendor_available modules are captured.
if archType == "arm64" { if archType == "arm64" {
binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant) binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
@ -209,21 +226,32 @@ func TestVendorSnapshotDirected(t *testing.T) {
archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant) sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant) rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
rlibRlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
// Included modules // Included modules
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib", rlibDir, rlibVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librustvendor_available", "librustvendor_available.dylib.so", dylibDir, dylibVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "libffivendor_available", "libffivendor_available.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib.json"))
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_available.rlib-std.rlib.json"))
includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librustvendor_available.dylib.so.json"))
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_available.so.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_available.so.json"))
// Excluded modules. Modules not included in the directed vendor snapshot // Excluded modules. Modules not included in the directed vendor snapshot
// are still include as fake modules. // are still include as fake modules.
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib", rlibDir, rlibVariant) cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib", rlibDir, rlibVariant)
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librustvendor_exclude", "librustvendor_exclude.dylib.so", dylibDir, dylibVariant)
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "libffivendor_exclude", "libffivendor_exclude.so", sharedDir, sharedVariant) cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "libffivendor_exclude", "libffivendor_exclude.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib.json"))
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librustvendor_exclude.rlib-std.rlib.json"))
includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librustvendor_exclude.dylib.so.json"))
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_exclude.so.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libffivendor_exclude.so.json"))
} }
@ -274,7 +302,7 @@ func TestVendorSnapshotExclude(t *testing.T) {
vendor_available: true, vendor_available: true,
} }
rust_library_rlib { rust_library {
name: "librust_exclude", name: "librust_exclude",
crate_name: "rust_exclude", crate_name: "rust_exclude",
srcs: ["exclude.rs"], srcs: ["exclude.rs"],
@ -308,6 +336,14 @@ func TestVendorSnapshotExclude(t *testing.T) {
cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibVendorVariant) cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibVendorVariant)
cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibVendorVariant) cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibVendorVariant)
cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, rlibDylibStdVendorVariant)
cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, rlibDylibStdVendorVariant)
cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, rlibDylibStdVendorVariant)
cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_include", false, dylibVendorVariant)
cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_exclude", true, dylibVendorVariant)
cc.AssertExcludeFromVendorSnapshotIs(t, ctx, "librust_available_exclude", true, dylibVendorVariant)
// Verify the content of the vendor snapshot. // Verify the content of the vendor snapshot.
snapshotDir := "vendor-snapshot" snapshotDir := "vendor-snapshot"
@ -327,14 +363,22 @@ func TestVendorSnapshotExclude(t *testing.T) {
sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant) sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
rlibVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_dylib-std", archType, archVariant)
rlibRlibStdVariant := fmt.Sprintf("android_vendor.29_%s_%s_rlib_rlib-std", archType, archVariant)
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
dylibVariant := fmt.Sprintf("android_vendor.29_%s_%s_dylib", archType, archVariant)
dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
// Included modules // Included modules
cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib", rlibDir, rlibVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib", rlibDir, rlibVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib.json"))
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librust_include.rlib-std.rlib.json"))
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librust_include", "librust_include.dylib.so", dylibDir, dylibVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librust_include.dylib.so.json"))
// Excluded modules // Excluded modules
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
@ -345,6 +389,12 @@ func TestVendorSnapshotExclude(t *testing.T) {
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_exclude.rlib.json")) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_exclude.rlib.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib", rlibDir, rlibVariant) cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib", rlibDir, rlibVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.json")) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librust_available_exclude.rlib.rlib-std.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_exclude", "librust_exclude.dylib.so", dylibDir, dylibVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(dylibDir, "librust_exclude.dylib.so.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librust_available_exclude", "librust_available_exclude.dylib.so", dylibDir, dylibVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(dylibDir, "librust_available_exclude.dylib.so.json"))
} }
// Verify that each json file for an included module has a rule. // Verify that each json file for an included module has a rule.
@ -525,7 +575,7 @@ func TestVendorSnapshotUse(t *testing.T) {
srcs: ["client.rs"], srcs: ["client.rs"],
} }
rust_library_rlib { rust_library {
name: "libclient_rust", name: "libclient_rust",
crate_name: "client_rust", crate_name: "client_rust",
vendor: true, vendor: true,
@ -572,6 +622,11 @@ func TestVendorSnapshotUse(t *testing.T) {
rlibs: [ rlibs: [
"libstd", "libstd",
"librust_vendor_available", "librust_vendor_available",
"librust_vendor_available.rlib-std"
],
dylibs: [
"libstd",
"librust_vendor_available",
], ],
binaries: [ binaries: [
"bin", "bin",
@ -600,6 +655,10 @@ func TestVendorSnapshotUse(t *testing.T) {
"libstd", "libstd",
"librust_vendor_available", "librust_vendor_available",
], ],
dylibs: [
"libstd",
"librust_vendor_available",
],
binaries: [ binaries: [
"bin32", "bin32",
], ],
@ -679,6 +738,52 @@ func TestVendorSnapshotUse(t *testing.T) {
}, },
} }
vendor_snapshot_rlib {
name: "librust_vendor_available.rlib-std",
version: "30",
target_arch: "arm64",
vendor: true,
arch: {
arm64: {
src: "librust_vendor_available.rlib-std.rlib",
},
arm: {
src: "librust_vendor_available.rlib-std.rlib",
},
},
}
vendor_snapshot_dylib {
name: "libstd",
version: "30",
target_arch: "arm64",
vendor: true,
sysroot: true,
arch: {
arm64: {
src: "libstd.dylib.so",
},
arm: {
src: "libstd.dylib.so",
},
},
}
vendor_snapshot_dylib {
name: "librust_vendor_available",
version: "30",
target_arch: "arm64",
vendor: true,
arch: {
arm64: {
src: "librust_vendor_available.dylib.so",
},
arm: {
src: "librust_vendor_available.dylib.so",
},
},
}
vendor_snapshot_object { vendor_snapshot_object {
name: "crtend_android", name: "crtend_android",
version: "30", version: "30",
@ -921,6 +1026,9 @@ func TestVendorSnapshotUse(t *testing.T) {
"vendor/liblog.so": nil, "vendor/liblog.so": nil,
"vendor/libstd.rlib": nil, "vendor/libstd.rlib": nil,
"vendor/librust_vendor_available.rlib": nil, "vendor/librust_vendor_available.rlib": nil,
"vendor/librust_vendor_available.rlib-std.rlib": nil,
"vendor/libstd.dylib.so": nil,
"vendor/librust_vendor_available.dylib.so": nil,
"vendor/crtbegin_so.o": nil, "vendor/crtbegin_so.o": nil,
"vendor/crtend_so.o": nil, "vendor/crtend_so.o": nil,
"vendor/libclang_rt.builtins-aarch64-android.a": nil, "vendor/libclang_rt.builtins-aarch64-android.a": nil,
@ -931,7 +1039,9 @@ func TestVendorSnapshotUse(t *testing.T) {
} }
sharedVariant := "android_vendor.30_arm64_armv8-a_shared" sharedVariant := "android_vendor.30_arm64_armv8-a_shared"
rlibVariant := "android_vendor.30_arm64_armv8-a_rlib_rlib-std" rlibVariant := "android_vendor.30_arm64_armv8-a_rlib_dylib-std"
rlibRlibStdVariant := "android_vendor.30_arm64_armv8-a_rlib_rlib-std"
dylibVariant := "android_vendor.30_arm64_armv8-a_dylib"
staticVariant := "android_vendor.30_arm64_armv8-a_static" staticVariant := "android_vendor.30_arm64_armv8-a_static"
binaryVariant := "android_vendor.30_arm64_armv8-a" binaryVariant := "android_vendor.30_arm64_armv8-a"
@ -963,14 +1073,9 @@ func TestVendorSnapshotUse(t *testing.T) {
t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g) t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
} }
libclientAndroidMkRlibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkRlibs
if g, w := libclientAndroidMkRlibs, []string{"librust_vendor_available.vendor.rlib-std", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g)
}
libclientAndroidMkDylibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkDylibs libclientAndroidMkDylibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkDylibs
if len(libclientAndroidMkDylibs) > 0 { if g, w := libclientAndroidMkDylibs, []string{"librust_vendor_available.vendor", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
t.Errorf("wanted libclient libclientAndroidMkDylibs [], got %q", libclientAndroidMkDylibs) t.Errorf("wanted libclient libclientAndroidMkDylibs %q, got %q", w, libclientAndroidMkDylibs)
} }
libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
@ -979,22 +1084,39 @@ func TestVendorSnapshotUse(t *testing.T) {
} }
libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs libclientRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibVariant).Module().(*Module).Properties.AndroidMkRlibs
if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor.rlib-std", "libstd.vendor"}; !reflect.DeepEqual(g, w) { if g, w := libclientRustAndroidMkRlibs, []string{"librust_vendor_available.vendor"}; !reflect.DeepEqual(g, w) {
t.Errorf("wanted libclient libclientAndroidMkRlibs %q, got %q", w, g) t.Errorf("wanted rlib libclient libclientAndroidMkRlibs %q, got %q", w, g)
}
libclientRlibStdRustAndroidMkRlibs := ctx.ModuleForTests("libclient_rust", rlibRlibStdVariant).Module().(*Module).Properties.AndroidMkRlibs
if g, w := libclientRlibStdRustAndroidMkRlibs, []string{"librust_vendor_available.vendor.rlib-std", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
t.Errorf("wanted rlib libclient libclientAndroidMkRlibs %q, got %q", w, g)
}
libclientRustDylibAndroidMkDylibs := ctx.ModuleForTests("libclient_rust", dylibVariant).Module().(*Module).Properties.AndroidMkDylibs
if g, w := libclientRustDylibAndroidMkDylibs, []string{"librust_vendor_available.vendor", "libstd.vendor"}; !reflect.DeepEqual(g, w) {
t.Errorf("wanted dylib libclient libclientRustDylibAndroidMkDylibs %q, got %q", w, g)
} }
// rust vendor snapshot must have ".vendor" suffix in AndroidMk // rust vendor snapshot must have ".vendor" suffix in AndroidMk
librustVendorAvailableSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_rlib.30.arm64", rlibVariant).Module() librustVendorAvailableSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_rlib.30.arm64", rlibVariant).Module()
librustVendorSnapshotMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0] librustVendorSnapshotMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0]
expectedRustVendorSnapshotName := "librust_vendor_available.vendor.rlib-std" expectedRustVendorSnapshotName := "librust_vendor_available.vendor"
if librustVendorSnapshotMkName != expectedRustVendorSnapshotName { if librustVendorSnapshotMkName != expectedRustVendorSnapshotName {
t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotMkName, expectedRustVendorSnapshotName) t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotMkName, expectedRustVendorSnapshotName)
} }
librustVendorAvailableDylibSnapshotModule := ctx.ModuleForTests("librust_vendor_available.vendor_dylib.30.arm64", dylibVariant).Module()
librustVendorSnapshotDylibMkName := android.AndroidMkEntriesForTest(t, ctx, librustVendorAvailableDylibSnapshotModule)[0].EntryMap["LOCAL_MODULE"][0]
expectedRustVendorDylibSnapshotName := "librust_vendor_available.vendor"
if librustVendorSnapshotDylibMkName != expectedRustVendorDylibSnapshotName {
t.Errorf("Unexpected rust vendor snapshot name in AndroidMk: %q, expected: %q\n", librustVendorSnapshotDylibMkName, expectedRustVendorDylibSnapshotName)
}
rustVendorBinModule := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Module() rustVendorBinModule := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Module()
rustVendorBinMkRlibName := android.AndroidMkEntriesForTest(t, ctx, rustVendorBinModule)[0].EntryMap["LOCAL_RLIB_LIBRARIES"][0] rustVendorBinMkDylibName := android.AndroidMkEntriesForTest(t, ctx, rustVendorBinModule)[0].EntryMap["LOCAL_DYLIB_LIBRARIES"][0]
if rustVendorBinMkRlibName != expectedRustVendorSnapshotName { if rustVendorBinMkDylibName != expectedRustVendorSnapshotName {
t.Errorf("Unexpected rust rlib name in AndroidMk: %q, expected: %q\n", rustVendorBinMkRlibName, expectedRustVendorSnapshotName) t.Errorf("Unexpected rust rlib name in AndroidMk: %q, expected: %q\n", rustVendorBinMkDylibName, expectedRustVendorSnapshotName)
} }
binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustLink").Args["linkFlags"] binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("rustLink").Args["linkFlags"]
@ -1051,18 +1173,18 @@ func TestRecoverySnapshotCapture(t *testing.T) {
crate_name: "recovery_available", crate_name: "recovery_available",
} }
rust_library_rlib { rust_library {
name: "librecovery_rlib", name: "librecovery_rustlib",
recovery: true, recovery: true,
srcs: ["foo.rs"], srcs: ["foo.rs"],
crate_name: "recovery_rlib", crate_name: "recovery_rustlib",
} }
rust_library_rlib { rust_library {
name: "librecovery_available_rlib", name: "librecovery_available_rustlib",
recovery_available: true, recovery_available: true,
srcs: ["foo.rs"], srcs: ["foo.rs"],
crate_name: "recovery_available_rlib", crate_name: "recovery_available_rustlib",
} }
rust_binary { rust_binary {
@ -1113,13 +1235,29 @@ func TestRecoverySnapshotCapture(t *testing.T) {
filepath.Join(staticDir, "librecovery_available.a.json")) filepath.Join(staticDir, "librecovery_available.a.json"))
// For rlib libraries, all recovery:true and recovery_available modules are captured. // For rlib libraries, all recovery:true and recovery_available modules are captured.
rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant) rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rlib", "librecovery_available_rlib.rlib", rlibDir, rlibVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib", rlibDir, rlibVariant)
jsonFiles = append(jsonFiles, jsonFiles = append(jsonFiles,
filepath.Join(rlibDir, "librecovery_rlib.rlib.json"), filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"),
filepath.Join(rlibDir, "librecovery_available_rlib.rlib.json")) filepath.Join(rlibDir, "librecovery_available_rustlib.rlib.json"))
rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
jsonFiles = append(jsonFiles,
filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"),
filepath.Join(rlibDir, "librecovery_available_rustlib.rlib-std.rlib.json"))
// For dylib libraries, all recovery:true and recovery_available modules are captured.
dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.dylib.so", dylibDir, dylibVariant)
jsonFiles = append(jsonFiles,
filepath.Join(dylibDir, "librecovery_rustlib.dylib.so.json"),
filepath.Join(dylibDir, "librecovery_available_rustlib.dylib.so.json"))
// For binary executables, all recovery:true and recovery_available modules are captured. // For binary executables, all recovery:true and recovery_available modules are captured.
if archType == "arm64" { if archType == "arm64" {
@ -1169,25 +1307,25 @@ func TestRecoverySnapshotExclude(t *testing.T) {
exclude_from_recovery_snapshot: true, exclude_from_recovery_snapshot: true,
crate_name: "available_exclude", crate_name: "available_exclude",
} }
rust_library_rlib { rust_library {
name: "libinclude_rlib", name: "libinclude_rustlib",
srcs: ["src/include.rs"], srcs: ["src/include.rs"],
recovery_available: true, recovery_available: true,
crate_name: "include_rlib", crate_name: "include_rustlib",
} }
rust_library_rlib { rust_library {
name: "libexclude_rlib", name: "libexclude_rustlib",
srcs: ["src/exclude.rs"], srcs: ["src/exclude.rs"],
recovery: true, recovery: true,
exclude_from_recovery_snapshot: true, exclude_from_recovery_snapshot: true,
crate_name: "exclude_rlib", crate_name: "exclude_rustlib",
} }
rust_library_rlib { rust_library {
name: "libavailable_exclude_rlib", name: "libavailable_exclude_rustlib",
srcs: ["src/exclude.rs"], srcs: ["src/exclude.rs"],
recovery_available: true, recovery_available: true,
exclude_from_recovery_snapshot: true, exclude_from_recovery_snapshot: true,
crate_name: "available_exclude_rlib", crate_name: "available_exclude_rustlib",
} }
` `
@ -1198,11 +1336,11 @@ func TestRecoverySnapshotExclude(t *testing.T) {
recovery: true, recovery: true,
crate_name: "recovery", crate_name: "recovery",
} }
rust_library_rlib { rust_library {
name: "librecovery_rlib", name: "librecovery_rustlib",
srcs: ["recovery.rs"], srcs: ["recovery.rs"],
recovery: true, recovery: true,
crate_name: "recovery_rlib", crate_name: "recovery_rustlib",
} }
` `
@ -1220,14 +1358,25 @@ func TestRecoverySnapshotExclude(t *testing.T) {
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, sharedRecoveryVariant) cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, sharedRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, sharedRecoveryVariant) cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, sharedRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, sharedRecoveryVariant) cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, sharedRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rlib", false, rlibRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rlib", true, rlibRecoveryVariant) cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, rlibRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rlib", true, rlibRecoveryVariant) cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, rlibRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, rlibRlibStdRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, rlibRlibStdRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, rlibRlibStdRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, rlibRlibStdRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude_rustlib", false, dylibRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude_rustlib", true, dylibRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude_rustlib", true, dylibRecoveryVariant)
// A recovery module is excluded, but by its path not the exclude_from_recovery_snapshot property // A recovery module is excluded, but by its path not the exclude_from_recovery_snapshot property
// ('device/' and 'vendor/' are default excluded). See snapshot/recovery_snapshot.go for more detail. // ('device/' and 'vendor/' are default excluded). See snapshot/recovery_snapshot.go for more detail.
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, sharedRecoveryVariant) cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, sharedRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rlib", false, rlibRecoveryVariant) cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, rlibRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, rlibRlibStdRecoveryVariant)
cc.AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery_rustlib", false, dylibRecoveryVariant)
// Verify the content of the recovery snapshot. // Verify the content of the recovery snapshot.
@ -1246,15 +1395,21 @@ func TestRecoverySnapshotExclude(t *testing.T) {
archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant) rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
// Included modules // Included modules
cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rlib", "libinclude_rlib.rlib", rlibDir, rlibVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rustlib", "libinclude_rustlib.rlib", rlibDir, rlibVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rlib.rlib.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rustlib.rlib.json"))
cc.CheckSnapshot(t, ctx, snapshotSingleton, "libinclude_rustlib", "libinclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "libinclude_rustlib.rlib-std.rlib.json"))
// Excluded modules // Excluded modules
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant) cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
@ -1263,12 +1418,27 @@ func TestRecoverySnapshotExclude(t *testing.T) {
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json")) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant) cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json")) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rlib", "libexclude_rlib.rlib", rlibDir, rlibVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rlib.rlib.json")) cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.rlib", rlibDir, rlibVariant)
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.rlib.json"))
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rlib.rlib.json")) cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rlib", "libavailable_exclude_rlib.rlib", rlibDir, rlibVariant) excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"))
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rlib.rlib.json")) cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.rlib", rlibDir, rlibVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.rlib.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.rlib-std.rlib.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.rlib-std.rlib.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude_rustlib", "libexclude_rustlib.dylib.so", dylibDir, dylibVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libexclude_rustlib.dylib.so.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.dylib.so.json"))
cc.CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude_rustlib", "libavailable_exclude_rustlib.dylib.so", dylibDir, dylibVariant)
excludeJsonFiles = append(excludeJsonFiles, filepath.Join(rlibDir, "libavailable_exclude_rustlib.dylib.so.json"))
} }
// Verify that each json file for an included module has a rule. // Verify that each json file for an included module has a rule.
@ -1302,15 +1472,15 @@ func TestRecoverySnapshotDirected(t *testing.T) {
srcs: ["foo.rs"], srcs: ["foo.rs"],
} }
rust_library_rlib { rust_library {
name: "librecovery_rlib", name: "librecovery_rustlib",
recovery: true, recovery: true,
crate_name: "recovery", crate_name: "recovery",
srcs: ["foo.rs"], srcs: ["foo.rs"],
} }
rust_library_rlib { rust_library {
name: "librecovery_available_rlib", name: "librecovery_available_rustlib",
recovery_available: true, recovery_available: true,
crate_name: "recovery_available", crate_name: "recovery_available",
srcs: ["foo.rs"], srcs: ["foo.rs"],
@ -1335,7 +1505,7 @@ func TestRecoverySnapshotDirected(t *testing.T) {
ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "current", "29", "current") ctx := testRustRecoveryFsVersions(t, bp, rustMockedFiles, "current", "29", "current")
ctx.Config().TestProductVariables.RecoverySnapshotModules = make(map[string]bool) ctx.Config().TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery"] = true ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery"] = true
ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery_rlib"] = true ctx.Config().TestProductVariables.RecoverySnapshotModules["librecovery_rustlib"] = true
ctx.Config().TestProductVariables.DirectedRecoverySnapshot = true ctx.Config().TestProductVariables.DirectedRecoverySnapshot = true
// Check recovery snapshot output. // Check recovery snapshot output.
@ -1353,15 +1523,22 @@ func TestRecoverySnapshotDirected(t *testing.T) {
archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant) archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant) sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant) rlibVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_dylib-std", archType, archVariant)
rlibRlibStdVariant := fmt.Sprintf("android_recovery_%s_%s_rlib_rlib-std", archType, archVariant)
dylibVariant := fmt.Sprintf("android_recovery_%s_%s_dylib", archType, archVariant)
sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared") sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib") rlibDir := filepath.Join(snapshotVariantPath, archDir, "rlib")
dylibDir := filepath.Join(snapshotVariantPath, archDir, "dylib")
// Included modules // Included modules
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rlib", "librecovery_rlib.rlib", rlibDir, rlibVariant) cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib", rlibDir, rlibVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rlib.rlib.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib.json"))
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_rustlib.rlib-std.rlib.json"))
cc.CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_rustlib", "librecovery_rustlib.dylib.so", dylibDir, dylibVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librecovery_rustlib.dylib.so.json"))
// TODO: When Rust supports the "prefer" property for prebuilts, perform this check. // TODO: When Rust supports the "prefer" property for prebuilts, perform this check.
/* /*
@ -1374,8 +1551,12 @@ func TestRecoverySnapshotDirected(t *testing.T) {
// are still included as fake modules. // are still included as fake modules.
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant) cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rlib", "librecovery_available_rlib.rlib", rlibDir, rlibVariant) cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib", rlibDir, rlibVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rlib.rlib.json")) includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rustlib.rlib.json"))
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.rlib-std.rlib", rlibDir, rlibRlibStdVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(rlibDir, "librecovery_available_rustlib.rlib-std.rlib.json"))
cc.CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available_rustlib", "librecovery_available_rustlib.dylib.so", dylibDir, dylibVariant)
includeJsonFiles = append(includeJsonFiles, filepath.Join(dylibDir, "librecovery_available_rustlib.dylib.so.json"))
} }
// Verify that each json file for an included module has a rule. // Verify that each json file for an included module has a rule.