···11+# Building clayterm from source
22+33+This guide is for maintainers and builders working on clayterm itself.
44+55+It covers:
66+77+- cloning the repo correctly,
88+- initializing the `clay` git submodule,
99+- installing the toolchain needed to compile the C sources to WebAssembly,
1010+- building the local development artifacts, and
1111+- verifying that the repo is ready for development.
1212+1313+It does **not** cover npm/JSR packaging or publishing.
1414+1515+## What the local build produces
1616+1717+The local source build is driven by `make`.
1818+1919+It generates:
2020+2121+- `clayterm.wasm` — the compiled WebAssembly module built from the C sources
2222+- `wasm.ts` — a generated TypeScript file derived from `clayterm.wasm`
2323+2424+`wasm.ts` is generated output, not hand-maintained source.
2525+2626+## Clone the repo with submodules
2727+2828+The build depends on the `clay` git submodule.
2929+3030+Preferred fresh clone:
3131+3232+```sh
3333+git clone --recurse-submodules https://github.com/thefrontside/clayterm.git
3434+cd clayterm
3535+```
3636+3737+If you already cloned without submodules:
3838+3939+```sh
4040+git submodule update --init --recursive
4141+```
4242+4343+Quick check:
4444+4545+```sh
4646+git submodule status --recursive
4747+```
4848+4949+You should also see a populated `clay/` directory. If `clay/` is missing or
5050+empty, fix the submodule state before building.
5151+5252+## Required tools
5353+5454+You need:
5555+5656+- `git`
5757+- `make`
5858+- `clang` with wasm32-capable support
5959+- `deno`
6060+6161+Equivalent packages are fine if your package manager uses different names.
6262+6363+## Install the toolchain
6464+6565+### macOS
6666+6767+Install Apple's command line tools first. They provide the base developer tools,
6868+including `git` and `make`.
6969+7070+```sh
7171+xcode-select --install
7272+```
7373+7474+Then install LLVM and Deno with Homebrew:
7575+7676+```sh
7777+brew install llvm deno
7878+```
7979+8080+Use Homebrew LLVM before Apple's system `clang` when building clayterm:
8181+8282+```sh
8383+echo 'export PATH="$(brew --prefix llvm)/bin:$PATH"' >> ~/.zshrc
8484+source ~/.zshrc
8585+```
8686+8787+If you do not already have `git` available after installing the command line
8888+tools, install it with Homebrew:
8989+9090+```sh
9191+brew install git
9292+```
9393+9494+### Debian / Ubuntu
9595+9696+Install the build toolchain and Git:
9797+9898+```sh
9999+sudo apt-get update
100100+sudo apt-get install -y build-essential clang lld git curl
101101+```
102102+103103+Install Deno with the official installer:
104104+105105+```sh
106106+curl -fsSL https://deno.land/install.sh | sh
107107+```
108108+109109+Add Deno to your shell path:
110110+111111+```sh
112112+echo 'export PATH="$HOME/.deno/bin:$PATH"' >> ~/.bashrc
113113+source ~/.bashrc
114114+```
115115+116116+### Fedora / RHEL
117117+118118+Install the build toolchain and Git:
119119+120120+```sh
121121+sudo dnf install -y clang lld make git curl
122122+```
123123+124124+Install Deno with the official installer:
125125+126126+```sh
127127+curl -fsSL https://deno.land/install.sh | sh
128128+```
129129+130130+Add Deno to your shell path:
131131+132132+```sh
133133+echo 'export PATH="$HOME/.deno/bin:$PATH"' >> ~/.bashrc
134134+source ~/.bashrc
135135+```
136136+137137+### Windows
138138+139139+The recommended Windows build-host path is **WSL2 with Ubuntu**.
140140+141141+From an elevated PowerShell prompt:
142142+143143+```powershell
144144+wsl --install -d Ubuntu
145145+```
146146+147147+Then open the Ubuntu environment and follow the **Debian / Ubuntu** instructions
148148+above.
149149+150150+The build host runs inside WSL2, but the resulting WebAssembly artifacts are
151151+intended to run on **native Windows** at runtime.
152152+153153+## Verify the toolchain
154154+155155+Before building, confirm the required tools are available:
156156+157157+```sh
158158+git --version
159159+make --version
160160+clang --version
161161+deno --version
162162+```
163163+164164+For a quick wasm-target smoke test, make sure `clang` can compile for `wasm32`:
165165+166166+```sh
167167+clang --target=wasm32 -c -x c /dev/null -o /tmp/clayterm-wasm-test.o
168168+rm -f /tmp/clayterm-wasm-test.o
169169+```
170170+171171+On macOS, if `which clang` still points to `/usr/bin/clang` and the wasm test
172172+fails, make sure the Homebrew LLVM `bin/` directory is at the front of your
173173+`PATH`.
174174+175175+## Build from source
176176+177177+Run the local source build from the repository root:
178178+179179+```sh
180180+make
181181+```
182182+183183+This should produce:
184184+185185+- `clayterm.wasm`
186186+- `wasm.ts`
187187+188188+For a clean rebuild:
189189+190190+```sh
191191+make clean && make
192192+```
193193+194194+## When to rebuild
195195+196196+Re-run `make` when:
197197+198198+- you change files under `src/`
199199+- you update the `clay` submodule
200200+- `clayterm.wasm` or `wasm.ts` is missing
201201+- generated outputs look stale after switching branches or pulling changes
202202+203203+When in doubt, use a clean rebuild:
204204+205205+```sh
206206+make clean && make
207207+```
208208+209209+## Verify the build
210210+211211+After `make` succeeds, run the test suite:
212212+213213+```sh
214214+deno task test
215215+```
216216+217217+Before opening a PR, it is also a good idea to run the same checks CI runs:
218218+219219+```sh
220220+deno task fmt:check
221221+deno lint
222222+```
223223+224224+## Troubleshooting
225225+226226+### `clay/` is missing or empty
227227+228228+Symptoms may include build failures such as:
229229+230230+- `fatal error: '../clay/clay.h' file not found`
231231+232232+Recovery:
233233+234234+```sh
235235+git submodule update --init --recursive
236236+```
237237+238238+Then verify the submodule state and rebuild:
239239+240240+```sh
241241+git submodule status --recursive
242242+make clean && make
243243+```
244244+245245+### `clang` cannot target `wasm32`
246246+247247+Symptoms may include:
248248+249249+- target-related `clang` errors mentioning `wasm32`
250250+- linker failures while producing `clayterm.wasm`
251251+252252+Recovery:
253253+254254+- make sure you are using an LLVM/Clang build with wasm support
255255+- on macOS, prefer the Homebrew `llvm` toolchain over `/usr/bin/clang`
256256+- on Linux/WSL2, make sure both `clang` and `lld` are installed
257257+- rerun the wasm smoke test:
258258+259259+```sh
260260+clang --target=wasm32 -c -x c /dev/null -o /tmp/clayterm-wasm-test.o
261261+rm -f /tmp/clayterm-wasm-test.o
262262+```
263263+264264+If the smoke test fails, fix the toolchain first and only then rerun `make`.
265265+266266+### Generated artifacts are missing or stale
267267+268268+Symptoms may include:
269269+270270+- `clayterm.wasm` is missing
271271+- `wasm.ts` is missing
272272+- you changed `src/` or updated `clay/`, but the generated outputs do not match
273273+274274+Recovery:
275275+276276+```sh
277277+make clean && make
278278+```
279279+280280+Then verify the repo is in a good state:
281281+282282+```sh
283283+deno task test
284284+```
285285+286286+## Scope note
287287+288288+This document is intentionally limited to local source builds for development.
289289+290290+Out of scope:
291291+292292+- `deno task build:npm`
293293+- `deno task build:jsr`
294294+- `npm publish`
295295+- `deno publish`
296296+- release tagging and package publishing workflows
+3-7
README.md
···212212213213## Development
214214215215-Requires `clang` with wasm32 target support.
215215+For local source builds, toolchain setup, and `clay` submodule instructions, see
216216+[BUILD.md](BUILD.md).
216217217217-First build the `.wasm`
218218+Quick local validation:
218219219220```sh
220221make
221221-```
222222-223223-run tests
224224-225225-```sh
226222deno task test
227223```