| 28 | } |
| 29 | |
| 30 | int main() { |
| 31 | // Define the WASI functions globally on the `Config`. |
| 32 | Engine engine; |
| 33 | Linker linker(engine); |
| 34 | linker.define_wasi().unwrap(); |
| 35 | |
| 36 | // Create a WASI context and put it in a Store; all instances in the store |
| 37 | // share this context. `WasiConfig` provides a number of ways to |
| 38 | // configure what the target program will have access to. |
| 39 | WasiConfig wasi; |
| 40 | wasi.inherit_argv(); |
| 41 | wasi.inherit_stdin(); |
| 42 | wasi.inherit_stdout(); |
| 43 | wasi.inherit_stderr(); |
| 44 | |
| 45 | Store store(engine); |
| 46 | store.context().set_wasi(std::move(wasi)).unwrap(); |
| 47 | |
| 48 | // Load and compile the wasm module. |
| 49 | auto bytes = read_binary_file("target/wasm32-wasip1/debug/wasi.wasm"); |
| 50 | auto module = |
| 51 | Module::compile(engine, Span<uint8_t>(bytes.data(), bytes.size())) |
| 52 | .unwrap(); |
| 53 | |
| 54 | // Define the module in the linker (anonymous name matches Rust example |
| 55 | // usage). |
| 56 | linker.module(store.context(), "", module).unwrap(); |
| 57 | |
| 58 | // Get the default export (command entrypoint) and invoke it. |
| 59 | Func default_func = linker.get_default(store.context(), "").unwrap(); |
| 60 | default_func.call(store, {}).unwrap(); |
| 61 | |
| 62 | return 0; |
| 63 | } |
nothing calls this directly
no test coverage detected