Skip to content

Partially support building and locating wasm proc-macros - #160981

Open
bjorn3 wants to merge 2 commits into
rust-lang:mainfrom
bjorn3:proc_macro_refactors7
Open

Partially support building and locating wasm proc-macros#160981
bjorn3 wants to merge 2 commits into
rust-lang:mainfrom
bjorn3:proc_macro_refactors7

Conversation

@bjorn3

@bjorn3 bjorn3 commented Aug 12, 2026

Copy link
Copy Markdown
Member

For building this currently only removes the crate type check and doesn't implement crate metadata support for wasip2 or the proc-macro ABI. And for locating wasip2 needs support for loading crate metadata. Crate metadata building and loading should work for wasip1.

Part of #160389

r? @Mark-Simulacrum

@rustbot

rustbot commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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. labels Aug 12, 2026
Comment thread compiler/rustc_session/src/session.rs Outdated
@bjorn3

bjorn3 commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

These changes are based on my wasip1 PR and I have rebased that PR on top of this. It should work just fine for wasip2 too though.

Comment thread compiler/rustc_session/src/session.rs Outdated
// In this case, the only path we can pass
// with '--extern-meta' is the '.rlib' file
AuxType::Lib => Some(format!("lib{name}.rlib")),
// FIXME maybe use `rustc --print file-names` instead?

@Mark-Simulacrum Mark-Simulacrum Aug 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably applies to the full match/function, not just this line, right?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, although for rlibs using the hard coded lib{name}.rlib would be fine on all targets,

&self,
crate_rejections: &mut CrateRejections,
) -> Result<Option<Library>, CrateError> {
debug!("find_commandline_library {}", self.crate_name);

@Mark-Simulacrum Mark-Simulacrum Aug 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need support here for finding .wasm?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is indirectly called by CStore::load_proc_macro. This function first tries to load for the host by calling locator.for_proc_macro() before calling CStore::load on it, and then for the wasm target by calling locator.for_wasm_proc_macro() before CStore::load. For the second call, the for_wasm_proc_macro causes the locator to attempt to load a crate for wasm32-wasip2. This in turn causes the locator to use the .wasm suffix for dylibs as indicated in the target spec.

@bjorn3
bjorn3 force-pushed the proc_macro_refactors7 branch from b97e027 to 63c5ce6 Compare August 12, 2026 13:22
@bjorn3

bjorn3 commented Aug 13, 2026

Copy link
Copy Markdown
Member Author

I've added --print wasm-proc-macro-tuple as preparation for future cargo support for -Zwasm-proc-macros.

@rust-log-analyzer

This comment has been minimized.

@bjorn3
bjorn3 force-pushed the proc_macro_refactors7 branch from fc1faeb to a63ba48 Compare August 13, 2026 09:54
@rust-log-analyzer

This comment has been minimized.

@bjorn3
bjorn3 force-pushed the proc_macro_refactors7 branch from a63ba48 to 00a1d38 Compare August 13, 2026 11:02
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Aug 13, 2026
bjorn3 added 2 commits August 13, 2026 15:47
For building this currently only removes the crate type check and
doesn't implement crate metadata support for wasip2 or the proc-macro
ABI. And for locating wasip2 needs support for loading crate metadata.
Crate metadata building and loading should work for wasip1.
This can be used by cargo to determine the target for which wasm
proc-macros should be compiled.
@bjorn3
bjorn3 force-pushed the proc_macro_refactors7 branch from 00a1d38 to f2abd0e Compare August 13, 2026 13:52
@rustbot

rustbot commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

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

Labels

A-compiletest Area: The compiletest test runner A-run-make Area: port run-make Makefiles to rmake.rs A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants