You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This does require that wasm execution support is present on all targets rustc itself wants to support compiling to.
Enable sound(er) caching of proc macros. Today rust-analyzer assumes that macro outputs don't change (never re-running them) and rustc has a flag to do the same (-Zcache-proc-macros). Since we'll now tightly control what the macro has access to, it should be much easier to enable incremental caching by "default". To start this would be limited to users who are willing to opt-in somehow -- some macros intentionally need external access to file system or network paths, and we'd need users to have a wasm toolchain on hand -- but for simple cases this should be a win.
Improve macro determinism. Today it's easy for authors of macros to depending on platform randomness (e.g., via hashmap iteration order), which results in non-deterministic builds. This hurts reproducible builds and causes decreases in cache hit rates in build systems reliant on identical outputs (e.g., Buck) as a result. Wasm makes it much easier to control what randomness (or other non-deterministic inputs) macros have access to because we act as a ~kernel for the running program.
Non-goals:
Make any security guarantees. rustc continues to assume trusted input; there's no attempt to make guarantees around sandboxing or making it otherwise safe to compile untrusted code.
Design interface for opt-in/out / stability guarantees on what interfaces are accessible.
Implementation plan
We are aiming to use wasmtime for execution (though may start on wasmi if we run into issues). The maintainers are happy to work with us on any features / gaps that we need from our early discussion at the 2026 all hands (rust-lang/all-hands-2026#73).
WASI is the intended target family. This avoids a bespoke macro target for basic functionality to work (e.g., println!), and in general should allow more code to 'just work' if/when we want to allow it (e.g., network or filesystem access) without necessarily needing special case interfaces (e.g., like proc_macro::tracked). This also lets us dogfood the component model to help make sure that users have a good experience on wasi targets.
We have two draft PRs that share some common bits up right now (wasip1 on wasmi and wasip2 on wasmtime). @bjorn3 and @Mark-Simulacrum have discussed and we're aligned on landing the common/shared code first -- compiletest support, rustc flags, crate loading changes. Once that lands we'll figure out whether to go ahead with wasmtime or wasmi depending on what blockers we hit (or don't hit) with wasmtime. As of writing for this MCP it looks like wasmtime should support all targets in its interpreter mode, but we'll validate this. We're also looking at whether we can reduce the duplication of ABI surface area for macros. In general though we're expecting that edits to the proc macro implementation (e.g. adding new host-exposed ABI) shouldn't really need to know about wasm support to implement functionality regardless of approach. If we run into concerns we may land some of the implementation behind #[cfg] to allow iterating without maintaining an out of tree patch set, but we're hoping to avoid this.
What are we approving in this MCP?
The above should be mostly considered background. At a high level this is just approving landing unstable support for wasm proc macros. This was technically almost approved in the past (#475 and with concerns addressed here in #876), but since those were a while back we're cutting a new MCP before we land any work into the compiler tree.
Proposal
Summary
This proposes adding support for proc macros in wasm code natively in rustc. The current goals, though with somewhat indeterminate timeline, are:
-Zcache-proc-macros). Since we'll now tightly control what the macro has access to, it should be much easier to enable incremental caching by "default". To start this would be limited to users who are willing to opt-in somehow -- some macros intentionally need external access to file system or network paths, and we'd need users to have a wasm toolchain on hand -- but for simple cases this should be a win.Non-goals:
Implementation plan
We are aiming to use wasmtime for execution (though may start on wasmi if we run into issues). The maintainers are happy to work with us on any features / gaps that we need from our early discussion at the 2026 all hands (rust-lang/all-hands-2026#73).
WASI is the intended target family. This avoids a bespoke macro target for basic functionality to work (e.g.,
println!), and in general should allow more code to 'just work' if/when we want to allow it (e.g., network or filesystem access) without necessarily needing special case interfaces (e.g., likeproc_macro::tracked). This also lets us dogfood the component model to help make sure that users have a good experience on wasi targets.We have two draft PRs that share some common bits up right now (wasip1 on wasmi and wasip2 on wasmtime). @bjorn3 and @Mark-Simulacrum have discussed and we're aligned on landing the common/shared code first -- compiletest support, rustc flags, crate loading changes. Once that lands we'll figure out whether to go ahead with wasmtime or wasmi depending on what blockers we hit (or don't hit) with wasmtime. As of writing for this MCP it looks like wasmtime should support all targets in its interpreter mode, but we'll validate this. We're also looking at whether we can reduce the duplication of ABI surface area for macros. In general though we're expecting that edits to the proc macro implementation (e.g. adding new host-exposed ABI) shouldn't really need to know about wasm support to implement functionality regardless of approach. If we run into concerns we may land some of the implementation behind #[cfg] to allow iterating without maintaining an out of tree patch set, but we're hoping to avoid this.
What are we approving in this MCP?
The above should be mostly considered background. At a high level this is just approving landing unstable support for wasm proc macros. This was technically almost approved in the past (#475 and with concerns addressed here in #876), but since those were a while back we're cutting a new MCP before we land any work into the compiler tree.
Mentors or Reviewers
@bjorn3 / @Mark-Simulacrum will be jointly reviewing/implementing the work.
Process
The main points of the Major Change Process are as follows:
@rustbot secondor kickoff a team FCP with@rfcbot fcp $RESOLUTION.You can read more about Major Change Proposals on forge.