From 6a88443089849454d45135f18d32183afd122b93 Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Wed, 2 Dec 2020 09:15:16 -0500 Subject: Rust: Vendor support for Rust static libraries. We don't have Rust VNDK support yet, but static linkage can be supported in the interim. This adds support for making rust_ffi_static libraries available to CC vendor modules. Since rust_ffi_static modules will link against rlibs, we allow rlib linkage into vendor as well, but only for the variants which use the rlib libstd. Bug: 172525289 Test: New Soong tests pass Test: Example vendor cc_binary links against rust_ffi_static module. Change-Id: Idf3aeb51e32293866f1ad965e329aa6b9e0bf2ef --- rust/rust.go | 85 +++++++++++++++++++----------------------------------------- 1 file changed, 27 insertions(+), 58 deletions(-) (limited to 'rust/rust.go') diff --git a/rust/rust.go b/rust/rust.go index 4094094c3..3bb48619b 100644 --- a/rust/rust.go +++ b/rust/rust.go @@ -65,7 +65,13 @@ type BaseProperties struct { AndroidMkSharedLibs []string AndroidMkStaticLibs []string - SubName string `blueprint:"mutated"` + ImageVariationPrefix string `blueprint:"mutated"` + VndkVersion string `blueprint:"mutated"` + SubName string `blueprint:"mutated"` + + // Set by imageMutator + CoreVariantNeeded bool `blueprint:"mutated"` + ExtraVariants []string `blueprint:"mutated"` PreventInstall bool HideFromMake bool @@ -76,11 +82,15 @@ type Module struct { android.DefaultableModuleBase android.ApexModuleBase + VendorProperties cc.VendorProperties + Properties BaseProperties hod android.HostOrDeviceSupported multilib android.Multilib + makeLinkType string + compiler compiler coverage *coverage clippy *clippy @@ -109,33 +119,6 @@ func (mod *Module) OutputFiles(tag string) (android.Paths, error) { } } -var _ android.ImageInterface = (*Module)(nil) - -func (mod *Module) ImageMutatorBegin(ctx android.BaseModuleContext) {} - -func (mod *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool { - return true -} - -func (mod *Module) RamdiskVariantNeeded(android.BaseModuleContext) bool { - return mod.InRamdisk() -} - -func (mod *Module) VendorRamdiskVariantNeeded(android.BaseModuleContext) bool { - return mod.InVendorRamdisk() -} - -func (mod *Module) RecoveryVariantNeeded(android.BaseModuleContext) bool { - return mod.InRecovery() -} - -func (mod *Module) ExtraImageVariations(android.BaseModuleContext) []string { - return nil -} - -func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) { -} - func (mod *Module) SelectedStl() string { return "" } @@ -176,24 +159,18 @@ func (mod *Module) Toc() android.OptionalPath { panic(fmt.Errorf("Toc() called on non-library module: %q", mod.BaseModuleName())) } -func (mod *Module) OnlyInRamdisk() bool { - return false -} - -func (mod *Module) OnlyInVendorRamdisk() bool { - return false -} - -func (mod *Module) OnlyInRecovery() bool { - return false -} - func (mod *Module) UseSdk() bool { return false } +// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64. +// "product" and "vendor" variant modules return true for this function. +// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true", +// "soc_specific: true" and more vendor installed modules are included here. +// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or +// "product_specific: true" modules are included here. func (mod *Module) UseVndk() bool { - return false + return mod.Properties.VndkVersion != "" } func (mod *Module) MustUseVendorVariant() bool { @@ -201,10 +178,7 @@ func (mod *Module) MustUseVendorVariant() bool { } func (mod *Module) IsVndk() bool { - return false -} - -func (mod *Module) HasVendorVariant() bool { + // TODO(b/165791368) return false } @@ -216,10 +190,6 @@ func (c *Module) IsVndkPrivate(config android.Config) bool { return false } -func (mod *Module) InProduct() bool { - return false -} - func (mod *Module) SdkVersion() string { return "" } @@ -388,6 +358,7 @@ func DefaultsFactory(props ...interface{}) android.Module { module.AddProperties(props...) module.AddProperties( &BaseProperties{}, + &cc.VendorProperties{}, &BindgenProperties{}, &BaseCompilerProperties{}, &BinaryCompilerProperties{}, @@ -484,11 +455,6 @@ func (mod *Module) OutputFile() android.OptionalPath { return mod.outputFile } -func (mod *Module) InRecovery() bool { - // For now, Rust has no notion of the recovery image - return false -} - func (mod *Module) CoverageFiles() android.Paths { if mod.compiler != nil { if !mod.compiler.nativeCoverage() { @@ -508,6 +474,7 @@ var _ cc.LinkableInterface = (*Module)(nil) func (mod *Module) Init() android.Module { mod.AddProperties(&mod.Properties) + mod.AddProperties(&mod.VendorProperties) if mod.compiler != nil { mod.AddProperties(mod.compiler.compilerProps()...) @@ -627,6 +594,12 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { } toolchain := mod.toolchain(ctx) + mod.makeLinkType = cc.GetMakeLinkType(actx, mod) + + // Differentiate static libraries that are vendor available + if mod.UseVndk() { + mod.Properties.SubName += ".vendor" + } if !toolchain.Supported() { // This toolchain's unsupported, there's nothing to do for this mod. @@ -968,10 +941,6 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) { deps := mod.deps(ctx) var commonDepVariations []blueprint.Variation - if !mod.Host() { - commonDepVariations = append(commonDepVariations, - blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}) - } stdLinkage := "dylib-std" if mod.compiler.stdLinkage(ctx) == RlibLinkage { -- cgit v1.2.3-59-g8ed1b