Skip to content

build: add wasm targets for policy module and WASI linter - #96

Open
starkross wants to merge 1 commit into
mainfrom
feat/wasm-build
Open

build: add wasm targets for policy module and WASI linter#96
starkross wants to merge 1 commit into
mainfrom
feat/wasm-build

Conversation

@starkross

Copy link
Copy Markdown
Owner

Adds two make targets. Both were run and verified locally (go1.26.1, opa 1.17.0, macOS arm64).

make wasm-policydist/wasm/policy.wasm (192K)

Compiles the Rego rules to a standalone wasm module using OPA's Rego→wasm compiler. Policies only — no interpreter, no Go runtime — so any OPA-ABI host (JS, Rust, Python, Go, …) can evaluate them.

Verified by loading the built artifact with @open-policy-agent/opa-wasm and evaluating testdata/bad.yaml: identical 6 findings (OTEL-001, 003, 010, 011, 015, 033) to the native binary, same rule IDs and messages.

load+instantiate  16.2 ms
first eval         2.78 ms
steady-state       0.057 ms

make wasmdist/wasm/augur.wasm (44M)

The whole linter — CLI, YAML loading, env expansion, embedded OPA interpreter — as a WASI preview 1 module, runnable under wasmtime, wasmer or node. --format json output is byte-identical to the native binary. Large but self-contained; fine for server or CI embedding, too heavy for a browser.

Why both

The size gap is the interesting part and the reason the targets are named separately rather than one wasm:

build raw brotli
policy.wasm 195,435 54 KB
augur.wasm (wasip1) 46,593,356 6.04 MB
Go hello-world (runtime floor) 1,646,290 371 KB

Stripping the entire CLI and cobra from the wasip1 build saved 1.6M of 46.6M — the bundled OPA interpreter is ~96% of it, and TinyGo can't compile OPA (reflection). So the two artifacts aren't small-and-large versions of one thing; they're for different consumers, and policy.wasm is the only viable browser payload.

Notes

  • Both write to dist/wasm/, already covered by .gitignore and already removed by make clean (verified).
  • wasm-policy guards on opa being installed, matching the existing conftest/regal idiom.
  • --ignore '*_test.rego' matters: without it opa build sweeps the ~90 test rules in as entrypoints, inflating the module to 261K.
  • No CI wiring here — happy to add a job that builds and size-checks these if you want it.

Add two make targets, both verified locally on go1.26.1 / opa 1.17.0.

wasm-policy compiles the Rego rules to a standalone module with OPA's
Rego->wasm compiler. It carries the policies only -- no interpreter, no
Go runtime -- so any OPA-ABI host (JS, Rust, Python, Go) can evaluate
them. 192K, versus 44M for the full linter, because the bundled OPA
interpreter is ~96% of that build. This is the artifact to ship to a
browser.

wasm builds the whole linter -- CLI, YAML loading, env expansion and the
embedded interpreter -- as a WASI preview 1 module for wasmtime, wasmer
or node. Self-contained but large; fine for server or CI embedding.

Both write to dist/wasm/, which `make clean` already removes and
.gitignore already covers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant