summaryrefslogtreecommitdiff
path: root/rust/image_test.go
diff options
context:
space:
mode:
author Ivan Lozano <ivanlozano@google.com> 2024-05-13 21:03:34 -0400
committer Ivan Lozano <ivanlozano@google.com> 2024-05-16 13:00:43 -0400
commit0a468a4f3b1c9dea9b31ca51cebd3db58d65e771 (patch)
tree9ee8007e83b660eb7bb4affcbf6584ea3fdab82e /rust/image_test.go
parent28ed8f4f83551ca651dd3831eb5b0a23567f5fa6 (diff)
rust: made-to-order rust staticlibs
Whenever any two Rust static libraries are included as static libraries anywhere in a CC dependency tree, we sometimes get duplicate symbol errors. To avoid this, we no longer directly link multiple rust static libs to CC modules. Instead, we build rust_ffi_rlib modules and produce the actual static library that gets linked against the CC module based on that CC module's full list of Rust rlib dependencies. This introduces a new static_rlibs property for cc modules to define the rust_ffi_rlib dependencies, which are then used to generate the module above. This CL is intended to deprecate rust_ffi_static. It leaves rust_ffi_static and rust_ffi static variants in place until the remaining rust_ffi_static declarations and uses can be removed. In the meantime, rust_ffi_static produces rust_ffi_rlib variants as well to make the transition easier. Bug: 254469782 Test: m # with no changes Test: m libapexsupport # with static_rlibs Test: m libunwindstack # with static_rlibs Test: m netsimd # with static_rlibs, no duplicate symbols Test: m blueprint_tests # New Soong tests Change-Id: I47e27ac967ef0cad46d398ebf59d8275929ae28a
Diffstat (limited to 'rust/image_test.go')
-rw-r--r--rust/image_test.go55
1 files changed, 37 insertions, 18 deletions
diff --git a/rust/image_test.go b/rust/image_test.go
index ba94906c6..71e271c89 100644
--- a/rust/image_test.go
+++ b/rust/image_test.go
@@ -22,33 +22,45 @@ import (
"android/soong/cc"
)
-// Test that cc modules can link against vendor_available rust_ffi_static libraries.
+// Test that cc modules can link against vendor_available rust_ffi_rlib/rust_ffi_static libraries.
func TestVendorLinkage(t *testing.T) {
ctx := testRust(t, `
cc_binary {
- name: "fizz_vendor",
- static_libs: ["libfoo_vendor"],
+ name: "fizz_vendor_available",
+ static_libs: ["libfoo_vendor_static"],
+ static_rlibs: ["libfoo_vendor"],
+ vendor_available: true,
+ }
+ cc_binary {
+ name: "fizz_soc_specific",
+ static_rlibs: ["libfoo_vendor"],
soc_specific: true,
}
- rust_ffi_static {
+ rust_ffi_rlib {
name: "libfoo_vendor",
crate_name: "foo",
srcs: ["foo.rs"],
vendor_available: true,
}
+ rust_ffi_static {
+ name: "libfoo_vendor_static",
+ crate_name: "foo",
+ srcs: ["foo.rs"],
+ vendor_available: true,
+ }
`)
- vendorBinary := ctx.ModuleForTests("fizz_vendor", "android_vendor_arm64_armv8-a").Module().(*cc.Module)
+ vendorBinary := ctx.ModuleForTests("fizz_vendor_available", "android_vendor_arm64_armv8-a").Module().(*cc.Module)
- if !android.InList("libfoo_vendor.vendor", vendorBinary.Properties.AndroidMkStaticLibs) {
- t.Errorf("vendorBinary should have a dependency on libfoo_vendor: %#v", vendorBinary.Properties.AndroidMkStaticLibs)
+ if !android.InList("libfoo_vendor_static.vendor", vendorBinary.Properties.AndroidMkStaticLibs) {
+ t.Errorf("vendorBinary should have a dependency on libfoo_vendor_static.vendor: %#v", vendorBinary.Properties.AndroidMkStaticLibs)
}
}
// Test that variants which use the vndk emit the appropriate cfg flag.
func TestImageCfgFlag(t *testing.T) {
ctx := testRust(t, `
- rust_ffi_static {
+ rust_ffi_shared {
name: "libfoo",
crate_name: "foo",
srcs: ["foo.rs"],
@@ -57,7 +69,7 @@ func TestImageCfgFlag(t *testing.T) {
}
`)
- vendor := ctx.ModuleForTests("libfoo", "android_vendor_arm64_armv8-a_static").Rule("rustc")
+ vendor := ctx.ModuleForTests("libfoo", "android_vendor_arm64_armv8-a_shared").Rule("rustc")
if !strings.Contains(vendor.Args["rustcFlags"], "--cfg 'android_vndk'") {
t.Errorf("missing \"--cfg 'android_vndk'\" for libfoo vendor variant, rustcFlags: %#v", vendor.Args["rustcFlags"])
@@ -69,7 +81,7 @@ func TestImageCfgFlag(t *testing.T) {
t.Errorf("unexpected \"--cfg 'android_product'\" for libfoo vendor variant, rustcFlags: %#v", vendor.Args["rustcFlags"])
}
- product := ctx.ModuleForTests("libfoo", "android_product_arm64_armv8-a_static").Rule("rustc")
+ product := ctx.ModuleForTests("libfoo", "android_product_arm64_armv8-a_shared").Rule("rustc")
if !strings.Contains(product.Args["rustcFlags"], "--cfg 'android_vndk'") {
t.Errorf("missing \"--cfg 'android_vndk'\" for libfoo product variant, rustcFlags: %#v", product.Args["rustcFlags"])
}
@@ -80,7 +92,7 @@ func TestImageCfgFlag(t *testing.T) {
t.Errorf("missing \"--cfg 'android_product'\" for libfoo product variant, rustcFlags: %#v", product.Args["rustcFlags"])
}
- system := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_static").Rule("rustc")
+ system := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared").Rule("rustc")
if strings.Contains(system.Args["rustcFlags"], "--cfg 'android_vndk'") {
t.Errorf("unexpected \"--cfg 'android_vndk'\" for libfoo system variant, rustcFlags: %#v", system.Args["rustcFlags"])
}
@@ -93,27 +105,34 @@ func TestImageCfgFlag(t *testing.T) {
}
-// Test that cc modules can link against vendor_ramdisk_available rust_ffi_static libraries.
+// Test that cc modules can link against vendor_ramdisk_available rust_ffi_rlib and rust_ffi_static libraries.
func TestVendorRamdiskLinkage(t *testing.T) {
ctx := testRust(t, `
- cc_library_static {
+ cc_library_shared {
name: "libcc_vendor_ramdisk",
- static_libs: ["libfoo_vendor_ramdisk"],
+ static_rlibs: ["libfoo_vendor_ramdisk"],
+ static_libs: ["libfoo_static_vendor_ramdisk"],
system_shared_libs: [],
vendor_ramdisk_available: true,
}
- rust_ffi_static {
+ rust_ffi_rlib {
name: "libfoo_vendor_ramdisk",
crate_name: "foo",
srcs: ["foo.rs"],
vendor_ramdisk_available: true,
}
+ rust_ffi_static {
+ name: "libfoo_static_vendor_ramdisk",
+ crate_name: "foo",
+ srcs: ["foo.rs"],
+ vendor_ramdisk_available: true,
+ }
`)
- vendorRamdiskLibrary := ctx.ModuleForTests("libcc_vendor_ramdisk", "android_vendor_ramdisk_arm64_armv8-a_static").Module().(*cc.Module)
+ vendorRamdiskLibrary := ctx.ModuleForTests("libcc_vendor_ramdisk", "android_vendor_ramdisk_arm64_armv8-a_shared").Module().(*cc.Module)
- if !android.InList("libfoo_vendor_ramdisk.vendor_ramdisk", vendorRamdiskLibrary.Properties.AndroidMkStaticLibs) {
- t.Errorf("libcc_vendor_ramdisk should have a dependency on libfoo_vendor_ramdisk")
+ if !android.InList("libfoo_static_vendor_ramdisk.vendor_ramdisk", vendorRamdiskLibrary.Properties.AndroidMkStaticLibs) {
+ t.Errorf("libcc_vendor_ramdisk should have a dependency on libfoo_static_vendor_ramdisk")
}
}