Add unit test to verify default linkage for rust binaries

Test: go test
Change-Id: I16eed90dffc8f98a880aa801e96601227dcc37be
This commit is contained in:
Vinh Tran
2023-08-14 11:26:18 -04:00
parent 88df1d3e0b
commit 05b3410290

View File

@@ -21,6 +21,27 @@ import (
"android/soong/android"
)
// Test that rustlibs default linkage is always rlib for host binaries.
func TestBinaryHostLinkage(t *testing.T) {
ctx := testRust(t, `
rust_binary_host {
name: "fizz-buzz",
srcs: ["foo.rs"],
rustlibs: ["libfoo"],
}
rust_library {
name: "libfoo",
srcs: ["foo.rs"],
crate_name: "foo",
host_supported: true,
}
`)
fizzBuzz := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module)
if !android.InList("libfoo.rlib-std", fizzBuzz.Properties.AndroidMkRlibs) {
t.Errorf("rustlibs dependency libfoo should be an rlib dep for host binaries")
}
}
// Test that rustlibs default linkage is correct for binaries.
func TestBinaryLinkage(t *testing.T) {
ctx := testRust(t, `
@@ -54,6 +75,12 @@ func TestBinaryLinkage(t *testing.T) {
if !android.InList("libfoo", fizzBuzzDevice.Properties.AndroidMkDylibs) {
t.Errorf("rustlibs dependency libfoo should be an dylib dep for device modules")
}
rlibLinkDevice := ctx.ModuleForTests("rlib_linked", "android_arm64_armv8-a").Module().(*Module)
if !android.InList("libfoo.rlib-std", rlibLinkDevice.Properties.AndroidMkRlibs) {
t.Errorf("rustlibs dependency libfoo should be an rlib dep for device modules when prefer_rlib is set")
}
}
// Test that prefer_rlib links in libstd statically as well as rustlibs.