From 05b3410290a954733a507fcac4862c10cb1a43c0 Mon Sep 17 00:00:00 2001 From: Vinh Tran Date: Mon, 14 Aug 2023 11:26:18 -0400 Subject: Add unit test to verify default linkage for rust binaries Test: go test Change-Id: I16eed90dffc8f98a880aa801e96601227dcc37be --- rust/binary_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'rust/binary_test.go') diff --git a/rust/binary_test.go b/rust/binary_test.go index dd4f99314..fc4c56037 100644 --- a/rust/binary_test.go +++ b/rust/binary_test.go @@ -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. -- cgit v1.2.3-59-g8ed1b