diff options
author | Ivan Lozano <ivanlozano@google.com> | 2019-10-18 14:49:46 -0700 |
---|---|---|
committer | Ivan Lozano <ivanlozano@google.com> | 2019-10-28 22:09:01 -0700 |
commit | 52767be335c200dfbf2af3da802e24a1cc91f1bf (patch) | |
tree | e9501012123d5a37570c03646bff99a79d3d385e /rust/library_test.go | |
parent | 183a3218e257b6d1dcd6636f136ede87411b13f4 (diff) |
Add support for Rust C libraries.
Adds the ability for rust modules to be compiled as C libraries, and
allows cc modules to depend on these rust-generated modules. This also
means that soong-rust should not have any dependencies on soong-cc aside
from what's required for testing.
There's a couple small fixes included as well:
- A bug in libNameFromFilePath that caused issues when library's had
"lib" in their name.
- VariantName is removed from rust library MutatedProperties since this
was unused.
Bug: 140726209
Test: Soong tests pass.
Test: Example cc_binary can include a rust shared library as a dep.
Test: m crosvm.experimental
Change-Id: Ia7deed1345d2423001089014cc65ce7934123da4
Diffstat (limited to 'rust/library_test.go')
-rw-r--r-- | rust/library_test.go | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/rust/library_test.go b/rust/library_test.go index bf8643efb..66bcd20fb 100644 --- a/rust/library_test.go +++ b/rust/library_test.go @@ -29,19 +29,37 @@ func TestLibraryVariants(t *testing.T) { crate_name: "foo", }`) - // Test both variants are being built. + // Test all variants are being built. libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib").Output("libfoo.rlib") - libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.so") + libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.dylib.so") + libfooStatic := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_static").Output("libfoo.a") + libfooShared := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_shared").Output("libfoo.so") + + rlibCrateType := "rlib" + dylibCrateType := "dylib" + sharedCrateType := "cdylib" + staticCrateType := "static" // Test crate type for rlib is correct. - if !strings.Contains(libfooRlib.Args["rustcFlags"], "crate-type=rlib") { - t.Errorf("missing crate-type for libfoo rlib, rustcFlags: %#v", libfooRlib.Args["rustcFlags"]) + if !strings.Contains(libfooRlib.Args["rustcFlags"], "crate-type="+rlibCrateType) { + t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", rlibCrateType, libfooRlib.Args["rustcFlags"]) } // Test crate type for dylib is correct. - if !strings.Contains(libfooDylib.Args["rustcFlags"], "crate-type=dylib") { - t.Errorf("missing crate-type for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"]) + if !strings.Contains(libfooDylib.Args["rustcFlags"], "crate-type="+dylibCrateType) { + t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", dylibCrateType, libfooDylib.Args["rustcFlags"]) + } + + // Test crate type for C static libraries is correct. + if !strings.Contains(libfooStatic.Args["rustcFlags"], "crate-type="+staticCrateType) { + t.Errorf("missing crate-type for static variant, expecting %#v, rustcFlags: %#v", staticCrateType, libfooStatic.Args["rustcFlags"]) } + + // Test crate type for C shared libraries is correct. + if !strings.Contains(libfooShared.Args["rustcFlags"], "crate-type="+sharedCrateType) { + t.Errorf("missing crate-type for shared variant, expecting %#v, got rustcFlags: %#v", sharedCrateType, libfooShared.Args["rustcFlags"]) + } + } // Test that dylibs are not statically linking the standard library. @@ -53,7 +71,7 @@ func TestDylibPreferDynamic(t *testing.T) { crate_name: "foo", }`) - libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.so") + libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib").Output("libfoo.dylib.so") if !strings.Contains(libfooDylib.Args["rustcFlags"], "prefer-dynamic") { t.Errorf("missing prefer-dynamic flag for libfoo dylib, rustcFlags: %#v", libfooDylib.Args["rustcFlags"]) |