rust: Mutate prebuilt modules dylib/rlib
This change makes it possible to use a single module to provide both dylib and rlib varieties of a library. This allows the use of libstd and libtest from a rustlibs property, allowing linkage type to change for different variants. Bug: 159718669 Test: cd external crates; mma; m crosvm.experimental Change-Id: I477c4d2faec63703fdc6dd42ba020747d6a50714
This commit is contained in:
parent
0f003b1851
commit
c761eeca48
5 changed files with 76 additions and 36 deletions
|
@ -193,17 +193,7 @@ func (compiler *baseCompiler) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
|
stdlib = stdlib + "_" + ctx.toolchain().RustTriple()
|
||||||
}
|
}
|
||||||
|
|
||||||
// This check is technically insufficient - on the host, where
|
deps.Rustlibs = append(deps.Rustlibs, stdlib)
|
||||||
// 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.Device() {
|
|
||||||
// Dynamically linked stdlib
|
|
||||||
deps.Dylibs = append(deps.Dylibs, stdlib)
|
|
||||||
} else if ctx.Host() && !ctx.TargetPrimary() {
|
|
||||||
// Otherwise use the static in-tree stdlib for host secondary arch
|
|
||||||
deps.Rlibs = append(deps.Rlibs, stdlib+".static")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return deps
|
return deps
|
||||||
|
|
|
@ -38,7 +38,8 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
type VariantLibraryProperties struct {
|
type VariantLibraryProperties struct {
|
||||||
Enabled *bool `android:"arch_variant"`
|
Enabled *bool `android:"arch_variant"`
|
||||||
|
Srcs []string `android:"path,arch_variant"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LibraryCompilerProperties struct {
|
type LibraryCompilerProperties struct {
|
||||||
|
@ -355,7 +356,7 @@ func (library *libraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
if !ctx.Host() && library.static() {
|
if !ctx.Host() && library.static() {
|
||||||
library.setNoStdlibs()
|
library.setNoStdlibs()
|
||||||
for _, stdlib := range config.Stdlibs {
|
for _, stdlib := range config.Stdlibs {
|
||||||
deps.Rlibs = append(deps.Rlibs, stdlib+".static")
|
deps.Rlibs = append(deps.Rlibs, stdlib)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
android.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
|
||||||
android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
||||||
|
android.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PrebuiltProperties struct {
|
type PrebuiltProperties struct {
|
||||||
|
@ -34,16 +36,47 @@ type prebuiltLibraryDecorator struct {
|
||||||
|
|
||||||
var _ compiler = (*prebuiltLibraryDecorator)(nil)
|
var _ compiler = (*prebuiltLibraryDecorator)(nil)
|
||||||
|
|
||||||
|
func PrebuiltLibraryFactory() android.Module {
|
||||||
|
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
||||||
|
return module.Init()
|
||||||
|
}
|
||||||
|
|
||||||
func PrebuiltDylibFactory() android.Module {
|
func PrebuiltDylibFactory() android.Module {
|
||||||
module, _ := NewPrebuiltDylib(android.HostAndDeviceSupported)
|
module, _ := NewPrebuiltDylib(android.HostAndDeviceSupported)
|
||||||
return module.Init()
|
return module.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PrebuiltRlibFactory() android.Module {
|
||||||
|
module, _ := NewPrebuiltRlib(android.HostAndDeviceSupported)
|
||||||
|
return module.Init()
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
||||||
|
module, library := NewRustLibrary(hod)
|
||||||
|
library.BuildOnlyRust()
|
||||||
|
library.setNoStdlibs()
|
||||||
|
prebuilt := &prebuiltLibraryDecorator{
|
||||||
|
libraryDecorator: library,
|
||||||
|
}
|
||||||
|
module.compiler = prebuilt
|
||||||
|
return module, prebuilt
|
||||||
|
}
|
||||||
|
|
||||||
func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
||||||
module, library := NewRustLibrary(hod)
|
module, library := NewRustLibrary(hod)
|
||||||
library.BuildOnlyDylib()
|
library.BuildOnlyDylib()
|
||||||
library.setNoStdlibs()
|
library.setNoStdlibs()
|
||||||
library.setDylib()
|
prebuilt := &prebuiltLibraryDecorator{
|
||||||
|
libraryDecorator: library,
|
||||||
|
}
|
||||||
|
module.compiler = prebuilt
|
||||||
|
return module, prebuilt
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPrebuiltRlib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
|
||||||
|
module, library := NewRustLibrary(hod)
|
||||||
|
library.BuildOnlyRlib()
|
||||||
|
library.setNoStdlibs()
|
||||||
prebuilt := &prebuiltLibraryDecorator{
|
prebuilt := &prebuiltLibraryDecorator{
|
||||||
libraryDecorator: library,
|
libraryDecorator: library,
|
||||||
}
|
}
|
||||||
|
@ -57,7 +90,7 @@ func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
||||||
srcPath := srcPathFromModuleSrcs(ctx, prebuilt.Properties.Srcs)
|
srcPath := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
||||||
|
|
||||||
prebuilt.unstrippedOutputFile = srcPath
|
prebuilt.unstrippedOutputFile = srcPath
|
||||||
|
|
||||||
|
@ -72,3 +105,15 @@ func (prebuilt *prebuiltLibraryDecorator) compilerDeps(ctx DepsContext, deps Dep
|
||||||
func (prebuilt *prebuiltLibraryDecorator) nativeCoverage() bool {
|
func (prebuilt *prebuiltLibraryDecorator) nativeCoverage() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (prebuilt *prebuiltLibraryDecorator) prebuiltSrcs() []string {
|
||||||
|
srcs := prebuilt.Properties.Srcs
|
||||||
|
if prebuilt.rlib() {
|
||||||
|
srcs = append(srcs, prebuilt.libraryDecorator.Properties.Rlib.Srcs...)
|
||||||
|
}
|
||||||
|
if prebuilt.dylib() {
|
||||||
|
srcs = append(srcs, prebuilt.libraryDecorator.Properties.Dylib.Srcs...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return srcs
|
||||||
|
}
|
||||||
|
|
|
@ -440,6 +440,9 @@ func (mod *Module) HasStaticVariant() bool {
|
||||||
|
|
||||||
func (mod *Module) CoverageFiles() android.Paths {
|
func (mod *Module) CoverageFiles() android.Paths {
|
||||||
if mod.compiler != nil {
|
if mod.compiler != nil {
|
||||||
|
if !mod.compiler.nativeCoverage() {
|
||||||
|
return android.Paths{}
|
||||||
|
}
|
||||||
if library, ok := mod.compiler.(*libraryDecorator); ok {
|
if library, ok := mod.compiler.(*libraryDecorator); ok {
|
||||||
if library.coverageFile != nil {
|
if library.coverageFile != nil {
|
||||||
return android.Paths{library.coverageFile}
|
return android.Paths{library.coverageFile}
|
||||||
|
|
|
@ -21,14 +21,26 @@ import (
|
||||||
|
|
||||||
func GatherRequiredDepsForTest() string {
|
func GatherRequiredDepsForTest() string {
|
||||||
bp := `
|
bp := `
|
||||||
rust_prebuilt_dylib {
|
rust_prebuilt_library {
|
||||||
name: "libstd_x86_64-unknown-linux-gnu",
|
name: "libstd_x86_64-unknown-linux-gnu",
|
||||||
srcs: [""],
|
crate_name: "std",
|
||||||
|
rlib: {
|
||||||
|
srcs: ["libstd.rlib"],
|
||||||
|
},
|
||||||
|
dylib: {
|
||||||
|
srcs: ["libstd.so"],
|
||||||
|
},
|
||||||
host_supported: true,
|
host_supported: true,
|
||||||
}
|
}
|
||||||
rust_prebuilt_dylib {
|
rust_prebuilt_library {
|
||||||
name: "libtest_x86_64-unknown-linux-gnu",
|
name: "libtest_x86_64-unknown-linux-gnu",
|
||||||
srcs: [""],
|
crate_name: "test",
|
||||||
|
rlib: {
|
||||||
|
srcs: ["libtest.rlib"],
|
||||||
|
},
|
||||||
|
dylib: {
|
||||||
|
srcs: ["libtest.so"],
|
||||||
|
},
|
||||||
host_supported: true,
|
host_supported: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,34 +53,21 @@ func GatherRequiredDepsForTest() string {
|
||||||
nocrt: true,
|
nocrt: true,
|
||||||
system_shared_libs: [],
|
system_shared_libs: [],
|
||||||
}
|
}
|
||||||
rust_library_dylib {
|
rust_library {
|
||||||
name: "libstd",
|
name: "libstd",
|
||||||
crate_name: "std",
|
crate_name: "std",
|
||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
no_stdlibs: true,
|
no_stdlibs: true,
|
||||||
host_supported: true,
|
host_supported: true,
|
||||||
|
native_coverage: false,
|
||||||
}
|
}
|
||||||
rust_library_rlib {
|
rust_library {
|
||||||
name: "libstd.static",
|
|
||||||
crate_name: "std",
|
|
||||||
srcs: ["foo.rs"],
|
|
||||||
no_stdlibs: true,
|
|
||||||
host_supported: true,
|
|
||||||
}
|
|
||||||
rust_library_dylib {
|
|
||||||
name: "libtest",
|
name: "libtest",
|
||||||
crate_name: "test",
|
crate_name: "test",
|
||||||
srcs: ["foo.rs"],
|
srcs: ["foo.rs"],
|
||||||
no_stdlibs: true,
|
no_stdlibs: true,
|
||||||
host_supported: true,
|
host_supported: true,
|
||||||
|
native_coverage: false,
|
||||||
}
|
|
||||||
rust_library_rlib {
|
|
||||||
name: "libtest.static",
|
|
||||||
crate_name: "test",
|
|
||||||
srcs: ["foo.rs"],
|
|
||||||
no_stdlibs: true,
|
|
||||||
host_supported: true,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
` + cc.GatherRequiredDepsForTest(android.NoOsType)
|
` + cc.GatherRequiredDepsForTest(android.NoOsType)
|
||||||
|
@ -95,7 +94,9 @@ func CreateTestContext() *android.TestContext {
|
||||||
ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
|
ctx.RegisterModuleType("rust_ffi_host_shared", RustFFISharedHostFactory)
|
||||||
ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
|
ctx.RegisterModuleType("rust_ffi_host_static", RustFFIStaticHostFactory)
|
||||||
ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
|
ctx.RegisterModuleType("rust_proc_macro", ProcMacroFactory)
|
||||||
|
ctx.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
|
||||||
ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
ctx.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
||||||
|
ctx.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
|
||||||
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
|
||||||
// rust mutators
|
// rust mutators
|
||||||
ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
|
ctx.BottomUp("rust_libraries", LibraryMutator).Parallel()
|
||||||
|
|
Loading…
Reference in a new issue