Skip to content

Implement wasm proc-macros using wasmi - #157709

Draft
bjorn3 wants to merge 5 commits into
rust-lang:mainfrom
bjorn3:proc_macro_refactors5
Draft

Implement wasm proc-macros using wasmi#157709
bjorn3 wants to merge 5 commits into
rust-lang:mainfrom
bjorn3:proc_macro_refactors5

Conversation

@bjorn3

@bjorn3bjorn3 commented Jun 10, 2026

Copy link
Copy Markdown
Member

This is an alternative approach to rust-lang/all-hands-2026#73. Unlike #157590 this uses wasmi + wasm32-wasip1. The advantage of this that it allows us to unconditionally depend on support for wasm proc-macros, allowing us to use them instead of the -Zdual-proc-macro hack as well as using proc-macros in the standard library without breaking cross-compilation. And by removing the last commit this can even use wasm32-unknown-unknown to avoid depending on wasi-sdk (which currently has a bootstrap cycle with rustc and thus might not be a great dependency to have for building rustc as it makes the lives of distros harder)

Once wasmtime supports all architectures for which we support host tools, swapping wasmi for wasmtime is trivial. After that at a future point we can switch to the component model to allow using wasm32-wasip2 once we deem the advantages of this to outweigh the code duplication cost for the extra proc-macro ABI, extra code for handling the crate metadata for wasm components and the hack necessary to get wit-bindgen to work within the context of libproc_macro. This PR should not make this harder, while allowing us to get (some of) the benefits of wasm proc-macros earlier.

cc @Mark-Simulacrum@alexcrichton

@rustbotrustbot added A-meta Area: Issues & PRs about the rust-lang/rust repository itself S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. labels Jun 10, 2026
@rust-log-analyzer

This comment has been minimized.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from 7f2358a to 3572b0eCompareJune 11, 2026 11:23
@rustbotrustbot added A-tidy Area: The tidy tool T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jun 11, 2026
@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from 3572b0e to 3f33572CompareJune 12, 2026 12:50
@rust-bors

This comment has been minimized.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from 3f33572 to 3f346c6CompareJune 22, 2026 09:06
@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch 2 times, most recently from 45afede to 439c9ebCompareJune 22, 2026 14:21
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 22, 2026
…=Mark-Simulacrum
Fix linking for wasm with crate metadata included
On wasm the crate metadata ends up in a custom section. It is not possible to refer to create symbols inside a custom section, so attempting to export it during linking will result in a linker error. This keeps the target spec flag to deny compiling rust dylibs for wasm, but may theoretically allow compiling wasm rust dylibs with a custom target spec. It will help with wasm proc-macros. And in the future we can try to flip the only-cdylib option to false on wasm.
Extracted out of rust-lang#157709, but also helps with rust-lang#157590.
r? @Mark-Simulacrum
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 22, 2026
…=Mark-Simulacrum
Fix linking for wasm with crate metadata included
On wasm the crate metadata ends up in a custom section. It is not possible to refer to create symbols inside a custom section, so attempting to export it during linking will result in a linker error. This keeps the target spec flag to deny compiling rust dylibs for wasm, but may theoretically allow compiling wasm rust dylibs with a custom target spec. It will help with wasm proc-macros. And in the future we can try to flip the only-cdylib option to false on wasm.
Extracted out of rust-lang#157709, but also helps with rust-lang#157590.
r? @Mark-Simulacrum
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 22, 2026
…=Mark-Simulacrum
Fix linking for wasm with crate metadata included
On wasm the crate metadata ends up in a custom section. It is not possible to refer to create symbols inside a custom section, so attempting to export it during linking will result in a linker error. This keeps the target spec flag to deny compiling rust dylibs for wasm, but may theoretically allow compiling wasm rust dylibs with a custom target spec. It will help with wasm proc-macros. And in the future we can try to flip the only-cdylib option to false on wasm.
Extracted out of rust-lang#157709, but also helps with rust-lang#157590.
r? @Mark-Simulacrum
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 22, 2026
…=Mark-Simulacrum
Fix linking for wasm with crate metadata included
On wasm the crate metadata ends up in a custom section. It is not possible to refer to create symbols inside a custom section, so attempting to export it during linking will result in a linker error. This keeps the target spec flag to deny compiling rust dylibs for wasm, but may theoretically allow compiling wasm rust dylibs with a custom target spec. It will help with wasm proc-macros. And in the future we can try to flip the only-cdylib option to false on wasm.
Extracted out of rust-lang#157709, but also helps with rust-lang#157590.
r? @Mark-Simulacrum
rust-timer added a commit that referenced this pull request Jun 22, 2026
Rollup merge of #158242 - bjorn3:wasm_rust_dylib_metadata, r=Mark-Simulacrum
Fix linking for wasm with crate metadata included
On wasm the crate metadata ends up in a custom section. It is not possible to refer to create symbols inside a custom section, so attempting to export it during linking will result in a linker error. This keeps the target spec flag to deny compiling rust dylibs for wasm, but may theoretically allow compiling wasm rust dylibs with a custom target spec. It will help with wasm proc-macros. And in the future we can try to flip the only-cdylib option to false on wasm.
Extracted out of #157709, but also helps with #157590.
r? @Mark-Simulacrum
@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch 2 times, most recently from eadf95b to 1c04273CompareJune 25, 2026 09:41
@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from 1c04273 to 4c6ae5aCompareJune 30, 2026 12:38
@rust-bors

This comment has been minimized.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from 4c6ae5a to fb5a3f2CompareJuly 1, 2026 11:23
@rust-bors

This comment has been minimized.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch 2 times, most recently from 528e86a to 279919dCompareJuly 2, 2026 09:22
@rust-bors

This comment has been minimized.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from 279919d to 14b2d8aCompareJuly 9, 2026 11:45
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from 4258ad0 to 1cf1d47CompareAugust 10, 2026 14:40
@rust-bors

This comment has been minimized.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from 1cf1d47 to 3a2ce85CompareAugust 12, 2026 10:00
@rustbotrustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc labels Aug 12, 2026
@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch 2 times, most recently from 5608fe2 to 15ca38aCompareAugust 12, 2026 10:17
@bjorn3

Copy link
Copy Markdown
MemberAuthor

All proc-macro tests that don't involve panicking seem to work with the exception of two proc-macro that have an auxiliary dependency, where compiletest builds it for the host rather than wasm target.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch 3 times, most recently from 38786f8 to 17873afCompareAugust 12, 2026 13:32
@rust-bors

This comment has been minimized.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from 17873af to 25004b4CompareAugust 13, 2026 13:53
@rustbotrustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Aug 13, 2026
@rust-bors

This comment has been minimized.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from 25004b4 to fba9db7CompareAugust 17, 2026 15:11
@rust-bors

This comment has been minimized.

@bjorn3
bjorn3force-pushed the proc_macro_refactors5 branch from fba9db7 to 9c9a8d7CompareAugust 21, 2026 09:36
@rust-bors

rust-borsBot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiletestArea: The compiletest test runnerA-metaArea: Issues & PRs about the rust-lang/rust repository itselfA-run-makeArea: port run-make Makefiles to rmake.rsA-testsuiteArea: The testsuite used to check the correctness of rustcA-tidyArea: The tidy toolS-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-rust-analyzerRelevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@bjorn3@rust-log-analyzer@rustbot