Merge "rust: Add rust_ffi_static vendor ramdisk Support"

This commit is contained in:
Ivan Lozano
2021-02-09 13:49:28 +00:00
committed by Gerrit Code Review
8 changed files with 99 additions and 16 deletions

View File

@@ -24,7 +24,7 @@ import (
var _ android.ImageInterface = (*Module)(nil)
func (mod *Module) VendorRamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
return false
return mod.Properties.VendorRamdiskVariantNeeded
}
func (mod *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
@@ -52,6 +52,10 @@ func (mod *Module) InRecovery() bool {
return false
}
func (mod *Module) InVendorRamdisk() bool {
return mod.ModuleBase.InVendorRamdisk() || mod.ModuleBase.InstallInVendorRamdisk()
}
func (mod *Module) OnlyInRamdisk() bool {
// TODO(b/165791368)
return false
@@ -86,7 +90,9 @@ func (c *Module) InProduct() bool {
func (mod *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
m := module.(*Module)
if strings.HasPrefix(variant, cc.VendorVariationPrefix) {
if variant == android.VendorRamdiskVariation {
m.MakeAsPlatform()
} else if strings.HasPrefix(variant, cc.VendorVariationPrefix) {
m.Properties.ImageVariationPrefix = cc.VendorVariationPrefix
m.Properties.VndkVersion = strings.TrimPrefix(variant, cc.VendorVariationPrefix)
@@ -117,6 +123,8 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
}
coreVariantNeeded := true
vendorRamdiskVariantNeeded := false
var vendorVariants []string
if mod.HasVendorVariant() {
@@ -138,15 +146,23 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
// We can't check shared() here because image mutator is called before the library mutator, so we need to
// check buildShared()
if lib.buildShared() {
mctx.PropertyErrorf(prop, "can only be set for rust_ffi_static modules.")
mctx.PropertyErrorf(prop, "cannot be set for rust_ffi or rust_ffi_shared modules.")
} else {
vendorVariants = append(vendorVariants, platformVndkVersion)
}
}
}
if Bool(mod.Properties.Vendor_ramdisk_available) {
if lib, ok := mod.compiler.(libraryInterface); !ok || (ok && lib.buildShared()) {
mctx.PropertyErrorf("vendor_ramdisk_available", "cannot be set for rust_ffi or rust_ffi_shared modules.")
} else {
vendorRamdiskVariantNeeded = true
}
}
if vendorSpecific {
if lib, ok := mod.compiler.(libraryInterface); !ok || (ok && !lib.static()) {
if lib, ok := mod.compiler.(libraryInterface); !ok || (ok && (lib.buildShared() || lib.buildDylib() || lib.buildRlib())) {
mctx.ModuleErrorf("Rust vendor specific modules are currently only supported for rust_ffi_static modules.")
} else {
coreVariantNeeded = false
@@ -155,6 +171,8 @@ func (mod *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
}
mod.Properties.CoreVariantNeeded = coreVariantNeeded
mod.Properties.VendorRamdiskVariantNeeded = vendorRamdiskVariantNeeded
for _, variant := range android.FirstUniqueStrings(vendorVariants) {
mod.Properties.ExtraVariants = append(mod.Properties.ExtraVariants, cc.VendorVariationPrefix+variant)
}

View File

@@ -21,7 +21,7 @@ import (
"android/soong/cc"
)
// Test that cc_binaries can link against rust_ffi_static libraries.
// Test that cc modules can link against vendor_available rust_ffi_static libraries.
func TestVendorLinkage(t *testing.T) {
ctx := testRust(t, `
cc_binary {
@@ -44,9 +44,33 @@ func TestVendorLinkage(t *testing.T) {
}
}
// Test that cc modules can link against vendor_ramdisk_available rust_ffi_static libraries.
func TestVendorRamdiskLinkage(t *testing.T) {
ctx := testRust(t, `
cc_library_static {
name: "libcc_vendor_ramdisk",
static_libs: ["libfoo_vendor_ramdisk"],
system_shared_libs: [],
vendor_ramdisk_available: true,
}
rust_ffi_static {
name: "libfoo_vendor_ramdisk",
crate_name: "foo",
srcs: ["foo.rs"],
vendor_ramdisk_available: true,
}
`)
vendorRamdiskLibrary := ctx.ModuleForTests("libcc_vendor_ramdisk", "android_vendor_ramdisk_arm64_armv8-a_static").Module().(*cc.Module)
if !android.InList("libfoo_vendor_ramdisk.vendor_ramdisk", vendorRamdiskLibrary.Properties.AndroidMkStaticLibs) {
t.Errorf("libcc_vendor_ramdisk should have a dependency on libfoo_vendor_ramdisk")
}
}
// Test that shared libraries cannot be made vendor available until proper support is added.
func TestForbiddenVendorLinkage(t *testing.T) {
testRustError(t, "can only be set for rust_ffi_static modules", `
testRustError(t, "cannot be set for rust_ffi or rust_ffi_shared modules.", `
rust_ffi_shared {
name: "libfoo_vendor",
crate_name: "foo",
@@ -54,6 +78,14 @@ func TestForbiddenVendorLinkage(t *testing.T) {
vendor_available: true,
}
`)
testRustError(t, "cannot be set for rust_ffi or rust_ffi_shared modules.", `
rust_ffi_shared {
name: "libfoo_vendor",
crate_name: "foo",
srcs: ["foo.rs"],
vendor_ramdisk_available: true,
}
`)
testRustError(t, "Rust vendor specific modules are currently only supported for rust_ffi_static modules.", `
rust_ffi {
name: "libfoo_vendor",
@@ -70,4 +102,13 @@ func TestForbiddenVendorLinkage(t *testing.T) {
vendor: true,
}
`)
testRustError(t, "Rust vendor specific modules are currently only supported for rust_ffi_static modules.", `
rust_binary {
name: "foo_vendor",
crate_name: "foo",
srcs: ["foo.rs"],
vendor: true,
}
`)
}

View File

@@ -74,8 +74,16 @@ type BaseProperties struct {
SubName string `blueprint:"mutated"`
// Set by imageMutator
CoreVariantNeeded bool `blueprint:"mutated"`
ExtraVariants []string `blueprint:"mutated"`
CoreVariantNeeded bool `blueprint:"mutated"`
VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
ExtraVariants []string `blueprint:"mutated"`
// Make this module available when building for vendor ramdisk.
// On device without a dedicated recovery partition, the module is only
// available after switching root into
// /first_stage_ramdisk. To expose the module before switching root, install
// the recovery variant instead (TODO(b/165791368) recovery not yet supported)
Vendor_ramdisk_available *bool
// Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
Min_sdk_version *string
@@ -658,7 +666,9 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
// Differentiate static libraries that are vendor available
if mod.UseVndk() {
mod.Properties.SubName += ".vendor"
mod.Properties.SubName += cc.VendorSuffix
} else if mod.InVendorRamdisk() && !mod.OnlyInVendorRamdisk() {
mod.Properties.SubName += cc.VendorRamdiskSuffix
}
if !toolchain.Supported() {

View File

@@ -101,6 +101,7 @@ func GatherRequiredDepsForTest() string {
no_stdlibs: true,
host_supported: true,
vendor_available: true,
vendor_ramdisk_available: true,
native_coverage: false,
sysroot: true,
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],
@@ -113,6 +114,7 @@ func GatherRequiredDepsForTest() string {
no_stdlibs: true,
host_supported: true,
vendor_available: true,
vendor_ramdisk_available: true,
native_coverage: false,
sysroot: true,
apex_available: ["//apex_available:platform", "//apex_available:anyapex"],