๐Ÿ›  Setup: your local forge

Phases 1โ€“2 mostly run in the browser. But real projects โ€” the canvas starter, the snake port, domains, the capstone โ€” need OCaml on your machine. Twenty minutes, once.

The toolchain, in one table

ToolWhat it isGame analogy
opamOCaml's package & compiler managerthe item shop
ocaml 5.5.0the compiler + toplevelthe game engine itself
dunethe build systemthe crafting bench
utopa deluxe toplevel for your terminalthe training arena
js_of_ocamlcompiles OCaml bytecode to JavaScriptthe portal to the browser world

1 ยท Install opam

Linux / macOS โ€” official installer script (or your package manager: apt install opam, dnf install opam, brew install opam; make sure you get opam โ‰ฅ 2.1):

Windows โ€” two good options: WSL2 with Ubuntu, then follow the Linux steps inside it (recommended โ€” it matches every terminal block on this site), or native opam โ‰ฅ 2.2 from ocaml.org/install.

2 ยท Create the OCaml 5.5 switch and install the tools

Verify the loot:

(Later versions are fine.)

3 ยท Editor

VS Code with the OCaml Platform extension gives inline types, errors and formatting. Install the extension, then:

4 ยท The canvas starter (your first portal)

Download canvas-starter.zip โ€” a minimal dune project that compiles OCaml to JavaScript and animates a square on an HTML canvas. It's the skeleton every local project in this course grows from.

Open http://localhost:8000 โ€” a bouncing square you steer with the arrow keys. The project layout:

canvas-starter/
โ”œโ”€โ”€ dune-project      # project manifest (one line of config)
โ”œโ”€โ”€ bin/
โ”‚   โ”œโ”€โ”€ dune          # "build main.ml to JavaScript"
โ”‚   โ””โ”€โ”€ main.ml       # ALL the game logic โ€” yours to edit
โ””โ”€โ”€ web/
    โ”œโ”€โ”€ dune          # copies the compiled JS next to the page
    โ”œโ”€โ”€ index.html    # the page: canvas + HUD (Maks's territory)
    โ””โ”€โ”€ style.css     # the look (also Maks's territory)

Edit bin/main.ml, run dune build again, refresh the browser. That's the whole loop. (Try dune build -w for auto-rebuild on save.)

5 ยท Hosting this site (localhost or homelab)

The site is pure static files in site/. Simplest:

For the homelab, a tiny nginx container (Dockerfile included in the repo โ€” nginx also gzips the 11 MB engine down to ~3 MB on the wire):

Then any device on your network can play at http://<server-ip>:8043.

6 ยท Rebuilding the in-page engine (optional)

The engine at site/assets/toplevel/toplevel.js is an OCaml 5.5 toplevel compiled with js_of_ocaml (source in playground-src/). It ships prebuilt; rebuild only if you upgrade OCaml or hack on it:

Troubleshooting