From 22cef966e1552575f891ea77bf0151555a207056 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Mon, 13 Jan 2020 16:31:13 -0800 Subject: [PATCH 1/2] rust: Include Soong module name as metadata If we want to build a component which uses two versions of a crate in the dependency graph (for example, libc in std and libc from external/crates), Rust requires at least one of them have a metadata field to differentiate them. Since Soong module names should be distinct for a given target, they should serve as metadata. Bug: 147397356 Test: Build a rust library with "rlibs: ["liblibc"]" in the blueprint Change-Id: I5d85ea8b3197972c09de301c9523efaff08adf81 --- rust/library.go | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/library.go b/rust/library.go index 43819cef7..2844e70d9 100644 --- a/rust/library.go +++ b/rust/library.go @@ -323,6 +323,7 @@ func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { return deps } func (library *libraryDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags { + flags.RustFlags = append(flags.RustFlags, "-C metadata="+ctx.baseModuleName()) flags = library.baseCompiler.compilerFlags(ctx, flags) if library.shared() || library.static() { library.includeDirs = append(library.includeDirs, android.PathsForModuleSrc(ctx, library.Properties.Include_dirs)...) From 46c46ccafdbe2de0b4ae7e29651b5c11d5697752 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Mon, 13 Jan 2020 16:34:34 -0800 Subject: [PATCH 2/2] rust: Do not pass -C prefer-dynamic for cdylib cdylib targets cannot currently dynamically link to Rust crates, so this flag was not actually doing anything, and in conjunction with -C lto which we *do* want on for this target, causes a hard error on rustc-1.40.0. Bug: 147438124 Test: Build a rust_library module, this implicitly tries to build cdylib Change-Id: I828b3e6bae7c58f4081db3e73009b443a382a296 --- rust/library.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/library.go b/rust/library.go index 2844e70d9..0cf2dd045 100644 --- a/rust/library.go +++ b/rust/library.go @@ -338,7 +338,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa flags.RustFlags = append(flags.RustFlags, deps.depFlags...) - if library.dylib() || library.shared() { + if library.dylib() { // We need prefer-dynamic for now to avoid linking in the static stdlib. See: // https://github.com/rust-lang/rust/issues/19680 // https://github.com/rust-lang/rust/issues/34909