index.html, the .wasm module and the JavaScript that loads it. That covers a module with a loader you wrote, a C or C++ game compiled with Emscripten, and Rust, Zig or Go compiled to wasm, including Bevy and Ebitengine games. OpenGame does not compile anything: you build, and upload the build.
Choose the engine ID
opengame init detects most of these from your project. Pass --engine to choose one yourself:
In the build,
opengame check and the server recognize Emscripten from its runtime code and the .wasm it built, threaded or not, and from its MINIMAL_RUNTIME loader, as well as Rust’s wasm-bindgen glue and Go’s wasm_exec.js. A Zig build carries no signature of its own, so a module its page loads itself is named WebAssembly. Hosting is the same either way.
Starters
The OpenGame repository has a starter for each language, undertemplates/. Each builds with node build.mjs into dist/, and needs its compiler on your PATH.
Load the SDK
Every language here reaches the SDK throughwindow.OpenGame. Ship opengame-global.js and its .LEGAL.txt notice in the build, and load the script before the module, as Platform services shows:
/_og/sdk.js from OpenGame. A build without threads gets no added script, so ship a copy.
Raw WebAssembly
Writeindex.html and a loader, and call the SDK from JavaScript:
index.html
game.wasm beside index.html, or fetch it by a path relative to the page.
C and C++ with Emscripten
Build with Emscripten, with its environment active:- Output: Emscripten writes
index.html,index.jsandindex.wasm, plus any.datafile the build preloads. Upload the whole folder. - Libraries: build each native library with Emscripten too. A desktop library does not link into a web build.
- Main loop: pass your frame function to
emscripten_set_main_loop, so each frame returns control to the browser. - Threads: optional. Build with
-pthread, and OpenGame serves the build isolated. - Memory:
-sALLOW_MEMORY_GROWTH=1lets the heap grow. If JavaScript keeps a view of the heap, create it again after growth. - C++ exports: put each function you mark
EMSCRIPTEN_KEEPALIVEinsideextern "C", so JavaScript can call it by its plain name.
integrations/c in the repository, calls the SDK from C or C++. Copy opengame.c, opengame.h and opengame.js into the project, and link them:
main.c
og_request takes a bridge operation and its JSON arguments, and the result arrives later through the callback. Platform services lists the operations. Emscripten rewrites index.html on each build, so add the opengame-global.js script tag after the build, or pass a shell file with --shell-file that already has it.
Emscripten builds covers a larger codebase, a port or a decompilation: the build flags, shorthand calls such as og_track and og_board_submit, saves that last between visits, and what the player does for fullscreen, sound and input.
Rust
Add the wasm target, then build with Trunk or with Cargo:- Trunk:
initsetstrunk build --releaseas the build command when the project hasTrunk.toml, or anindex.htmlthat usesdata-trunk. Trunk writesdist/. - wasm-bindgen: install the
wasm-bindgenCLI at the version of thewasm-bindgencrate inCargo.lock. - Threads: a build whose module uses shared memory is served isolated.
opengame crate is integrations/rust in the repository, used as a path dependency:
Cargo.toml
track, achievements::unlock, achievements::list, sign_in, open_link, fullscreen, player and subscribe for pause, mute and player changes. It uses wasm-bindgen by default. With default-features = false and features = ["raw-import"], it uses raw imports, and the page loads it with imports.mjs, host.mjs and lifecycle.mjs from integrations/c.
To add the SDK in a Trunk project, copy both files with Trunk and load the script before Trunk’s module:
index.html
Zig
Build forwasm32-freestanding with Zig 0.13:
build.zig, the same settings are entry = .disabled, rdynamic = true and export_memory = true. The OpenGame Zig package, integrations/zig, has a Zig module and opengame.mjs, which builds the imports the module needs:
opengame.mjs and lifecycle.js beside the page. Call no export until instance is assigned, and call host.dispose() on pagehide. The Zig package expects one memory that is not shared, so use it in a single-thread build.
Go
Build with the standard Go compiler:- Runtime glue: copy
wasm_exec.jsfrom the Go you built with. It is in$(go env GOROOT)/lib/wasmon Go 1.24 and later, and inmisc/wasmbefore that. - Page: load
opengame-global.js, thenlifecycle.js, thenwasm_exec.js, and start the module withnew Go()andgo.run(instance). - Threads: Go’s
js/wasmport runs every goroutine on the browser’s main thread.
integrations/go in the repository. Point your go.mod at it:
integrations/go/web/lifecycle.js into the build. Drain the module’s message channel continuously, and never block the JavaScript event loop while you wait for a result.
Deploy
deploy uploads the build and prints the address of its deploy page, where Play appears once the checks pass. Export and deploy covers each step and opengame submit.
Memory and callbacks
- A module’s declared maximum memory is a limit it reserves, not memory it uses. Measure the running game.
- Recreate typed-array views of wasm memory after it grows.
- The OpenGame packages hand callbacks borrowed pointers or slices. Copy what you keep before the callback returns.
- Call the SDK from the browser’s main thread. A worker thread has no
window.OpenGame.