Merge "Add unit test to verify default linkage for rust binaries" into main
This commit is contained in:
@@ -21,6 +21,27 @@ import (
|
|||||||
"android/soong/android"
|
"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.
|
// Test that rustlibs default linkage is correct for binaries.
|
||||||
func TestBinaryLinkage(t *testing.T) {
|
func TestBinaryLinkage(t *testing.T) {
|
||||||
ctx := testRust(t, `
|
ctx := testRust(t, `
|
||||||
@@ -54,6 +75,12 @@ func TestBinaryLinkage(t *testing.T) {
|
|||||||
if !android.InList("libfoo", fizzBuzzDevice.Properties.AndroidMkDylibs) {
|
if !android.InList("libfoo", fizzBuzzDevice.Properties.AndroidMkDylibs) {
|
||||||
t.Errorf("rustlibs dependency libfoo should be an dylib dep for device modules")
|
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.
|
// Test that prefer_rlib links in libstd statically as well as rustlibs.
|
||||||
|
Reference in New Issue
Block a user