Hi everyone! I'm trying run Kotlin built project in wasmtime (yes, I know it's not officially supported) with WASI HTTP components. When I try to start it in wasmtime with some custom components like in this branch:
https://github.com/dmchub/kotlin-wasm-cm-experiments/tree/test
it throws error with mentioning custom components
$ wasmtime serve -W function-references,gc,component-model build/out/component/kco-wasm-wasi.uncomposed.wasm
Error: component imports instance `component-model:example/ui`, but a matching implementation was not found in the linker
Caused by:
0: instance export `create-button` has the wrong type
1: function implementation is missing
when I remove custom components and leave only wasi-http components like here:
https://github.com/dmchub/kotlin-wasm-cm-experiments/tree/wasmtime
it throws error with incoming-handler mentioning:
$ wasmtime serve -W function-references,gc build/out/component/kco-wasm-wasi.uncomposed.wasm
Error: no exported instance named wasi:http/incoming-handler@0.2.3
it confuses me because I set 0.2.0 version in WIT components, not 0.2.3
https://github.com/dmchub/kotlin-wasm-cm-experiments/blob/wasmtime/wit/deps/http/proxy.wit#L1
How can I fix wasi:http/incoming-handler@0.2.3
issue? Or maybe it's possible to add custom components in the linker?
Here is list of commands I run to get the result:
rm -rf ./build/out
mkdir -p ./build/out/dependencies
cp wit/example.wit ./rust-component/wit/
cd ./rust-component/
cargo build --target wasm32-wasip1 --release
wasm-tools component new ./target/wasm32-wasip1/release/example.wasm -o ../build/out/dependencies/example.wasm --adapt .././wasi_snapshot_preview1.reactor.wasm
cd ..
wit-bindgen kotlin ./wit --out-dir src/wasmWasiMain/kotlin/bindings
java -jar ./ktfmt-0.47-jar-with-dependencies.jar ./src/wasmWasiMain/kotlin/bindings
./gradlew :compileProductionExecutableKotlinWasmWasi -Pkotlin.wasm.stability.nowarn=true
mkdir -p ./build/out/wasm
wasm-tools component embed wit/ ./build/compileSync/wasmWasi/main/productionExecutable/kotlin/kco-wasm-wasi.wasm -o build/out/wasm/kco-wasm-wasi.embedded.wasm
mkdir -p ./build/out/component
wasm-tools component new build/out/wasm/kco-wasm-wasi.embedded.wasm -o build/out/component/kco-wasm-wasi.uncomposed.wasm --adapt ./wasi_snapshot_preview1.reactor.wasm --realloc-via-memory-grow
wasmtime serve -W function-references,gc build/out/component/kco-wasm-wasi.uncomposed.wasm
Could you share some of the wasm components in question here? The first error looks like a bug in creating the component itself. The second error I'm not so sure about though
Last updated: Apr 08 2025 at 03:15 UTC