(export "wasi:cli/run@0.2.1|run")
I think here you meant (export "wasi:cli/run@0.2.1#run")
. Also make sure you use --world wasi:cli/command
in the embed
subcommand to select the right world
Ah, yes, I was trying a few different things and at some point I changed #
to |
. And also the command
include was precisely the thing that was missing, thanks so much!
For anyone trying that for themselves. Given that you have wit
declarations for WASI p2 in the wit/deps
directory, you declare a world like that:
package testing:wasi-components;
world just-testing {
include wasi:cli/imports@0.2.1;
// this is what I was missing, I wrongly assumed wasi:cli/imports grabs everything
include wasi:cli/command@0.2.1;
}
now with the following wat code:
(module
(import "wasi:io/streams@0.2.1" "[method]output-stream.blocking-write-and-flush" (func $blocking-write-and-flush (param i32 i32 i32 i32)))
(import "wasi:cli/stdout@0.2.1" "get-stdout" (func $get-stdout (result i32)))
(func (export "wasi:cli/run@0.2.1#run") (result i32)
(call $blocking-write-and-flush
(call $get-stdout)
(i32.const 100)
(i32.const 6)
(i32.const 200))
(i32.const 0)
)
(memory (export "memory") 1)
(data (i32.const 100) "hello\n")
)
You can do:
wasm-tools component embed ./wit --world just-testing foo.wat -t -o foo.core.wasm
wasm-tools component new foo.core.wasm -o foo.component.wasm
wasmtime run foo.component.wasm
# => hello
Piotr Sarnacki has marked this topic as resolved.
this is the interesting part to learn from on my side:
// this is what I was missing, I wrongly assumed wasi:cli/imports grabs everything
include wasi:cli/command@0.2.1;
Last updated: Nov 22 2024 at 17:03 UTC