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
diff --git a/rust/rust.go b/rust/rust.go
index 1c718a4..d627261 100644
--- a/rust/rust.go
+++ b/rust/rust.go
@@ -27,6 +27,7 @@
cc_config "android/soong/cc/config"
"android/soong/fuzz"
"android/soong/rust/config"
+ "android/soong/snapshot"
)
var pctx = android.NewPackageContext("android/soong/rust")
@@ -806,6 +807,13 @@
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 {
if mod.cachedToolchain == nil {
mod.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
@@ -920,12 +928,13 @@
}
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
// 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
// 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()
} else if !mod.installable(apexInfo) {
mod.SkipInstall()
@@ -1046,7 +1055,7 @@
}
func (mod *Module) Prebuilt() *android.Prebuilt {
- if p, ok := mod.compiler.(*prebuiltLibraryDecorator); ok {
+ if p, ok := mod.compiler.(rustPrebuilt); ok {
return p.prebuilt()
}
return nil
@@ -1501,6 +1510,7 @@
}
var _ android.HostToolProvider = (*Module)(nil)
+var _ snapshot.RelativeInstallPath = (*Module)(nil)
func (mod *Module) HostToolPath() android.OptionalPath {
if !mod.Host() {
@@ -1508,6 +1518,10 @@
}
if binary, ok := mod.compiler.(*binaryDecorator); ok {
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{}
}