diff options
author | 2020-12-08 14:43:00 -0500 | |
---|---|---|
committer | 2020-12-09 09:55:12 -0500 | |
commit | ea08613dd35bf8ae9f41e61e6c80a8fe255ce155 (patch) | |
tree | 5abd2eea941cf451a44a9926aa4d7f92848d9201 /rust/compiler.go | |
parent | 110d13bef3bd302a22facf16677a9ee893a0486c (diff) |
Move prefer_rlib from binary to base compiler.
Moves the prefer_rlib property out from being exclusively a binary
property to one thats part of the base compiler properties. This
provides a little more control over the libstd linkage in our libraries.
Specifically, this enables a usecase where rust_ffi_shared needs to link
against libstd statically rather than dynamically.
Bug: 175121262
Test: New Soong tests pass.
Change-Id: If68014c684a75ba70e9d7dacbb01c7d360dc25a1
Diffstat (limited to 'rust/compiler.go')
-rw-r--r-- | rust/compiler.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/rust/compiler.go b/rust/compiler.go index 8d2f09c2b..4312452d2 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -122,6 +122,17 @@ type BaseCompilerProperties struct { // whether to suppress inclusion of standard crates - defaults to false No_stdlibs *bool + + // Change the rustlibs linkage to select rlib linkage by default for device targets. + // Also link libstd as an rlib as well on device targets. + // Note: This is the default behavior for host targets. + // + // This is primarily meant for rust_binary and rust_ffi modules where the default + // linkage of libstd might need to be overridden in some use cases. This should + // generally be avoided with other module types since it may cause collisions at + // linkage if all dependencies of the root binary module do not link against libstd\ + // the same way. + Prefer_rlib *bool `android:"arch_variant"` } type baseCompiler struct { @@ -154,9 +165,15 @@ func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath { panic("baseCompiler does not implement coverageOutputZipPath()") } +func (compiler *baseCompiler) preferRlib() bool { + return Bool(compiler.Properties.Prefer_rlib) +} + func (compiler *baseCompiler) stdLinkage(ctx *depsContext) RustLinkage { // For devices, we always link stdlibs in as dylibs by default. - if ctx.Device() { + if compiler.preferRlib() { + return RlibLinkage + } else if ctx.Device() { return DylibLinkage } else { return RlibLinkage |