Files

78 lines
4.1 KiB
Markdown

# Building the OneCAD Draft wasm bundle (`static/onecaddraft`)
The complete source state of this repository (rebrand + Odoo glue + Rust
bridge) is ready to build. **The wasm compile of the app crate (640k lines of
Rust across 789 files) needs ~4.5 GB RAM for rustc alone** — it OOM-kills in
a 4 GB cgroup (verified twice with a memory monitor: rustc peaks at
~3.7 GB and grows past the ceiling during metadata encoding). Any machine
with **8 GB+ free RAM** and ~3 GB free disk completes it.
## Build on a roomy machine (the one path that works end-to-end)
```bash
# 0) deps: rustup target add wasm32-unknown-unknown; cargo install --locked trunk
# wasm-bindgen-cli MUST match Cargo.lock (grep wasm-bindgen Cargo.lock)
# 1) OPTIONAL (recommended for production quality): restore opt level
# In Cargo.toml [profile.release] remove the opt-level = 0 line added for
# the constrained sandbox build. Upstream default (opt 3) is best for CAD.
# 2) build (trunk reads Trunk.toml: target=web-app.html, dist=dist/app,
# and runs the [[hooks]] post_build script that builds + wasm-binds
# the ocs_web_worker cdylib automatically)
trunk build --release
# 3) assemble + deploy + version lockstep (compiles web/odoo/*.ts with
# esbuild, strips sw.js/app.webmanifest, injects the odoo boot snippet,
# deploys to core-components/one_cad_draft/static/onecaddraft/)
python3 scripts/assemble_onecaddraft_dist.py # on the one-os-dev sandbox
# 4) install/upgrade the module
python3 scripts/onecaddraft-install-rpc.py # XML-RPC 127.0.0.1:18070 db=oneos
```
`assemble_onecaddraft_dist.py` gates: REQUIRED `index.html`,
`OpenCADStudio.js`, `OpenCADStudio_bg.wasm`, `worker_pkg/ocs_web_worker.js`,
`worker_pkg/ocs_web_worker_bg.wasm`, `ocs-parse-worker.js`, `ocs-control.js`,
`locale-labels.json`, non-empty `fonts/`; FORBIDDEN `sw.js`,
`app.webmanifest` (stripped with a loud log); no absolute `/app/`-prefixed
asset refs; version lockstep across `bundleVersion`, `__manifest__.py` and
the glue `?v=` literals.
## Sandbox lessons that cost us hours (do not re-learn)
1. **`?v=` bump per build.** Odoo serves statics with 7-day max-age; the
assembler bumps everything in lockstep. Hard-refresh the browser once.
2. **wasm-bindgen stack OOM** when the Odoo stack is up: `oneos-dev down`
before bindgen, `up` after (the assembler does not build, so this only
matters for manual bindgen runs).
3. **NEVER `wasm-tools strip -a`** (destroys `__wasm_bindgen_unstable`).
Use `wasm-opt --strip-dwarf` then `-O1`/`-O2` if hand-optimizing; trunk
already runs the wasm-opt pass requested in the HTML tag.
4. **Overlay rootfs**: only runtime-layer deletions free space; build
scratch must be deleted eagerly (`target/release/deps` re-fills on
resume — deleting it buys nothing net).
5. **`NO_COLOR=1` breaks trunk's clap parser** (`--no-color` expects
true/false): run trunk with `env -u NO_COLOR`.
6. **`cargo check` creates a full second (dev-profile) tree** — on a
constrained disk it IS the disk-full event. Don't check; build.
7. **Orphan sweep**: profile-era changes leave stale-hash artifacts forever;
`scripts/prune-orphans.py` (in the one-os-dev sandbox) reclaims them.
8. **Background processes die between tool calls** in the z.ai sandbox —
run long builds in ≤9-minute foreground chunks; cargo resumes
incrementally.
## What is already wired (no further source work needed)
- `web/odoo/{index.ts,bridge.ts,explorer.js}` — the Documents glue (save
air-gap via `window.openCadStudioSaveFile`, deep-link opens via
`wasmBindings.ocs_web_drop_file`, explorer dialogs, bind storage).
- `src/odoo_bridge.rs` — Rust bridge: `File > Open` in the embedded shell
dispatches `onecaddraft:host-request {method:"odoo.pickOpen"}` and drains
completions in `Message::PollWebControl` (50 ms tick) into
`open_web_bytes`. Never touches `window.onecaddraftHostReady`.
- `src/app/update/file.rs` (intercept) + `src/app/update/mod.rs` (drain) +
`src/lib.rs` (module decl) + `Cargo.toml` (CustomEvent features).
- `core-components/one_cad_draft/` in one-os-dev: the 5-file addon
(storage seq 52, menu seq 37, extensions dxf/dwg, fileExtension .dxf).