Link device binaries dynamically by default.
Device binaries currently are linked statically by default. Instead we
should be linking these dynamic by default. To avoid conflicts when
manually specifying rlib dependencies on modules, we always link libstd
dynamically for all device modules except static libraries.
This removes the "prefer_dynamic" property entirely to avoid confusion.
Bug: 165161105
Test: m profcollectd is built dynamically.
Test: cd external/rust/; mma
Test: cd external/crosvm/; mma
Change-Id: I25ac897040acbcc2d97c791a33e8e01610632272
diff --git a/rust/compiler.go b/rust/compiler.go
index ef7fb8c..2600f4d 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -145,6 +145,10 @@
panic("baseCompiler does not implement coverageOutputZipPath()")
}
+func (compiler *baseCompiler) static() bool {
+ return false
+}
+
var _ compiler = (*baseCompiler)(nil)
func (compiler *baseCompiler) inData() bool {
@@ -216,7 +220,15 @@
stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
}
- deps.Rustlibs = append(deps.Rustlibs, stdlib)
+ // For devices, we always link stdlibs in as dylibs except for ffi static libraries.
+ // (rustc does not support linking libstd as a dylib for ffi static libraries)
+ if ctx.Host() {
+ deps.Rustlibs = append(deps.Rustlibs, stdlib)
+ } else if ctx.RustModule().compiler.static() {
+ deps.Rlibs = append(deps.Rlibs, stdlib)
+ } else {
+ deps.Dylibs = append(deps.Dylibs, stdlib)
+ }
}
}
return deps