MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / main

Function main

examples/wasip1/main.cc:30–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30int 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}

Callers

nothing calls this directly

Calls 15

read_binary_fileFunction · 0.85
define_wasiMethod · 0.80
inherit_argvMethod · 0.80
set_wasiMethod · 0.80
compileFunction · 0.50
unwrapMethod · 0.45
inherit_stdinMethod · 0.45
inherit_stdoutMethod · 0.45
inherit_stderrMethod · 0.45
contextMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected