Skip to content

Instantly share code, notes, and snippets.

@beijaflor
Created December 15, 2024 16:00
Show Gist options
  • Save beijaflor/6aeeaa2d70c3e373a1467d94b2afb43a to your computer and use it in GitHub Desktop.
Save beijaflor/6aeeaa2d70c3e373a1467d94b2afb43a to your computer and use it in GitHub Desktop.
Web Assembly Component Model Pramtive

ref

https://nulab.com/ja/blog/nulab/webassembly-component-model/

setup

$ cargo -V
cargo 1.78.0 (54d8815d0 2024-03-26)
$ rustup update
$ cargo -V
cargo 1.83.0 (5ffbef321 2024-10-29)
$ cargo install --locked wasm-tools
$ wasm-tools --version
wasm-tools 1.221.2

init

$ touch module-example.wat
$ wasm-tools parse module-example.wat -o module-example.wasm
$ wasm-tools dump module-example.wasm
$ file module-example.wasm
$ touch component-example.wasm
$ wasm-tools parse component-example.wat -o component-example.wasm
$ wasm-tools dump component-example.wasm
$ file component-example.wasm

wasm time

$ curl https://wasmtime.dev/install.sh -sSf | bash
$ exec $SHELL -l
$ wasmtime -V
wasmtime 27.0.0 (8eefa236f 2024-11-20)
(component
(core module $Mod
(func (export "mod-main") (result i32)
(i32.const 1)
)
)
(core instance $m (instantiate $Mod))
(func $main_lifted (result (result)) (canon lift (core func $m "mod-main")))
(component $Comp
(import "main" (func $g (result (result))))
(export "run" (func $g))
)
(instance $c (instantiate $Comp
(with "main" (func $main_lifted))
))
(export "wasi:cli/[email protected]" (instance $c))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment