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

Method run_component

crates/wizer/src/component/wasmtime.rs:13–36  ·  view source on GitHub ↗

Same as [`Wizer::run`], except for components.

(
        &self,
        store: &mut Store<T>,
        wasm: &[u8],
        instantiate: impl AsyncFnOnce(&mut Store<T>, &Component) -> Result<Instance>,
    )

Source from the content-addressed store, hash-verified

11impl Wizer {
12 /// Same as [`Wizer::run`], except for components.
13 pub async fn run_component<T: Send>(
14 &self,
15 store: &mut Store<T>,
16 wasm: &[u8],
17 instantiate: impl AsyncFnOnce(&mut Store<T>, &Component) -> Result<Instance>,
18 ) -> wasmtime::Result<Vec<u8>> {
19 let (cx, instrumented_wasm) = self.instrument_component(wasm)?;
20
21 #[cfg(feature = "wasmprinter")]
22 log::debug!(
23 "instrumented wasm: {}",
24 wasmprinter::print_bytes(&instrumented_wasm).to_wasmtime_result()?,
25 );
26
27 let engine = store.engine();
28 let component = Component::new(engine, &instrumented_wasm)
29 .context("failed to compile the Wasm component")?;
30 let index = self.validate_component_init_func(&component)?;
31
32 let instance = instantiate(store, &component).await?;
33 self.initialize_component(store, &instance, index).await?;
34 self.snapshot_component(cx, &mut WasmtimeWizerComponent { store, instance })
35 .await
36 }
37
38 fn validate_component_init_func(
39 &self,

Callers 2

wizenFunction · 0.80
rust_regexFunction · 0.80

Calls 8

instrument_componentMethod · 0.80
initialize_componentMethod · 0.80
snapshot_componentMethod · 0.80
newFunction · 0.50
instantiateFunction · 0.50
engineMethod · 0.45
contextMethod · 0.45

Tested by 2

wizenFunction · 0.64
rust_regexFunction · 0.64