Skip to content

Implement wasm proc-macros using wasmi#157709

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

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

Conversation

@bjorn3

@bjorn3 bjorn3 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 wasi 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

@rustbot rustbot 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 bjorn3 force-pushed the proc_macro_refactors5 branch from 7f2358a to 3572b0e Compare June 11, 2026 11:23
@rustbot rustbot 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 bjorn3 force-pushed the proc_macro_refactors5 branch from 3572b0e to 3f33572 Compare June 12, 2026 12:50
@rust-bors

This comment has been minimized.

@bjorn3 bjorn3 force-pushed the proc_macro_refactors5 branch from 3f33572 to 3f346c6 Compare June 22, 2026 09:06
@bjorn3 bjorn3 force-pushed the proc_macro_refactors5 branch 2 times, most recently from 45afede to 439c9eb Compare June 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 bjorn3 force-pushed the proc_macro_refactors5 branch from 439c9eb to eadf95b Compare June 23, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-tidy Area: The tidy tool S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants