rust: rust_proc_macro host snapshot support.
Adds support for capturing rust_proc_macros as part of the host snapshot. Proc macros target the host and can be thought of as compiler plugins. Because of this, they don't have vendor image variants and can't be easily captured as part of the vendor snapshot. Instead we capture them as part of the host snapshot. This adds a rust_prebuilt_proc_macro module type. Bug: 204304380 Test: m HOST_FAKE_SNAPSHOT_ENABLE=true host-fake-snapshot dist Test: python3 development/vendor_snapshot/update.py --image=host --install-dir=vendor/vendor_name/ 31 --local out/dist Test: Checked Android.bp for rust_prebuilt_proc_macro modules. Change-Id: I4a8c4d9c41b7ca361b5b97d3f74973918c2a5fe3
This commit is contained in:
@@ -22,6 +22,7 @@ func init() {
|
||||
android.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
|
||||
android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
||||
android.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
|
||||
android.RegisterModuleType("rust_prebuilt_proc_macro", PrebuiltProcMacroFactory)
|
||||
}
|
||||
|
||||
type PrebuiltProperties struct {
|
||||
@@ -38,8 +39,42 @@ type prebuiltLibraryDecorator struct {
|
||||
Properties PrebuiltProperties
|
||||
}
|
||||
|
||||
type prebuiltProcMacroDecorator struct {
|
||||
android.Prebuilt
|
||||
|
||||
*procMacroDecorator
|
||||
Properties PrebuiltProperties
|
||||
}
|
||||
|
||||
func PrebuiltProcMacroFactory() android.Module {
|
||||
module, _ := NewPrebuiltProcMacro(android.HostSupportedNoCross)
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
type rustPrebuilt interface {
|
||||
prebuiltSrcs() []string
|
||||
prebuilt() *android.Prebuilt
|
||||
}
|
||||
|
||||
func NewPrebuiltProcMacro(hod android.HostOrDeviceSupported) (*Module, *prebuiltProcMacroDecorator) {
|
||||
module, library := NewProcMacro(hod)
|
||||
prebuilt := &prebuiltProcMacroDecorator{
|
||||
procMacroDecorator: library,
|
||||
}
|
||||
module.compiler = prebuilt
|
||||
|
||||
addSrcSupplier(module, prebuilt)
|
||||
|
||||
return module, prebuilt
|
||||
}
|
||||
|
||||
var _ compiler = (*prebuiltLibraryDecorator)(nil)
|
||||
var _ exportedFlagsProducer = (*prebuiltLibraryDecorator)(nil)
|
||||
var _ rustPrebuilt = (*prebuiltLibraryDecorator)(nil)
|
||||
|
||||
var _ compiler = (*prebuiltProcMacroDecorator)(nil)
|
||||
var _ exportedFlagsProducer = (*prebuiltProcMacroDecorator)(nil)
|
||||
var _ rustPrebuilt = (*prebuiltProcMacroDecorator)(nil)
|
||||
|
||||
func PrebuiltLibraryFactory() android.Module {
|
||||
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
||||
@@ -56,7 +91,7 @@ func PrebuiltRlibFactory() android.Module {
|
||||
return module.Init()
|
||||
}
|
||||
|
||||
func addSrcSupplier(module android.PrebuiltInterface, prebuilt *prebuiltLibraryDecorator) {
|
||||
func addSrcSupplier(module android.PrebuiltInterface, prebuilt rustPrebuilt) {
|
||||
srcsSupplier := func(_ android.BaseModuleContext, _ android.Module) []string {
|
||||
return prebuilt.prebuiltSrcs()
|
||||
}
|
||||
@@ -152,3 +187,44 @@ func (prebuilt *prebuiltLibraryDecorator) prebuiltSrcs() []string {
|
||||
func (prebuilt *prebuiltLibraryDecorator) prebuilt() *android.Prebuilt {
|
||||
return &prebuilt.Prebuilt
|
||||
}
|
||||
|
||||
func (prebuilt *prebuiltProcMacroDecorator) prebuiltSrcs() []string {
|
||||
srcs := prebuilt.Properties.Srcs
|
||||
return srcs
|
||||
}
|
||||
|
||||
func (prebuilt *prebuiltProcMacroDecorator) prebuilt() *android.Prebuilt {
|
||||
return &prebuilt.Prebuilt
|
||||
}
|
||||
|
||||
func (prebuilt *prebuiltProcMacroDecorator) compilerProps() []interface{} {
|
||||
return append(prebuilt.procMacroDecorator.compilerProps(),
|
||||
&prebuilt.Properties)
|
||||
}
|
||||
|
||||
func (prebuilt *prebuiltProcMacroDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
|
||||
prebuilt.flagExporter.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...)
|
||||
prebuilt.flagExporter.setProvider(ctx)
|
||||
|
||||
srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
|
||||
if len(paths) > 0 {
|
||||
ctx.PropertyErrorf("srcs", "prebuilt libraries can only have one entry in srcs (the prebuilt path)")
|
||||
}
|
||||
prebuilt.baseCompiler.unstrippedOutputFile = srcPath
|
||||
return srcPath
|
||||
}
|
||||
|
||||
func (prebuilt *prebuiltProcMacroDecorator) rustdoc(ctx ModuleContext, flags Flags,
|
||||
deps PathDeps) android.OptionalPath {
|
||||
|
||||
return android.OptionalPath{}
|
||||
}
|
||||
|
||||
func (prebuilt *prebuiltProcMacroDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
|
||||
deps = prebuilt.baseCompiler.compilerDeps(ctx, deps)
|
||||
return deps
|
||||
}
|
||||
|
||||
func (prebuilt *prebuiltProcMacroDecorator) nativeCoverage() bool {
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user