Stream: wit-bindgen

Topic: Modify the output of the bindgen! macro


view this post on Zulip Karel Hrkal (kajacx) (Jul 05 2023 at 15:28):

Hello, I am working on wasm-bridge, a project to "make wasmtime work on the web". I am currently looking into a way to add component model support.

When I invoke the wasm_bridge::component::bindgen! macro, the generated code uses the wasmtime crate. I was wondering if it would be possible to write my own proc macro, call the original bindgen macro with the same TokenStream input, and modify it's output.

Something like this:

#[proc_macro]
pub fn my_bindgen(stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let stream = wasmtime_component_macro::bindgen(stream);

    // Modify the stream
    eprintln!("{stream:?}");

    stream
}

But this gives a syntax error: expected function, found macro wasmtime_component_macro::bindgen

Is it even possible to call a proc macro like a normal function with TokenStream, or do I need to do something else?

Proves a single unified API to run WASM modules on the dektop using wasmtime, or on the web using js-sys. - GitHub - kajacx/wasm-bridge: Proves a single unified API to run WASM modules on the dekto...

Last updated: Oct 23 2024 at 20:03 UTC