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_library", PrebuiltLibraryFactory)
|
||||||
android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
|
||||||
android.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
|
android.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
|
||||||
|
android.RegisterModuleType("rust_prebuilt_proc_macro", PrebuiltProcMacroFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PrebuiltProperties struct {
|
type PrebuiltProperties struct {
|
||||||
@@ -38,8 +39,42 @@ type prebuiltLibraryDecorator struct {
|
|||||||
Properties PrebuiltProperties
|
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 _ compiler = (*prebuiltLibraryDecorator)(nil)
|
||||||
var _ exportedFlagsProducer = (*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 {
|
func PrebuiltLibraryFactory() android.Module {
|
||||||
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
|
||||||
@@ -56,7 +91,7 @@ func PrebuiltRlibFactory() android.Module {
|
|||||||
return module.Init()
|
return module.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
func addSrcSupplier(module android.PrebuiltInterface, prebuilt *prebuiltLibraryDecorator) {
|
func addSrcSupplier(module android.PrebuiltInterface, prebuilt rustPrebuilt) {
|
||||||
srcsSupplier := func(_ android.BaseModuleContext, _ android.Module) []string {
|
srcsSupplier := func(_ android.BaseModuleContext, _ android.Module) []string {
|
||||||
return prebuilt.prebuiltSrcs()
|
return prebuilt.prebuiltSrcs()
|
||||||
}
|
}
|
||||||
@@ -152,3 +187,44 @@ func (prebuilt *prebuiltLibraryDecorator) prebuiltSrcs() []string {
|
|||||||
func (prebuilt *prebuiltLibraryDecorator) prebuilt() *android.Prebuilt {
|
func (prebuilt *prebuiltLibraryDecorator) prebuilt() *android.Prebuilt {
|
||||||
return &prebuilt.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
|
||||||
|
}
|
||||||
|
@@ -33,6 +33,7 @@ type procMacroDecorator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type procMacroInterface interface {
|
type procMacroInterface interface {
|
||||||
|
ProcMacro() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ compiler = (*procMacroDecorator)(nil)
|
var _ compiler = (*procMacroDecorator)(nil)
|
||||||
@@ -90,6 +91,10 @@ func (procMacro *procMacroDecorator) autoDep(ctx android.BottomUpMutatorContext)
|
|||||||
return rlibAutoDep
|
return rlibAutoDep
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (procMacro *procMacroDecorator) ProcMacro() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (procMacro *procMacroDecorator) everInstallable() bool {
|
func (procMacro *procMacroDecorator) everInstallable() bool {
|
||||||
// Proc_macros are never installed
|
// Proc_macros are never installed
|
||||||
return false
|
return false
|
||||||
|
20
rust/rust.go
20
rust/rust.go
@@ -27,6 +27,7 @@ import (
|
|||||||
cc_config "android/soong/cc/config"
|
cc_config "android/soong/cc/config"
|
||||||
"android/soong/fuzz"
|
"android/soong/fuzz"
|
||||||
"android/soong/rust/config"
|
"android/soong/rust/config"
|
||||||
|
"android/soong/snapshot"
|
||||||
)
|
)
|
||||||
|
|
||||||
var pctx = android.NewPackageContext("android/soong/rust")
|
var pctx = android.NewPackageContext("android/soong/rust")
|
||||||
@@ -806,6 +807,13 @@ func (mod *Module) Installable() *bool {
|
|||||||
return mod.Properties.Installable
|
return mod.Properties.Installable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mod *Module) ProcMacro() bool {
|
||||||
|
if pm, ok := mod.compiler.(procMacroInterface); ok {
|
||||||
|
return pm.ProcMacro()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
|
func (mod *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
|
||||||
if mod.cachedToolchain == nil {
|
if mod.cachedToolchain == nil {
|
||||||
mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
|
mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
|
||||||
@@ -920,12 +928,13 @@ func (mod *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
|
||||||
if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) {
|
if !proptools.BoolDefault(mod.Installable(), mod.EverInstallable()) && !mod.ProcMacro() {
|
||||||
// If the module has been specifically configure to not be installed then
|
// If the module has been specifically configure to not be installed then
|
||||||
// hide from make as otherwise it will break when running inside make as the
|
// hide from make as otherwise it will break when running inside make as the
|
||||||
// output path to install will not be specified. Not all uninstallable
|
// output path to install will not be specified. Not all uninstallable
|
||||||
// modules can be hidden from make as some are needed for resolving make
|
// modules can be hidden from make as some are needed for resolving make
|
||||||
// side dependencies.
|
// side dependencies. In particular, proc-macros need to be captured in the
|
||||||
|
// host snapshot.
|
||||||
mod.HideFromMake()
|
mod.HideFromMake()
|
||||||
} else if !mod.installable(apexInfo) {
|
} else if !mod.installable(apexInfo) {
|
||||||
mod.SkipInstall()
|
mod.SkipInstall()
|
||||||
@@ -1046,7 +1055,7 @@ func (mod *Module) begin(ctx BaseModuleContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mod *Module) Prebuilt() *android.Prebuilt {
|
func (mod *Module) Prebuilt() *android.Prebuilt {
|
||||||
if p, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
|
if p, ok := mod.compiler.(rustPrebuilt); ok {
|
||||||
return p.prebuilt()
|
return p.prebuilt()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -1501,6 +1510,7 @@ func (mod *Module) disableClippy() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var _ android.HostToolProvider = (*Module)(nil)
|
var _ android.HostToolProvider = (*Module)(nil)
|
||||||
|
var _ snapshot.RelativeInstallPath = (*Module)(nil)
|
||||||
|
|
||||||
func (mod *Module) HostToolPath() android.OptionalPath {
|
func (mod *Module) HostToolPath() android.OptionalPath {
|
||||||
if !mod.Host() {
|
if !mod.Host() {
|
||||||
@@ -1508,6 +1518,10 @@ func (mod *Module) HostToolPath() android.OptionalPath {
|
|||||||
}
|
}
|
||||||
if binary, ok := mod.compiler.(*binaryDecorator); ok {
|
if binary, ok := mod.compiler.(*binaryDecorator); ok {
|
||||||
return android.OptionalPathForPath(binary.baseCompiler.path)
|
return android.OptionalPathForPath(binary.baseCompiler.path)
|
||||||
|
} else if pm, ok := mod.compiler.(*procMacroDecorator); ok {
|
||||||
|
// Even though proc-macros aren't strictly "tools", since they target the compiler
|
||||||
|
// and act as compiler plugins, we treat them similarly.
|
||||||
|
return android.OptionalPathForPath(pm.baseCompiler.path)
|
||||||
}
|
}
|
||||||
return android.OptionalPath{}
|
return android.OptionalPath{}
|
||||||
}
|
}
|
||||||
|
@@ -114,13 +114,13 @@ func (c *hostFakeSingleton) GenerateBuildActions(ctx android.SingletonContext) {
|
|||||||
if !apexInfo.IsForPlatform() {
|
if !apexInfo.IsForPlatform() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
path := hostBinToolPath(module)
|
path := hostToolPath(module)
|
||||||
if path.Valid() && path.String() != "" {
|
if path.Valid() && path.String() != "" {
|
||||||
outFile := filepath.Join(c.snapshotDir, path.String())
|
outFile := filepath.Join(c.snapshotDir, path.String())
|
||||||
if !seen[outFile] {
|
if !seen[outFile] {
|
||||||
seen[outFile] = true
|
seen[outFile] = true
|
||||||
outputs = append(outputs, WriteStringToFileRule(ctx, "", outFile))
|
outputs = append(outputs, WriteStringToFileRule(ctx, "", outFile))
|
||||||
jsonData = append(jsonData, *hostBinJsonDesc(module))
|
jsonData = append(jsonData, *hostJsonDesc(module))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@@ -19,6 +19,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
@@ -62,6 +63,11 @@ type hostSnapshot struct {
|
|||||||
installDir android.InstallPath
|
installDir android.InstallPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ProcMacro interface {
|
||||||
|
ProcMacro() bool
|
||||||
|
CrateName() string
|
||||||
|
}
|
||||||
|
|
||||||
func hostSnapshotFactory() android.Module {
|
func hostSnapshotFactory() android.Module {
|
||||||
module := &hostSnapshot{}
|
module := &hostSnapshot{}
|
||||||
initHostToolsModule(module)
|
initHostToolsModule(module)
|
||||||
@@ -94,7 +100,7 @@ func (f *hostSnapshot) CreateMetaData(ctx android.ModuleContext, fileName string
|
|||||||
|
|
||||||
// Create JSON file based on the direct dependencies
|
// Create JSON file based on the direct dependencies
|
||||||
ctx.VisitDirectDeps(func(dep android.Module) {
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
||||||
desc := hostBinJsonDesc(dep)
|
desc := hostJsonDesc(dep)
|
||||||
if desc != nil {
|
if desc != nil {
|
||||||
jsonData = append(jsonData, *desc)
|
jsonData = append(jsonData, *desc)
|
||||||
}
|
}
|
||||||
@@ -183,7 +189,7 @@ func (f *hostSnapshot) AndroidMkEntries() []android.AndroidMkEntries {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get host tools path and relative install string helpers
|
// Get host tools path and relative install string helpers
|
||||||
func hostBinToolPath(m android.Module) android.OptionalPath {
|
func hostToolPath(m android.Module) android.OptionalPath {
|
||||||
if provider, ok := m.(android.HostToolProvider); ok {
|
if provider, ok := m.(android.HostToolProvider); ok {
|
||||||
return provider.HostToolPath()
|
return provider.HostToolPath()
|
||||||
}
|
}
|
||||||
@@ -198,18 +204,30 @@ func hostRelativePathString(m android.Module) string {
|
|||||||
return outString
|
return outString
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create JSON description for given module, only create descriptions for binary modueles which
|
// Create JSON description for given module, only create descriptions for binary modules
|
||||||
// provide a valid HostToolPath
|
// and rust_proc_macro modules which provide a valid HostToolPath
|
||||||
func hostBinJsonDesc(m android.Module) *SnapshotJsonFlags {
|
func hostJsonDesc(m android.Module) *SnapshotJsonFlags {
|
||||||
path := hostBinToolPath(m)
|
path := hostToolPath(m)
|
||||||
relPath := hostRelativePathString(m)
|
relPath := hostRelativePathString(m)
|
||||||
|
procMacro := false
|
||||||
|
moduleStem := filepath.Base(path.String())
|
||||||
|
crateName := ""
|
||||||
|
|
||||||
|
if pm, ok := m.(ProcMacro); ok && pm.ProcMacro() {
|
||||||
|
procMacro = pm.ProcMacro()
|
||||||
|
moduleStem = strings.TrimSuffix(moduleStem, filepath.Ext(moduleStem))
|
||||||
|
crateName = pm.CrateName()
|
||||||
|
}
|
||||||
|
|
||||||
if path.Valid() && path.String() != "" {
|
if path.Valid() && path.String() != "" {
|
||||||
return &SnapshotJsonFlags{
|
return &SnapshotJsonFlags{
|
||||||
ModuleName: m.Name(),
|
ModuleName: m.Name(),
|
||||||
ModuleStemName: filepath.Base(path.String()),
|
ModuleStemName: moduleStem,
|
||||||
Filename: path.String(),
|
Filename: path.String(),
|
||||||
Required: append(m.HostRequiredModuleNames(), m.RequiredModuleNames()...),
|
Required: append(m.HostRequiredModuleNames(), m.RequiredModuleNames()...),
|
||||||
RelativeInstallPath: relPath,
|
RelativeInstallPath: relPath,
|
||||||
|
RustProcMacro: procMacro,
|
||||||
|
CrateName: crateName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@@ -114,6 +114,8 @@ type SnapshotJsonFlags struct {
|
|||||||
RelativeInstallPath string `json:",omitempty"`
|
RelativeInstallPath string `json:",omitempty"`
|
||||||
Filename string `json:",omitempty"`
|
Filename string `json:",omitempty"`
|
||||||
ModuleStemName string `json:",omitempty"`
|
ModuleStemName string `json:",omitempty"`
|
||||||
|
RustProcMacro bool `json:",omitempty"`
|
||||||
|
CrateName string `json:",omitempty"`
|
||||||
|
|
||||||
// dependencies
|
// dependencies
|
||||||
Required []string `json:",omitempty"`
|
Required []string `json:",omitempty"`
|
||||||
|
Reference in New Issue
Block a user