Go, Wasm, & Bazel: A Blueprint for Hermetic, High-Performance Web Applications
11th November 2025
Rajiv Ranjan Singh
Naman Lakhwani
Rajiv Ranjan Singh
Naman Lakhwani
//go:wasmimport and //go:wasmexport are used for function calls
Three files to create:
Keep: Your existing go.mod file
module( name = "bazelcon-2025", version = "1.0.0", ) # Bazel dependencies bazel_dep(name = "rules_go", version = "0.50.1") bazel_dep(name = "gazelle", version = "0.39.1") # Go SDK setup go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") go_sdk.download(version = "1.23.4") # Go dependencies go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps") go_deps.from_file(go_mod = "//:go.mod") use_repo(go_deps)
package main import ( "fmt" "runtime" ) func main() { fmt.Println("Hello, Bazel, WASM, and Go!") fmt.Printf("GOOS: %s, GOARCH: %s\n", runtime.GOOS, runtime.GOARCH) }
Build:
bazel build //:app
bazel build //:app-wasm
Run native:
$ ./bazel-bin/app_/app
Hello, Bazel, WASM, and Go!
GOOS: darwin, GOARCH: arm64
Run WASM:
$ wasmtime ./bazel-bin/app-wasm_/app-wasm
Hello, Bazel, WASM, and Go!
GOOS: wasip1, GOARCH: wasm
14
Rajiv Ranjan Singh
Naman Lakhwani