NewComponent compiles a component-model binary into a [Component]. This function expects a component binary, such as what is produced by Rust's `cargo component` tooling or `wasm-tools component new`.
(engine *Engine, wasm []byte)
| 39 | // This function expects a component binary, such as what is produced by Rust's |
| 40 | // `cargo component` tooling or `wasm-tools component new`. |
| 41 | func NewComponent(engine *Engine, wasm []byte) (*Component, error) { |
| 42 | var wasmPtr *C.uint8_t |
| 43 | if len(wasm) > 0 { |
| 44 | wasmPtr = (*C.uint8_t)(unsafe.Pointer(&wasm[0])) |
| 45 | } |
| 46 | var ptr *C.wasmtime_component_t |
| 47 | err := C.wasmtime_component_new(engine.ptr(), wasmPtr, C.size_t(len(wasm)), &ptr) |
| 48 | runtime.KeepAlive(engine) |
| 49 | runtime.KeepAlive(wasm) |
| 50 | if err != nil { |
| 51 | return nil, mkError(err) |
| 52 | } |
| 53 | return mkComponent(ptr, engine), nil |
| 54 | } |
| 55 | |
| 56 | func mkComponent(ptr *C.wasmtime_component_t, engine *Engine) *Component { |
| 57 | c := &Component{_ptr: ptr, engine: engine} |
searching dependent graphs…