Is it possible to create a .wit file from a wasm component file rather than the typical approach of using .wit file to generate the code with wit-bindgen?
For example:
#[derive(Command)] // This derive macro would export to a `record add { amount: i64 }`
pub struct Add {
amount: i64,
}
#[command]
impl Handler<Add> for Counter {
type Result = Added;
fn handle(&self, cmd: Add) -> Self::Result { ... }
}
// This function is generated from the `#[command]` attribute macro above,
// and exports to a `handle_add: func(state: Counter, cmd: Add) -> Added`
pub extern "c" fn handle_add(state: Counter, cmd: Add) -> (Added) {
<Counter as Handler<Add>>::handle(&state, cmd)
}
And from this code, I can compile it to a wasm component, and extract these exported functions from a host loading the component?
Take a look at the wasm-tools component wit
subcommand, e.g. wit-tools component wit your-component.wasm
typo: wit-tools
-> wasm-tools
Currently there's no implementation of going from Rust source code annotations directly to a component without WIT. As Lann mentioned you can extract WIT from a component, but given your snippet that doesn't sound like the direction you'd like to go in (instead a more #[wasm_bindgen]
-like-approach where you annotate Rust and a component gets generated)
Last updated: Dec 23 2024 at 13:07 UTC