|
| 1 | +--- |
| 2 | +name: ast-plugins |
| 3 | + |
| 4 | +# Builds the native-AST WASM plugins (Rust/syn, Python/ruff, Go/go-parser) from |
| 5 | +# the source under plugins/ast, smoke-tests each against the host ABI, and — on a |
| 6 | +# `plugins-v*` tag — publishes the .wasm files (+ SHA256SUMS) as release assets. |
| 7 | +# |
| 8 | +# The plugins are a self-contained, polyglot "closed box": the Node/TS package |
| 9 | +# neither builds nor depends on them (they're excluded from the npm tarball). |
| 10 | +# This workflow is the ONLY thing that compiles them, so it runs on every PR that |
| 11 | +# touches plugins/ast to guard against source rot. wasm is platform-independent, |
| 12 | +# so one artifact per plugin serves every OS/arch — no build matrix needed. |
| 13 | +# |
| 14 | +# Compatibility is governed by the ABI `contractVersion()`, not `codesight`'s npm |
| 15 | +# version, so plugins are released independently via their own `plugins-v*` tags. |
| 16 | +# |
| 17 | +# Note: Cargo.lock is committed and `cargo build --locked` enforces it, so Rust |
| 18 | +# builds are reproducible (the ruff git rev is pinned; the lockfile freezes all |
| 19 | +# transitive deps) and CI fails if the lockfile is stale. |
| 20 | + |
| 21 | +on: |
| 22 | + pull_request: |
| 23 | + paths: |
| 24 | + - plugins/ast/** |
| 25 | + - .github/workflows/ast-plugins.yml |
| 26 | + |
| 27 | + push: |
| 28 | + tags: |
| 29 | + - plugins-v* |
| 30 | + |
| 31 | + workflow_dispatch: |
| 32 | + |
| 33 | +permissions: |
| 34 | + contents: read |
| 35 | + |
| 36 | +jobs: |
| 37 | + build: |
| 38 | + name: Build & smoke-test plugins |
| 39 | + runs-on: ubuntu-latest |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Set up Rust (wasm32-unknown-unknown) |
| 44 | + uses: dtolnay/rust-toolchain@stable |
| 45 | + with: |
| 46 | + targets: wasm32-unknown-unknown |
| 47 | + |
| 48 | + - name: Cache cargo build |
| 49 | + uses: swatinem/rust-cache@v2 |
| 50 | + with: |
| 51 | + workspaces: plugins/ast |
| 52 | + |
| 53 | + - name: Set up Go |
| 54 | + uses: actions/setup-go@v5 |
| 55 | + with: |
| 56 | + go-version: "1.24" |
| 57 | + cache: false # stdlib-only module, no go.sum to key a dependency cache on |
| 58 | + |
| 59 | + - uses: pnpm/action-setup@v4 |
| 60 | + with: |
| 61 | + version: 9 |
| 62 | + |
| 63 | + - uses: actions/setup-node@v4 |
| 64 | + with: |
| 65 | + node-version: "20" |
| 66 | + |
| 67 | + - name: Install Node deps & build host |
| 68 | + run: | |
| 69 | + pnpm install |
| 70 | + pnpm build |
| 71 | +
|
| 72 | + # warnings = "deny" is wired into each crate, so any warning fails here. |
| 73 | + - name: Build Rust plugins (syn / ruff → wasm) |
| 74 | + working-directory: plugins/ast |
| 75 | + run: cargo build --locked --release --target wasm32-unknown-unknown |
| 76 | + |
| 77 | + # -ldflags="-s -w" drops the symbol table and DWARF (Go has no `strip = true` |
| 78 | + # equivalent); the wasm-opt pass below shrinks all three further. |
| 79 | + - name: Build Go plugin (go/parser → wasm) |
| 80 | + working-directory: plugins/ast/golang |
| 81 | + run: GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -ldflags="-s -w" -o codesight-go-ast.wasm . |
| 82 | + |
| 83 | + # Stage under the host's discovery filename template (^codesight-<lang>-ast.wasm$). |
| 84 | + # cargo emits underscores (codesight_rust_ast.wasm) and forbids hyphens in lib |
| 85 | + # target names, so the rename lives here in CI — never in the repo build. |
| 86 | + - name: Stage artifacts |
| 87 | + run: >- |
| 88 | + mkdir -p dist-plugins; |
| 89 | + cp |
| 90 | + plugins/ast/target/wasm32-unknown-unknown/release/codesight_rust_ast.wasm |
| 91 | + dist-plugins/codesight-rust-ast.wasm; |
| 92 | + cp |
| 93 | + plugins/ast/target/wasm32-unknown-unknown/release/codesight_python_ast.wasm |
| 94 | + dist-plugins/codesight-python-ast.wasm; |
| 95 | + cp |
| 96 | + plugins/ast/golang/codesight-go-ast.wasm |
| 97 | + dist-plugins/codesight-go-ast.wasm; |
| 98 | + ls -la dist-plugins |
| 99 | +
|
| 100 | + - name: Install wasm-opt (Binaryen) |
| 101 | + run: sudo apt-get update && sudo apt-get install -y binaryen |
| 102 | + |
| 103 | + # WASM-specific whole-module size pass. -Oz optimizes for size. The toolchains |
| 104 | + # emit no target_features section but do use bulk-memory (memory.copy/fill), so |
| 105 | + # we enable exactly the post-MVP features they need — all long supported by the |
| 106 | + # Node host's V8. The smoke test below runs against these optimized binaries, |
| 107 | + # so we validate exactly what ships. |
| 108 | + - name: Optimize wasm (wasm-opt -Oz) |
| 109 | + working-directory: dist-plugins |
| 110 | + run: | |
| 111 | + for f in *.wasm; do |
| 112 | + before=$(wc -c < "$f") |
| 113 | + wasm-opt -Oz \ |
| 114 | + --enable-bulk-memory --enable-sign-ext \ |
| 115 | + --enable-mutable-globals --enable-nontrapping-float-to-int \ |
| 116 | + "$f" -o "$f" |
| 117 | + echo "$f: ${before} -> $(wc -c < "$f") bytes" |
| 118 | + done |
| 119 | +
|
| 120 | + # Load each optimized plugin through the real host and round-trip a fixture to |
| 121 | + # catch host<->plugin drift bidirectionally (mirrors the reference-plugin guard). |
| 122 | + - name: Smoke-test ABI against the host |
| 123 | + env: |
| 124 | + PLUGIN_DIR: dist-plugins |
| 125 | + run: | |
| 126 | + cat > "${RUNNER_TEMP}/smoke.mjs" <<'JS' |
| 127 | + import assert from 'node:assert/strict'; |
| 128 | + import { pathToFileURL } from 'node:url'; |
| 129 | +
|
| 130 | + const host = pathToFileURL(`${process.cwd()}/dist/wasm/plugin-host.js`).href; |
| 131 | + const { loadPlugin } = await import(host); |
| 132 | + const dir = process.env.PLUGIN_DIR; |
| 133 | +
|
| 134 | + const fixtures = { |
| 135 | + rust: '#[get("/health")]\nfn handler() {}', |
| 136 | + python: 'from fastapi import FastAPI\napp = FastAPI()\n@app.get("/health")\ndef handler(): ...', |
| 137 | + go: 'package main\nfunc register(r *gin.Engine) { r.GET("/health", nil) }', |
| 138 | + }; |
| 139 | +
|
| 140 | + let failed = 0; |
| 141 | + for (const [lang, src] of Object.entries(fixtures)) { |
| 142 | + try { |
| 143 | + const plugin = loadPlugin(lang, [dir]); |
| 144 | + assert.ok(plugin, `${lang}: failed to load`); |
| 145 | + assert.equal(plugin.metadata?.languageId, lang, `${lang}: describe() languageId mismatch`); |
| 146 | + const routes = plugin.routes?.(src) ?? []; |
| 147 | + assert.ok(routes.length > 0, `${lang}: expected at least one route from the fixture`); |
| 148 | + console.log(`ok: ${lang} — ${routes.length} route(s), languageId=${plugin.metadata.languageId}`); |
| 149 | + } catch (error) { |
| 150 | + console.error(`FAIL: ${error.message}`); |
| 151 | + failed = 1; |
| 152 | + } |
| 153 | + } |
| 154 | + process.exit(failed); |
| 155 | + JS |
| 156 | + node "${RUNNER_TEMP}/smoke.mjs" |
| 157 | +
|
| 158 | + - name: Generate checksums |
| 159 | + working-directory: dist-plugins |
| 160 | + run: sha256sum *.wasm | tee SHA256SUMS |
| 161 | + |
| 162 | + - uses: actions/upload-artifact@v4 |
| 163 | + with: |
| 164 | + name: ast-plugins |
| 165 | + path: dist-plugins/ |
| 166 | + if-no-files-found: error |
| 167 | + |
| 168 | + release: |
| 169 | + name: Publish release assets |
| 170 | + needs: build |
| 171 | + if: startsWith(github.ref, 'refs/tags/plugins-v') |
| 172 | + runs-on: ubuntu-latest |
| 173 | + permissions: |
| 174 | + contents: write |
| 175 | + steps: |
| 176 | + - uses: actions/download-artifact@v4 |
| 177 | + with: |
| 178 | + name: ast-plugins |
| 179 | + path: dist-plugins |
| 180 | + |
| 181 | + - name: Publish to the GitHub Release |
| 182 | + uses: softprops/action-gh-release@v2 |
| 183 | + with: |
| 184 | + files: | |
| 185 | + dist-plugins/*.wasm |
| 186 | + dist-plugins/SHA256SUMS |
0 commit comments