Merge "[Rust] cdylibs can now link against dylibs."

This commit is contained in:
Treehugger Robot
2020-06-19 20:25:47 +00:00
committed by Gerrit Code Review
2 changed files with 17 additions and 7 deletions

View File

@@ -305,8 +305,8 @@ func (library *libraryDecorator) compilerProps() []interface{} {
func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
// TODO(b/144861059) Remove if C libraries support dylib linkage in the future.
if !ctx.Host() && (library.static() || library.shared()) {
// TODO(b/155498724) Remove if C static libraries no longer require libstd as an rlib dependency.
if !ctx.Host() && library.static() {
library.setNoStdlibs()
for _, stdlib := range config.Stdlibs {
deps.Rlibs = append(deps.Rlibs, stdlib+".static")

View File

@@ -17,6 +17,8 @@ package rust
import (
"strings"
"testing"
"android/soong/android"
)
// Test that variants are being generated correctly, and that crate-types are correct.
@@ -115,16 +117,24 @@ func TestValidateLibraryStem(t *testing.T) {
}
func TestSharedLibraryFlags(t *testing.T) {
func TestSharedLibrary(t *testing.T) {
ctx := testRust(t, `
rust_library_host {
rust_library {
name: "libfoo",
srcs: ["foo.rs"],
crate_name: "foo",
}`)
libfooShared := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_shared").Output("libfoo.so")
if !strings.Contains(libfooShared.Args["linkFlags"], "-Wl,-soname=libfoo.so") {
t.Errorf("missing expected -Wl,-soname linker flag for libfoo shared lib, linkFlags: %#v", libfooShared.Args["linkFlags"])
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared")
libfooOutput := libfoo.Output("libfoo.so")
if !strings.Contains(libfooOutput.Args["linkFlags"], "-Wl,-soname=libfoo.so") {
t.Errorf("missing expected -Wl,-soname linker flag for libfoo shared lib, linkFlags: %#v",
libfooOutput.Args["linkFlags"])
}
if !android.InList("libstd", libfoo.Module().(*Module).Properties.AndroidMkDylibs) {
t.Errorf("Non-static libstd dylib expected to be a dependency of Rust shared libraries. Dylib deps are: %#v",
libfoo.Module().(*Module).Properties.AndroidMkDylibs)
}
}