MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime-go / NewComponent

Function NewComponent

component_feat_component_model.go:41–54  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

39// This function expects a component binary, such as what is produced by Rust's
40// `cargo component` tooling or `wasm-tools component new`.
41func 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
56func mkComponent(ptr *C.wasmtime_component_t, engine *Engine) *Component {
57 c := &Component{_ptr: ptr, engine: engine}

Callers 2

newComponentFunction · 0.85
TestComponentNewFunction · 0.85

Calls 3

mkErrorFunction · 0.85
mkComponentFunction · 0.85
ptrMethod · 0.45

Tested by 2

newComponentFunction · 0.68
TestComponentNewFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…