build: add wasm targets for policy module and WASI linter - #96
Open
starkross wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds two
maketargets. Both were run and verified locally (go1.26.1, opa 1.17.0, macOS arm64).make wasm-policy→dist/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-wasmand evaluatingtestdata/bad.yaml: identical 6 findings (OTEL-001, 003, 010, 011, 015, 033) to the native binary, same rule IDs and messages.make wasm→dist/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 jsonoutput 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:policy.wasmaugur.wasm(wasip1)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.wasmis the only viable browser payload.Notes
dist/wasm/, already covered by.gitignoreand already removed bymake clean(verified).wasm-policyguards onopabeing installed, matching the existingconftest/regalidiom.--ignore '*_test.rego'matters: without itopa buildsweeps the ~90 test rules in as entrypoints, inflating the module to 261K.