Skip to content

wasm

2 posts with the tag “wasm”

2026 Week 14 - new category

2026W14

Simplest zig wasm

export fn add(a: i32, b: i32) i32 {
return a + b;
}
Terminal window
zig build-exe add.zig -target wasm32-freestanding -fno-entry -rdynamic
<!doctype html>
<html>
<body>
<script>
const request = new XMLHttpRequest()
request.open('GET', 'add.wasm')
request.responseType = 'arraybuffer'
request.send()
request.onload = function () {
WebAssembly.instantiate(request.response, { env: {} }).then((result) => {
const add = result.instance.exports.add
console.log(add(3, 5)) // Outputs 8
})
}
</script>
</body>
</html>

run

Terminal window
python -m http.server

Review

WASM - Simplest Thing That Works (STTWs)

2026W14-3

Simplest zig wasm

export fn add(a: i32, b: i32) i32 {
return a + b;
}
Terminal window
zig build-exe add.zig -target wasm32-freestanding -fno-entry -rdynamic
<!doctype html>
<html>
<body>
<script>
const request = new XMLHttpRequest()
request.open('GET', 'add.wasm')
request.responseType = 'arraybuffer'
request.send()
request.onload = function () {
WebAssembly.instantiate(request.response, { env: {} }).then((result) => {
const add = result.instance.exports.add
console.log(add(3, 5)) // Outputs 8
})
}
</script>
</body>
</html>

run

Terminal window
python -m http.server

Open and check console