diff options
Diffstat (limited to 'rust/compiler.go')
-rw-r--r-- | rust/compiler.go | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/rust/compiler.go b/rust/compiler.go index 8d2f09c2b..bcea6cccc 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -122,6 +122,17 @@ type BaseCompilerProperties struct { // whether to suppress inclusion of standard crates - defaults to false No_stdlibs *bool + + // Change the rustlibs linkage to select rlib linkage by default for device targets. + // Also link libstd as an rlib as well on device targets. + // Note: This is the default behavior for host targets. + // + // This is primarily meant for rust_binary and rust_ffi modules where the default + // linkage of libstd might need to be overridden in some use cases. This should + // generally be avoided with other module types since it may cause collisions at + // linkage if all dependencies of the root binary module do not link against libstd\ + // the same way. + Prefer_rlib *bool `android:"arch_variant"` } type baseCompiler struct { @@ -154,9 +165,15 @@ func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath { panic("baseCompiler does not implement coverageOutputZipPath()") } +func (compiler *baseCompiler) preferRlib() bool { + return Bool(compiler.Properties.Prefer_rlib) +} + func (compiler *baseCompiler) stdLinkage(ctx *depsContext) RustLinkage { // For devices, we always link stdlibs in as dylibs by default. - if ctx.Device() { + if compiler.preferRlib() { + return RlibLinkage + } else if ctx.Device() { return DylibLinkage } else { return RlibLinkage @@ -197,9 +214,9 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag flags.GlobalLinkFlags = append(flags.GlobalLinkFlags, ctx.toolchain().ToolchainLinkFlags()) if ctx.Host() && !ctx.Windows() { - rpath_prefix := `\$$ORIGIN/` + rpathPrefix := `\$$ORIGIN/` if ctx.Darwin() { - rpath_prefix = "@loader_path/" + rpathPrefix = "@loader_path/" } var rpath string @@ -208,8 +225,8 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag } else { rpath = "lib" } - flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpath_prefix+rpath) - flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpath_prefix+"../"+rpath) + flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpathPrefix+rpath) + flags.LinkFlags = append(flags.LinkFlags, "-Wl,-rpath,"+rpathPrefix+"../"+rpath) } return flags @@ -219,6 +236,10 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD panic(fmt.Errorf("baseCrater doesn't know how to crate things!")) } +func (compiler *baseCompiler) isDependencyRoot() bool { + return false +} + func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { deps.Rlibs = append(deps.Rlibs, compiler.Properties.Rlibs...) deps.Dylibs = append(deps.Dylibs, compiler.Properties.Dylibs...) |