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:
@@ -19,7 +19,9 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
android.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
|
||||
android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
||||
android.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
|
||||
}
|
||||
|
||||
type PrebuiltProperties struct {
|
||||
@@ -34,16 +36,47 @@ type prebuiltLibraryDecorator struct {
|
||||
|
||||
var _ compiler = (*prebuiltLibraryDecorator)(nil)
|
||||
|
||||
func PrebuiltLibraryFactory() android.Module {
|
||||
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
func PrebuiltDylibFactory() android.Module {
|
||||
module, _ := NewPrebuiltDylib(android.HostAndDeviceSupported)
|
||||
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) {
|
||||
module, library := NewRustLibrary(hod)
|
||||
library.BuildOnlyDylib()
|
||||
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{
|
||||
libraryDecorator: library,
|
||||
}
|
||||
@@ -57,7 +90,7 @@ func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -72,3 +105,15 @@ func (prebuilt *prebuiltLibraryDecorator) compilerDeps(ctx DepsContext, deps Dep
|
||||
func (prebuilt *prebuiltLibraryDecorator) nativeCoverage() bool {
|
||||
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
|
||||
}
|
||||
|
Reference in New Issue
Block a user