diff options
author | 2023-08-17 15:46:39 -0400 | |
---|---|---|
committer | 2023-08-17 16:54:48 -0400 | |
commit | 156ea44375a58b28f7b57c4b8c39be962c251808 (patch) | |
tree | c21260fc053f0741f6f074f8dabdf45aa73435de /rust/library_test.go | |
parent | 88df1d3e0b750e1a3c1cff1fa73576e9fbfe9e3d (diff) |
Add test to confirm -L flag for cc deps in rust
Test: go test
Change-Id: Ib9c7e109a0bd9f54dfdbdf5b3764e2d3e8272b1b
Diffstat (limited to 'rust/library_test.go')
-rw-r--r-- | rust/library_test.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/rust/library_test.go b/rust/library_test.go index add7173bc..30ef333b9 100644 --- a/rust/library_test.go +++ b/rust/library_test.go @@ -196,6 +196,65 @@ func TestStaticLibraryLinkage(t *testing.T) { } } +func TestNativeDependencyOfRlib(t *testing.T) { + ctx := testRust(t, ` + rust_ffi_static { + name: "libffi_static", + crate_name: "ffi_static", + rlibs: ["librust_rlib"], + srcs: ["foo.rs"], + } + rust_library_rlib { + name: "librust_rlib", + crate_name: "rust_rlib", + srcs: ["foo.rs"], + shared_libs: ["shared_cc_dep"], + static_libs: ["static_cc_dep"], + } + cc_library_shared { + name: "shared_cc_dep", + srcs: ["foo.cpp"], + } + cc_library_static { + name: "static_cc_dep", + srcs: ["foo.cpp"], + } + `) + + rustRlibRlibStd := ctx.ModuleForTests("librust_rlib", "android_arm64_armv8-a_rlib_rlib-std") + rustRlibDylibStd := ctx.ModuleForTests("librust_rlib", "android_arm64_armv8-a_rlib_dylib-std") + ffiStatic := ctx.ModuleForTests("libffi_static", "android_arm64_armv8-a_static") + + modules := []android.TestingModule{ + rustRlibRlibStd, + rustRlibDylibStd, + ffiStatic, + } + + // librust_rlib specifies -L flag to cc deps output directory on rustc command + // and re-export the cc deps to rdep libffi_static + // When building rlib crate, rustc doesn't link the native libraries + // The build system assumes the cc deps will be at the final linkage (either a shared library or binary) + // Hence, these flags are no-op + // TODO: We could consider removing these flags + for _, module := range modules { + if !strings.Contains(module.Rule("rustc").Args["libFlags"], + "-L out/soong/.intermediates/shared_cc_dep/android_arm64_armv8-a_shared/") { + t.Errorf( + "missing -L flag for shared_cc_dep, rustcFlags: %#v", + rustRlibRlibStd.Rule("rustc").Args["libFlags"], + ) + } + if !strings.Contains(module.Rule("rustc").Args["libFlags"], + "-L out/soong/.intermediates/static_cc_dep/android_arm64_armv8-a_static/") { + t.Errorf( + "missing -L flag for static_cc_dep, rustcFlags: %#v", + rustRlibRlibStd.Rule("rustc").Args["libFlags"], + ) + } + } +} + // Test that variants pull in the right type of rustlib autodep func TestAutoDeps(t *testing.T) { |