rust: Add whole_static_libs, revert static_lib

Revert the static_lib behavior to the previous behavior (pass static
libs to the linker rather than via to rustc using `-lstatic=<lib>`). To
bundle static libraries into libraries, provide the whole_static_libs
property which retains the current static_libs behavior.

Passing all static libraries via -lstatic was resulting in odd bloat
where in some cases static symbols were duplicated in binaries and
libraries. This split makes it possible to be explicit about when static
libraries should be bundled.

Bug: 183182230
Test: mma system/bt; mma system/security/keystore2; mma external/rust

Change-Id: Ic2dde5d1542dca5ce145aa3a3fbd9ea54440d991
This commit is contained in:
Ivan Lozano
2021-03-23 15:53:44 -04:00
parent 6400f20430
commit 63bb7680c9
4 changed files with 55 additions and 27 deletions

View File

@@ -149,6 +149,11 @@ func TestDepsTracking(t *testing.T) {
srcs: ["foo.rs"],
crate_name: "static",
}
rust_ffi_host_static {
name: "libwholestatic",
srcs: ["foo.rs"],
crate_name: "wholestatic",
}
rust_ffi_host_shared {
name: "libshared",
srcs: ["foo.rs"],
@@ -164,6 +169,7 @@ func TestDepsTracking(t *testing.T) {
srcs: ["foo.rs"],
crate_name: "rlib",
static_libs: ["libstatic"],
whole_static_libs: ["libwholestatic"],
}
rust_proc_macro {
name: "libpm",
@@ -204,8 +210,8 @@ func TestDepsTracking(t *testing.T) {
t.Errorf("Static library dependency not detected (dependency missing from AndroidMkStaticLibs)")
}
if !strings.Contains(rustc.Args["rustcFlags"], "-lstatic=static") {
t.Errorf("-lstatic flag not being passed to rustc for static library")
if !strings.Contains(rustc.Args["rustcFlags"], "-lstatic=wholestatic") {
t.Errorf("-lstatic flag not being passed to rustc for static library %#v", rustc.Args["rustcFlags"])
}
}