looking at the docs for setting up a host environemt all the functions are loaded via a test search for the name and input + output values are dynamic and must be known when invoking the function signature
Example from GCD C++ code
// Invoke `gcd` export
auto gcd = std::get<Func>(*instance.get(store, "gcd"));
auto results = gcd.call(store, {6, 27}).unwrap();
std::cout << "gcd(6, 27) = " << results[0].i32() << "\n";
is it possible given a wasm componet file (or even a top level WIT file) to auto generate all the binding code and wrap it as a C++ object / struct / free functions
something along the lines of
$ {magic-wasmtime-tool} cpp gcd.wit
and have it produce a file along the lines of
class gcd_module {
public:
// validate the loaded WASM file matches all the functions + params defined in the WIT files
gcd_module(Instance&);
int32_t gcd (int32_t a, int32_t b);
}
I think you're looking for the C++ equivalent of bindgen! which does not currently exist
yup that looks exactly like what im looking for .
thanks! ill keep an eye out for something similar for more languages.
Last updated: Dec 06 2025 at 06:05 UTC