rust: Only pass "-lstatic" for rlibs.
Passing '-lstatic' for dylib static dependencies results in some unexpected bloat as the static libraries are included as whole-archives. For now, limit this to rlibs while we investigate. Bug: 175886967 Bug: 179122837 Test: cd system/bt/; mma Test: Checked size of dylibs. Change-Id: Id8328e95771e2ca8503bc8df35248b1c39cabc8e
This commit is contained in:
19
rust/rust.go
19
rust/rust.go
@@ -896,14 +896,17 @@ func (mod *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
|||||||
exportDep := false
|
exportDep := false
|
||||||
switch {
|
switch {
|
||||||
case cc.IsStaticDepTag(depTag):
|
case cc.IsStaticDepTag(depTag):
|
||||||
// Link cc static libraries using "-lstatic" so rustc can reason about how to handle these
|
// Only pass -lstatic for rlibs as it results in dylib bloat.
|
||||||
// (for example, bundling them into rlibs).
|
if lib, ok := ctx.Module().(*Module).compiler.(libraryInterface); ok && lib.rlib() {
|
||||||
//
|
// Link cc static libraries using "-lstatic" so rustc can reason about how to handle these
|
||||||
// rustc does not support linking libraries with the "-l" flag unless they are prefixed by "lib".
|
// (for example, bundling them into rlibs).
|
||||||
// If we need to link a library that isn't prefixed by "lib", we'll just link to it directly through
|
//
|
||||||
// linkObjects; such a library may need to be redeclared by static dependents.
|
// rustc does not support linking libraries with the "-l" flag unless they are prefixed by "lib".
|
||||||
if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
|
// If we need to link a library that isn't prefixed by "lib", we'll just link to it directly through
|
||||||
depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
|
// linkObjects; such a library may need to be redeclared by static dependents.
|
||||||
|
if libName, ok := libNameFromFilePath(linkObject.Path()); ok {
|
||||||
|
depPaths.depFlags = append(depPaths.depFlags, "-lstatic="+libName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add this to linkObjects to pass the library directly to the linker as well. This propagates
|
// Add this to linkObjects to pass the library directly to the linker as well. This propagates
|
||||||
|
@@ -213,6 +213,7 @@ func TestDepsTracking(t *testing.T) {
|
|||||||
name: "librlib",
|
name: "librlib",
|
||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
crate_name: "rlib",
|
crate_name: "rlib",
|
||||||
|
static_libs: ["libstatic"],
|
||||||
}
|
}
|
||||||
rust_proc_macro {
|
rust_proc_macro {
|
||||||
name: "libpm",
|
name: "libpm",
|
||||||
@@ -230,7 +231,7 @@ func TestDepsTracking(t *testing.T) {
|
|||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module)
|
module := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Module().(*Module)
|
||||||
rustc := ctx.ModuleForTests("fizz-buzz", "linux_glibc_x86_64").Rule("rustc")
|
rustc := ctx.ModuleForTests("librlib", "linux_glibc_x86_64_rlib_rlib-std").Rule("rustc")
|
||||||
|
|
||||||
// Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up.
|
// Since dependencies are added to AndroidMk* properties, we can check these to see if they've been picked up.
|
||||||
if !android.InList("libdylib", module.Properties.AndroidMkDylibs) {
|
if !android.InList("libdylib", module.Properties.AndroidMkDylibs) {
|
||||||
|
Reference in New Issue
Block a user