Skip to content

Commit a1c2c6e

Browse files
authored
Merge pull request #16 from rivet-dev/ralph/wasmvm-dynamic-modules
chore: wasmvm dynamic modules & libc support
2 parents 1f51b7f + b564e7a commit a1c2c6e

432 files changed

Lines changed: 33841 additions & 3643 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@ jobs:
3737
- name: Build WASM binary
3838
run: cd wasmvm && make wasm
3939

40+
# --- C toolchain (wasi-sdk + patched sysroot + C test fixtures) ---
41+
- name: Cache wasi-sdk
42+
id: cache-wasi-sdk
43+
uses: actions/cache@v4
44+
with:
45+
path: wasmvm/c/vendor/wasi-sdk
46+
key: wasi-sdk-25-${{ runner.os }}-${{ runner.arch }}
47+
48+
- name: Download wasi-sdk
49+
if: steps.cache-wasi-sdk.outputs.cache-hit != 'true'
50+
run: make -C wasmvm/c wasi-sdk
51+
52+
- name: Cache patched wasi-libc sysroot
53+
id: cache-sysroot
54+
uses: actions/cache@v4
55+
with:
56+
path: |
57+
wasmvm/c/sysroot
58+
wasmvm/c/vendor/wasi-libc
59+
key: wasi-libc-sysroot-${{ runner.os }}-${{ hashFiles('wasmvm/patches/wasi-libc/*.patch', 'wasmvm/scripts/patch-wasi-libc.sh') }}
60+
61+
- name: Build patched wasi-libc sysroot
62+
if: steps.cache-sysroot.outputs.cache-hit != 'true'
63+
run: make -C wasmvm/c sysroot
64+
65+
- name: Build C test fixtures (WASM + native)
66+
run: make -C wasmvm/c programs native
67+
4068
# --- Node.js / TypeScript ---
4169
- name: Set up pnpm
4270
uses: pnpm/action-setup@v4

CLAUDE.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,43 @@
3333
- check GitHub Actions test/typecheck status per commit to identify when a failure first appeared
3434
- do not use `contract` in test filenames; use names like `suite`, `behavior`, `parity`, `integration`, or `policy` instead
3535

36+
## Tool Integration Policy
37+
38+
- NEVER implement a from-scratch reimplementation of a tool when the PRD specifies using an existing upstream project (e.g., codex, curl, git, make)
39+
- always fork, vendor, or depend on the real upstream source — do not build a "stub" or "demo" binary that fakes the tool's behavior
40+
- if the upstream cannot compile or link for the target, document the specific blockers and leave the story as failing — do not mark it passing with a placeholder
41+
- the PRD and story notes define which upstream project to use; follow them exactly unless explicitly told otherwise
42+
43+
## C Library Vendoring Policy
44+
45+
- NEVER commit third-party C library source code directly into this repo
46+
- **unmodified upstream libraries** (sqlite3, zlib, minizip, cJSON, etc.) must be downloaded at build time from their official release URLs — add a Makefile target in `wasmvm/c/Makefile` under `fetch-libs`
47+
- **modified libraries** (e.g., libcurl with WASI patches) must live in a fork under the `rivet-dev` GitHub org (e.g., `rivet-dev/secure-exec-curl`) — the Makefile downloads from the fork's archive URL
48+
- all downloaded library sources go in `wasmvm/c/libs/` which is gitignored — they are fetched by `make fetch-libs` and cached in `wasmvm/c/.cache/`
49+
- when adding a new C library dependency: (1) add its download URL and Makefile target to `fetch-libs`, (2) add `libs/<name>` to the appropriate `.gitignore`, (3) if WASI modifications are needed, create a `rivet-dev/secure-exec-<name>` fork first
50+
- existing forks: `rivet-dev/secure-exec-curl` (libcurl with `wasi_tls.c` and `wasi_stubs.c`)
51+
3652
## WASM Binary
3753

54+
- the goal for WasmVM is full POSIX compliance 1:1 — every command, syscall, and shell behavior should match a real Linux system exactly
3855
- WasmVM and Python are experimental surfaces in this repo
3956
- all docs for WasmVM, Python, or other experimental runtime features must live under the `Experimental` section of the docs navigation, not the main getting-started/reference sections
40-
- the WasmVM runtime requires a WASM binary at `wasmvm/target/wasm32-wasip1/release/multicall.wasm`
41-
- build it locally: `cd wasmvm && make wasm` (requires Rust nightly + wasm32-wasip1 target + rust-src component + wasm-opt/binaryen)
57+
- the WasmVM runtime requires standalone WASM binaries in `wasmvm/target/wasm32-wasip1/release/commands/`
58+
- build them locally: `cd wasmvm && make wasm` (requires Rust nightly + wasm32-wasip1 target + rust-src component + wasm-opt/binaryen)
4259
- the Rust toolchain is pinned in `wasmvm/rust-toolchain.toml` — rustup will auto-install it
43-
- CI builds the binary before tests; a CI-only guard test in `packages/runtime/wasmvm/test/driver.test.ts` fails if it's missing
44-
- tests gated behind `skipIf(!hasWasmBinary)` or `skipUnlessWasmBuilt()` will skip locally if the binary isn't built
60+
- CI builds the binaries before tests; a CI-only guard test in `packages/runtime/wasmvm/test/driver.test.ts` fails if they're missing
61+
- tests gated behind `skipIf(!hasWasmBinaries)` or `skipUnlessWasmBuilt()` will skip locally if binaries aren't built
4562
- see `wasmvm/CLAUDE.md` for full build details and architecture
4663

64+
## WasmVM Syscall Coverage
65+
66+
- every function in the `host_process` and `host_user` import modules (declared in `wasmvm/crates/wasi-ext/src/lib.rs`) must have at least one C parity test exercising it through libc
67+
- when adding a new host import, add a matching test case to `wasmvm/c/programs/syscall_coverage.c` and its parity test in `packages/runtime/wasmvm/test/c-parity.test.ts`
68+
- the canonical source of truth for import signatures is `wasmvm/crates/wasi-ext/src/lib.rs` — C patches and JS host implementations must match exactly
69+
- C patches in `wasmvm/patches/wasi-libc/` must be kept in sync with wasi-ext — ABI drift between C, Rust, and JS is a P0 bug
70+
- permission tier enforcement must cover ALL write/spawn/kill/pipe/dup operations — audit `packages/runtime/wasmvm/src/kernel-worker.ts` when adding new syscalls
71+
- `PATCHED_PROGRAMS` in `wasmvm/c/Makefile` must include all programs that use `host_process` or `host_user` imports (programs linking the patched sysroot)
72+
4773
## Terminology
4874

4975
- use `docs-internal/glossary.md` for canonical definitions of isolate, runtime, bridge, and driver
@@ -124,6 +150,8 @@ Follow the style in `packages/secure-exec/src/index.ts`.
124150
- `docs/system-drivers/browser.mdx` — update when createBrowserDriver options change
125151
- `docs/nodejs-compatibility.mdx` — update when bridge, polyfill, or stub implementations change; keep the Tested Packages section current when adding or removing project-matrix fixtures
126152
- `docs/cloudflare-workers-comparison.mdx` — update when secure-exec capabilities change; bump "Last updated" date
153+
- `docs/posix-compatibility.md` — update when kernel, WasmVM, Node bridge, or Python bridge behavior changes for any POSIX-relevant feature (signals, pipes, FDs, process model, TTY, VFS)
154+
- `docs/wasmvm/supported-commands.md` — update when adding, removing, or changing status of WasmVM commands; keep summary counts current
127155

128156
## Backlog Tracking
129157

0 commit comments

Comments
 (0)