Fork of daniellemaywood.uk/gleam — Wasm codegen work
988 B
hello_wasm#
A tiny Gleam program that compiles to WebAssembly and runs under wasmtime via WASI.
The compiler emits a _start entry that calls main and prints its return
value to stdout (wasi_snapshot_preview1::fd_write).
Run#
From this directory (builds the in-repo gleam first):
./run.sh
Or step by step:
# from repo root
cargo build -p gleam
# from this directory
../../target/debug/gleam build
wasmtime build/dev/wasm/hello_wasm/hello_wasm.wasm
Expected output:
Hello from Gleam Wasm!
fib(10) = 55
You can also call individual exports:
wasmtime --invoke fib build/dev/wasm/hello_wasm/hello_wasm.wasm 10
# => 55
Notes#
- Target is set in
gleam.toml:target = "wasm". mainmust take no arguments. Supported return types for printing:String,Int, andBool.- No Hex packages yet — the Wasm backend does not implement enough of the standard library for typical dependencies.