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

Function component_bytecode

tests/all/debug.rs:1177–1216  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1175#[test]
1176#[cfg_attr(miri, ignore)]
1177fn component_bytecode() -> wasmtime::Result<()> {
1178 use wasmtime::component::{Component, Linker};
1179
1180 // Build the bytecode for each core module by compiling them
1181 // standalone.
1182 let m1_body = r#"(func (export "f1") (result i32) i32.const 42)"#;
1183 let m2_body = r#"(func (export "f2") (result i32) i32.const 99)"#;
1184 let m1_wasm = wat::parse_str(&format!("(module $m1 {m1_body})")).unwrap();
1185 let m2_wasm = wat::parse_str(&format!("(module $m2 {m2_body})")).unwrap();
1186
1187 // Build a component that embeds both core modules inline.
1188 let component_wasm = wat::parse_str(&format!(
1189 r#"(component
1190 (core module $m1 {m1_body})
1191 (core instance $i1 (instantiate (module $m1)))
1192 (core module $m2 {m2_body})
1193 (core instance $i2 (instantiate (module $m2))))
1194 "#,
1195 ))
1196 .unwrap();
1197
1198 let mut config = Config::default();
1199 config.guest_debug(true);
1200 let engine = Engine::new(&config)?;
1201
1202 let component = Component::new(&engine, &component_wasm)?;
1203 let linker: Linker<()> = Linker::new(&engine);
1204 let mut store = Store::new(&engine, ());
1205 linker.instantiate(&mut store, &component)?;
1206
1207 let modules = store.debug_all_modules();
1208 assert_eq!(modules.len(), 2);
1209
1210 // Modules should be registered in offset order. The API doesn't
1211 // guarantee this, but this suffices for a test.
1212 assert_eq!(modules[0].debug_bytecode().unwrap(), &m1_wasm[..]);
1213 assert_eq!(modules[1].debug_bytecode().unwrap(), &m2_wasm[..]);
1214
1215 Ok(())
1216}
1217
1218#[test]
1219#[cfg_attr(miri, ignore)]

Callers

nothing calls this directly

Calls 6

OkFunction · 0.85
guest_debugMethod · 0.80
debug_all_modulesMethod · 0.80
newFunction · 0.50
unwrapMethod · 0.45
instantiateMethod · 0.45

Tested by

no test coverage detected