From 52767be335c200dfbf2af3da802e24a1cc91f1bf Mon Sep 17 00:00:00 2001 From: Ivan Lozano Date: Fri, 18 Oct 2019 14:49:46 -0700 Subject: 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 --- rust/rust_test.go | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'rust/rust_test.go') diff --git a/rust/rust_test.go b/rust/rust_test.go index 0c8d35586..eb04e7257 100644 --- a/rust/rust_test.go +++ b/rust/rust_test.go @@ -101,12 +101,20 @@ func testRustError(t *testing.T, pattern string, bp string) { // Test that we can extract the lib name from a lib path. func TestLibNameFromFilePath(t *testing.T) { - barPath := android.PathForTesting("out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/libbar.so") - libName := libNameFromFilePath(barPath) + libBarPath := android.PathForTesting("out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/libbar.so") + libLibPath := android.PathForTesting("out/soong/.intermediates/external/libbar/libbar/linux_glibc_x86_64_shared/liblib.dylib.so") + + libBarName := libNameFromFilePath(libBarPath) + libLibName := libNameFromFilePath(libLibPath) + expectedResult := "bar" + if libBarName != expectedResult { + t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libBarName) + } - if libName != expectedResult { - t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libName) + expectedResult = "lib.dylib" + if libLibName != expectedResult { + t.Errorf("libNameFromFilePath returned the wrong name; expected '%#v', got '%#v'", expectedResult, libLibPath) } } @@ -140,12 +148,20 @@ func TestDefaultCrateName(t *testing.T) { // Test to make sure dependencies are being picked up correctly. func TestDepsTracking(t *testing.T) { ctx := testRust(t, ` + rust_library_host_static { + name: "libstatic", + srcs: ["foo.rs"], + } + rust_library_host_shared { + name: "libshared", + srcs: ["foo.rs"], + } rust_library_host_dylib { - name: "libfoo", + name: "libdylib", srcs: ["foo.rs"], } rust_library_host_rlib { - name: "libbar", + name: "librlib", srcs: ["foo.rs"], } rust_proc_macro { @@ -154,20 +170,22 @@ func TestDepsTracking(t *testing.T) { } rust_binary_host { name: "fizz-buzz", - dylibs: ["libfoo"], - rlibs: ["libbar"], + dylibs: ["libdylib"], + rlibs: ["librlib"], proc_macros: ["libpm"], + static_libs: ["libstatic"], + shared_libs: ["libshared"], srcs: ["foo.rs"], } `) module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module) // Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up. - if !android.InList("libfoo", module.Properties.AndroidMkDylibs) { + if !android.InList("libdylib", module.Properties.AndroidMkDylibs) { t.Errorf("Dylib dependency not detected (dependency missing from AndroidMkDylibs)") } - if !android.InList("libbar", module.Properties.AndroidMkRlibs) { + if !android.InList("librlib", module.Properties.AndroidMkRlibs) { t.Errorf("Rlib dependency not detected (dependency missing from AndroidMkRlibs)") } @@ -175,6 +193,13 @@ func TestDepsTracking(t *testing.T) { t.Errorf("Proc_macro dependency not detected (dependency missing from AndroidMkProcMacroLibs)") } + if !android.InList("libshared", module.Properties.AndroidMkSharedLibs) { + t.Errorf("Shared library dependency not detected (dependency missing from AndroidMkSharedLibs)") + } + + if !android.InList("libstatic", module.Properties.AndroidMkStaticLibs) { + t.Errorf("Static library dependency not detected (dependency missing from AndroidMkStaticLibs)") + } } // Test to make sure proc_macros use host variants when building device modules. -- cgit v1.2.3-59-g8ed1b