Add wstd::main and wstd::test macros for WASIp3 - #149
Conversation
| use wstd::http::{Body, Client, Request, error::ErrorCode}; | ||
|
|
||
| #[wstd::main] | ||
| #[wstd::test] |
There was a problem hiding this comment.
A drive-by fix. This test wasn't actually running under cargo test because it used the main macro.
af9bae0 to
cabda1f
Compare
| 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, | ||
| }; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Based on #146
Addresses #148