diff options
Diffstat (limited to 'rust/compiler.go')
-rw-r--r-- | rust/compiler.go | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/rust/compiler.go b/rust/compiler.go index 664578d82..8d2f09c2b 100644 --- a/rust/compiler.go +++ b/rust/compiler.go @@ -24,6 +24,14 @@ import ( "android/soong/rust/config" ) +type RustLinkage int + +const ( + DefaultLinkage RustLinkage = iota + RlibLinkage + DylibLinkage +) + func (compiler *baseCompiler) edition() string { return proptools.StringDefault(compiler.Properties.Edition, config.DefaultEdition) } @@ -146,8 +154,13 @@ func (compiler *baseCompiler) coverageOutputZipPath() android.OptionalPath { panic("baseCompiler does not implement coverageOutputZipPath()") } -func (compiler *baseCompiler) static() bool { - return false +func (compiler *baseCompiler) stdLinkage(ctx *depsContext) RustLinkage { + // For devices, we always link stdlibs in as dylibs by default. + if ctx.Device() { + return DylibLinkage + } else { + return RlibLinkage + } } var _ compiler = (*baseCompiler)(nil) @@ -221,25 +234,24 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps { stdlib = stdlib + "_" + ctx.toolchain().RustTriple() } - // 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) - } + deps.Stdlibs = append(deps.Stdlibs, stdlib) } } return deps } -func bionicDeps(deps Deps) Deps { - deps.SharedLibs = append(deps.SharedLibs, "liblog") - deps.SharedLibs = append(deps.SharedLibs, "libc") - deps.SharedLibs = append(deps.SharedLibs, "libm") - deps.SharedLibs = append(deps.SharedLibs, "libdl") +func bionicDeps(deps Deps, static bool) Deps { + bionicLibs := []string{} + bionicLibs = append(bionicLibs, "liblog") + bionicLibs = append(bionicLibs, "libc") + bionicLibs = append(bionicLibs, "libm") + bionicLibs = append(bionicLibs, "libdl") + + if static { + deps.StaticLibs = append(deps.StaticLibs, bionicLibs...) + } else { + deps.SharedLibs = append(deps.SharedLibs, bionicLibs...) + } //TODO(b/141331117) libstd requires libgcc on Android deps.StaticLibs = append(deps.StaticLibs, "libgcc") |