Reputation: 1955
When I run wasm-bindgen --out-dir out some_binary.wasm
wasm-bindgen is able to figure out which functions have been annotated with #[wasm_bindgen]
and to generate appropriate bindings for them so that they can be called from Javascript. How does this work? Is a special section of the WASM binary being used to hold this auxiliary information?
Upvotes: 3
Views: 278
Reputation: 1955
The answer to this question is in the Communicating types to wasm-bindgen section of the wasm-bindgen guide.
In a nutshell, the #[wasm_bindgen]
macro generates executable functions that describe the necessary bindings in Javascript inside some_binary.wasm
. These functions are then executed by the wasm-bindgen CLI program to generate the Javascript bindings and a stripped WebAssembly module, i.e., some_binary_bg.wasm
.
Upvotes: 1