rust: Add rustlibs auto dependency selection
Adds the rustlibs dependency type which will automatically select between rlib and dylib based on the type of the library. Bug: 143217452 Test: cd external/rust; mma Change-Id: I97faadae98bf957090a32939cfb2d3a10f74a057
This commit is contained in:
@@ -131,3 +131,11 @@ func (binary *binaryDecorator) compile(ctx ModuleContext, flags Flags, deps Path
|
||||
func (binary *binaryDecorator) coverageOutputZipPath() android.OptionalPath {
|
||||
return binary.coverageOutputZipFile
|
||||
}
|
||||
|
||||
func (binary *binaryDecorator) autoDep() autoDep {
|
||||
if binary.preferDynamic() {
|
||||
return dylibAutoDep
|
||||
} else {
|
||||
return rlibAutoDep
|
||||
}
|
||||
}
|
||||
|
@@ -67,6 +67,9 @@ type BaseCompilerProperties struct {
|
||||
// list of rust dylib crate dependencies
|
||||
Dylibs []string `android:"arch_variant"`
|
||||
|
||||
// list of rust automatic crate dependencies
|
||||
Rustlibs []string `android:"arch_variant"`
|
||||
|
||||
// list of rust proc_macro crate dependencies
|
||||
Proc_macros []string `android:"arch_variant"`
|
||||
|
||||
@@ -178,6 +181,7 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
|
||||
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...)
|
||||
deps.Rustlibs = append(deps.Rustlibs, compiler.Properties.Rustlibs...)
|
||||
deps.ProcMacros = append(deps.ProcMacros, compiler.Properties.Proc_macros...)
|
||||
deps.StaticLibs = append(deps.StaticLibs, compiler.Properties.Static_libs...)
|
||||
deps.SharedLibs = append(deps.SharedLibs, compiler.Properties.Shared_libs...)
|
||||
|
@@ -186,6 +186,16 @@ func (library *libraryDecorator) setStatic() {
|
||||
library.MutatedProperties.VariantIsDylib = false
|
||||
}
|
||||
|
||||
func (library *libraryDecorator) autoDep() autoDep {
|
||||
if library.rlib() || library.static() {
|
||||
return rlibAutoDep
|
||||
} else if library.dylib() || library.shared() {
|
||||
return dylibAutoDep
|
||||
} else {
|
||||
return rlibAutoDep
|
||||
}
|
||||
}
|
||||
|
||||
var _ compiler = (*libraryDecorator)(nil)
|
||||
var _ libraryInterface = (*libraryDecorator)(nil)
|
||||
|
||||
|
@@ -143,3 +143,50 @@ func TestSharedLibrary(t *testing.T) {
|
||||
libfoo.Module().(*Module).Properties.AndroidMkDylibs)
|
||||
}
|
||||
}
|
||||
|
||||
// Test that variants pull in the right type of rustlib autodep
|
||||
func TestAutoDeps(t *testing.T) {
|
||||
|
||||
ctx := testRust(t, `
|
||||
rust_library_host {
|
||||
name: "libbar",
|
||||
srcs: ["bar.rs"],
|
||||
crate_name: "bar",
|
||||
}
|
||||
rust_library_host {
|
||||
name: "libfoo",
|
||||
srcs: ["foo.rs"],
|
||||
crate_name: "foo",
|
||||
rustlibs: ["libbar"],
|
||||
}
|
||||
rust_ffi_host {
|
||||
name: "libfoo.ffi",
|
||||
srcs: ["foo.rs"],
|
||||
crate_name: "foo",
|
||||
rustlibs: ["libbar"],
|
||||
}`)
|
||||
|
||||
libfooRlib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_rlib")
|
||||
libfooDylib := ctx.ModuleForTests("libfoo", "linux_glibc_x86_64_dylib")
|
||||
libfooStatic := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_static")
|
||||
libfooShared := ctx.ModuleForTests("libfoo.ffi", "linux_glibc_x86_64_shared")
|
||||
|
||||
for _, static := range []android.TestingModule{libfooRlib, libfooStatic} {
|
||||
if !android.InList("libbar", static.Module().(*Module).Properties.AndroidMkRlibs) {
|
||||
t.Errorf("libbar not present as static dependency in static lib")
|
||||
}
|
||||
if android.InList("libbar", static.Module().(*Module).Properties.AndroidMkDylibs) {
|
||||
t.Errorf("libbar present as dynamic dependency in static lib")
|
||||
}
|
||||
}
|
||||
|
||||
for _, dyn := range []android.TestingModule{libfooDylib, libfooShared} {
|
||||
if !android.InList("libbar", dyn.Module().(*Module).Properties.AndroidMkDylibs) {
|
||||
t.Errorf("libbar not present as dynamic dependency in dynamic lib")
|
||||
}
|
||||
if android.InList("libbar", dyn.Module().(*Module).Properties.AndroidMkRlibs) {
|
||||
t.Errorf("libbar present as static dependency in dynamic lib")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -76,3 +76,7 @@ func (procMacro *procMacroDecorator) getStem(ctx ModuleContext) string {
|
||||
|
||||
return stem + String(procMacro.baseCompiler.Properties.Suffix)
|
||||
}
|
||||
|
||||
func (procMacro *procMacroDecorator) autoDep() autoDep {
|
||||
return rlibAutoDep
|
||||
}
|
||||
|
25
rust/rust.go
25
rust/rust.go
@@ -217,6 +217,7 @@ func (mod *Module) StubDecorator() bool {
|
||||
type Deps struct {
|
||||
Dylibs []string
|
||||
Rlibs []string
|
||||
Rustlibs []string
|
||||
ProcMacros []string
|
||||
SharedLibs []string
|
||||
StaticLibs []string
|
||||
@@ -617,6 +618,7 @@ func (mod *Module) deps(ctx DepsContext) Deps {
|
||||
|
||||
deps.Rlibs = android.LastUniqueStrings(deps.Rlibs)
|
||||
deps.Dylibs = android.LastUniqueStrings(deps.Dylibs)
|
||||
deps.Rustlibs = android.LastUniqueStrings(deps.Rustlibs)
|
||||
deps.ProcMacros = android.LastUniqueStrings(deps.ProcMacros)
|
||||
deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
|
||||
deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
|
||||
@@ -639,6 +641,20 @@ var (
|
||||
testPerSrcDepTag = dependencyTag{name: "rust_unit_tests"}
|
||||
)
|
||||
|
||||
type autoDep struct {
|
||||
variation string
|
||||
depTag dependencyTag
|
||||
}
|
||||
|
||||
var (
|
||||
rlibAutoDep = autoDep{variation: "rlib", depTag: rlibDepTag}
|
||||
dylibAutoDep = autoDep{variation: "dylib", depTag: dylibDepTag}
|
||||
)
|
||||
|
||||
type autoDeppable interface {
|
||||
autoDep() autoDep
|
||||
}
|
||||
|
||||
func (mod *Module) begin(ctx BaseModuleContext) {
|
||||
if mod.coverage != nil {
|
||||
mod.coverage.begin(ctx)
|
||||
@@ -844,6 +860,15 @@ func (mod *Module) DepsMutator(actx android.BottomUpMutatorContext) {
|
||||
{Mutator: "link", Variation: ""}}...),
|
||||
dylibDepTag, deps.Dylibs...)
|
||||
|
||||
if deps.Rustlibs != nil {
|
||||
autoDep := mod.compiler.(autoDeppable).autoDep()
|
||||
actx.AddVariationDependencies(
|
||||
append(commonDepVariations, []blueprint.Variation{
|
||||
{Mutator: "rust_libraries", Variation: autoDep.variation},
|
||||
{Mutator: "link", Variation: ""}}...),
|
||||
autoDep.depTag, deps.Rustlibs...)
|
||||
}
|
||||
|
||||
actx.AddVariationDependencies(append(commonDepVariations,
|
||||
blueprint.Variation{Mutator: "link", Variation: "shared"}),
|
||||
cc.SharedDepTag, deps.SharedLibs...)
|
||||
|
@@ -105,6 +105,10 @@ func (test *testDecorator) compilerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||
return flags
|
||||
}
|
||||
|
||||
func (test *testDecorator) autoDep() autoDep {
|
||||
return rlibAutoDep
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Rust tests are binary files built with --test.
|
||||
android.RegisterModuleType("rust_test", RustTestFactory)
|
||||
|
Reference in New Issue
Block a user