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

Function main

examples/linking.cc:24–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24int main() {
25 Engine engine;
26 Store store(engine);
27
28 // Read our input `*.wat` files into `std::string`s
29 std::string linking1_wat = readFile("examples/linking1.wat");
30 std::string linking2_wat = readFile("examples/linking2.wat");
31
32 // Compile our two modules
33 Module linking1_module = Module::compile(engine, linking1_wat).unwrap();
34 Module linking2_module = Module::compile(engine, linking2_wat).unwrap();
35
36 // Configure WASI and store it within our `wasmtime_store_t`
37 WasiConfig wasi;
38 wasi.inherit_argv();
39 wasi.inherit_env();
40 wasi.inherit_stdin();
41 wasi.inherit_stdout();
42 wasi.inherit_stderr();
43 store.context().set_wasi(std::move(wasi)).unwrap();
44
45 // Create our linker which will be linking our modules together, and then add
46 // our WASI instance to it.
47 Linker linker(engine);
48 linker.define_wasi().unwrap();
49
50 // Instantiate our first module which only uses WASI, then register that
51 // instance with the linker since the next linking will use it.
52 Instance linking2 = linker.instantiate(store, linking2_module).unwrap();
53 linker.define_instance(store, "linking2", linking2).unwrap();
54
55 // And with that we can perform the final link and the execute the module.
56 Instance linking1 = linker.instantiate(store, linking1_module).unwrap();
57 Func f = std::get<Func>(*linking1.get(store, "run"));
58 f.call(store, {}).unwrap();
59}

Callers

nothing calls this directly

Calls 15

inherit_argvMethod · 0.80
set_wasiMethod · 0.80
define_wasiMethod · 0.80
define_instanceMethod · 0.80
readFileFunction · 0.70
compileFunction · 0.50
unwrapMethod · 0.45
inherit_envMethod · 0.45
inherit_stdinMethod · 0.45
inherit_stdoutMethod · 0.45
inherit_stderrMethod · 0.45
contextMethod · 0.45

Tested by

no test coverage detected