[rust] Add android_dylib cfg flag

Adds an android_dylib cfg when building a Rust crate as a dylib. This
cfg lets us make the hack to add a dependency on std for the
panic_handler and eh_personality conditional on actually building a
dylib.

Test: m nothing
Bug: 193087363
Change-Id: Idad5b98245264f916afa327812a435b368f99321
This commit is contained in:
Stephen Crane
2021-07-07 19:05:02 -07:00
parent af60f411f8
commit 0dbfc565f0
2 changed files with 22 additions and 0 deletions

View File

@@ -431,6 +431,12 @@ func (library *libraryDecorator) sharedLibFilename(ctx ModuleContext) string {
func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.ModuleName())
if library.dylib() {
// We need to add a dependency on std in order to link crates as dylibs.
// The hack to add this dependency is guarded by the following cfg so
// that we don't force a dependency when it isn't needed.
library.baseCompiler.Properties.Cfgs = append(library.baseCompiler.Properties.Cfgs, "android_dylib")
}
flags = library.baseCompiler.compilerFlags(ctx, flags)
if library.shared() || library.static() {
library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...)