Skip to content

Add wstd::main and wstd::test macros for WASIp3 - #149

Open
adamrk wants to merge 31 commits into
bytecodealliance:mainfrom
adamrk:abk/main-macro-for-wasip3
Open

Add wstd::main and wstd::test macros for WASIp3#149
adamrk wants to merge 31 commits into
bytecodealliance:mainfrom
adamrk:abk/main-macro-for-wasip3

Conversation

@adamrk

@adamrk adamrk commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Based on #146

Addresses #148

use wstd::http::{Body, Client, Request, error::ErrorCode};

#[wstd::main]
#[wstd::test]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A drive-by fix. This test wasn't actually running under cargo test because it used the main macro.

@adamrk
adamrk force-pushed the abk/main-macro-for-wasip3 branch from af9bae0 to cabda1f Compare September 3, 2026 14:25
Comment thread .cargo/config.toml Outdated
Comment thread macro/src/lib.rs Outdated
Comment thread src/lib.rs Outdated
pub use wstd_macro::attr_macro_test as test;
pub use wstd_macro::{
attr_macro_http_server as http_server, attr_macro_main as main, attr_macro_test as test,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just went to review this PR again and I think the changes to the macro actually got lost somehow in the fixing the base branch chaos? Theres no longer a diff on the macro crate in this PR and the cfg here on the pub use wstd_macro bits has gone missing as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I should have commented on that:
The previous setup of explicitly exporting the cli::run interface and having an unreachable main doesn't work with the p3 target because the two mains conflict (as you noted). So instead I just implemented block_on in p3 so that the existing macro works for both. What it produces on p3 is a little different than before in that in now generates a sync lifted main instead of an async one, but I believe the only difference there is that the instance now can't be reentered when it suspends.

An alternative would be to keep the previous version of the macro without it defining main and require users not add #![no_main] whenever they use it. I think that wouldn't be as nice from a user perspective.

@alexcrichton also mentioned there's likely a way we could add logic to wit-bindgen and wit-component-ld to annotate the main as a "low priority" symbol which would allow exporting an async cli::run explicitly with an unreachable main as before so that wit-component-ld can pick the right one when it sees the conflict during linking. This would let us get back to the async lifted main later on.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants