-
-
Notifications
You must be signed in to change notification settings - Fork 29
Description
I made a cargo subcommand called cargo watt, which aims to improve the tooling listed in the README.
Currently, it does two things:
- Compile a proc-macro crate (locally, from git or from crates.io) and generate a crate which exposes the compiled wasm
- Verify that that wasm file was compiled from some source
Initially I wanted to replace
#[proc_macro]
pub fn the_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
/* ... */
}with
#[no_mangle]
pub extern "C" fn the_macro(input: proc_macro2::TokenStream) -> proc_macro2::TokenStream {
the_macro_inner(input.into().into()
}
pub fn the_macro_inner(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
/* ... */
}but that doesn't work because Into<proc_macro::TokenStream> does not exist in wasm.
So my solution was to just replace the TokenStreams and hope for the best, while also using a patched version of syn which basically just has all instances of proc_macro replaced with proc_macro2.
This actually works for quite a few crates (e.g. serde-derive, typed-builder, tracing-attributes) but it doesn't for some other ones (everything depending on synstructure and some others).
Now I am wondering:
Is it fundamentally impossible to provide the From-impls because proc-macro just doesn't exist in wasm, or would it be possible to do this transformation in some other way?