summaryrefslogtreecommitdiff
path: root/rust/compiler.go
diff options
context:
space:
mode:
authorMatthew Maurer <mmaurer@google.com>2019-10-31 10:44:40 -0700
committerMatthew Maurer <mmaurer@google.com>2019-11-13 17:46:19 -0800
commit99020b04fbf5ce97d9a7a5b56b44cadeeb34ca4c (patch)
treead88fefd6317657e8977d0fcc73313d4c590df14 /rust/compiler.go
parent940ef19f77ed30fb1b3c850ef4f880420a6fb456 (diff)
Build Rust Device Sysroots in Soong
In order to ensure we are using current platform Bionic for any platform Rust binaries, we need to build the sysroot in Soong. This will also enable us too hook the "test" crate if necessary. While both a dynamic and static sysroot are available, on device only a dynamic sysroot will be injected. On host, we continue using the sysroot used to build the compiler as before. Bug: 139486496 Change-Id: I127377e5b056610ceb5015a34d266250320fbc31
Diffstat (limited to 'rust/compiler.go')
-rw-r--r--rust/compiler.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/rust/compiler.go b/rust/compiler.go
index 3f028350a..f6e952a75 100644
--- a/rust/compiler.go
+++ b/rust/compiler.go
@@ -31,6 +31,10 @@ func getDenyWarnings(compiler *baseCompiler) bool {
return BoolDefault(compiler.Properties.Deny_warnings, config.DefaultDenyWarnings)
}
+func (compiler *baseCompiler) setNoStdlibs() {
+ compiler.Properties.No_stdlibs = proptools.BoolPtr(true)
+}
+
func NewBaseCompiler(dir, dir64 string) *baseCompiler {
return &baseCompiler{
Properties: BaseCompilerProperties{},
@@ -81,6 +85,9 @@ type BaseCompilerProperties struct {
// install to a subdirectory of the default install path for the module
Relative_install_path *string `android:"arch_variant"`
+
+ // whether to suppress inclusion of standard crates - defaults to false
+ No_stdlibs *bool
}
type baseCompiler struct {
@@ -160,6 +167,23 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...)
deps.SharedLibs = append(deps.SharedLibs, compiler.Properties.Shared_libs...)
+ if !Bool(compiler.Properties.No_stdlibs) {
+ for _, stdlib := range config.Stdlibs {
+ // If we're building for host, use the compiler's stdlibs
+ if ctx.Host() {
+ stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
+ }
+
+ // This check is technically insufficient - on the host, where
+ // static linking is the default, if one of our static
+ // dependencies uses a dynamic library, we need to dynamically
+ // link the stdlib as well.
+ if (len(deps.Dylibs) > 0) || (!ctx.Host()) {
+ // Dynamically linked stdlib
+ deps.Dylibs = append(deps.Dylibs, stdlib)
+ }
+ }
+ }
return deps
}