Merge "[rust] Add android_dylib cfg flag"

This commit is contained in:
Matthew Maurer
2021-07-19 19:43:56 +00:00
committed by Gerrit Code Review
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)...)

View File

@@ -85,6 +85,22 @@ func TestDylibPreferDynamic(t *testing.T) {
}
}
// Check that we are passing the android_dylib config flag
func TestAndroidDylib(t *testing.T) {
ctx := testRust(t, `
rust_library_host_dylib {
name: "libfoo",
srcs: ["foo.rs"],
crate_name: "foo",
}`)
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.dylib.so")
if !strings.Contains(libfooDylib.Args["rustcFlags"], "--cfg 'android_dylib'") {
t.Errorf("missing android_dylib cfg flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"])
}
}
func TestValidateLibraryStem(t *testing.T) {
testRustError(t, "crate_name must be defined.", `
rust_library_host {