Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

gleam / examples / hello_wasm
1 folder 6 files
README.md

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".
  • main must take no arguments. Supported return types for printing: String, Int, and Bool.
  • No Hex packages yet — the Wasm backend does not implement enough of the standard library for typical dependencies.