|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | | -SRC_DIR="${1:-vendor/circt/build-wasm/bin}" |
5 | | -DST_DIR="${2:-static/circt}" |
6 | | -UVM_SRC_DIR="${3:-vendor/circt/lib/Runtime/uvm-core/src}" |
| 4 | +PUBLISH=0 |
| 5 | +POSITIONAL=() |
| 6 | +for arg in "$@"; do |
| 7 | + case "$arg" in |
| 8 | + --publish) PUBLISH=1 ;; |
| 9 | + *) POSITIONAL+=("$arg") ;; |
| 10 | + esac |
| 11 | +done |
| 12 | + |
| 13 | +SRC_DIR="${POSITIONAL[0]:-vendor/circt/build-wasm/bin}" |
| 14 | +DST_DIR="${POSITIONAL[1]:-static/circt}" |
| 15 | +UVM_SRC_DIR="${POSITIONAL[2]:-vendor/circt/lib/Runtime/uvm-core/src}" |
7 | 16 | UVM_DST_DIR="$DST_DIR/uvm-core/src" |
8 | 17 | UVM_MANIFEST_PATH="$DST_DIR/uvm-core/uvm-manifest.json" |
9 | 18 |
|
@@ -64,16 +73,24 @@ for tool in "${TOOLS[@]}"; do |
64 | 73 | patch_callmain_export "$DST_DIR/$tool.js" |
65 | 74 | done |
66 | 75 |
|
67 | | -# Sync VPI-capable sim if present (built with -DCIRCT_SIM_WASM_VPI=ON). |
| 76 | +# Sync VPI-capable sim. circt-sim already includes Asyncify + VPI exports |
| 77 | +# unconditionally in Emscripten builds, so use it as the VPI binary when a |
| 78 | +# separately-named circt-sim-vpi build is not present in the source dir. |
68 | 79 | if [ -f "$SRC_DIR/$VPI_TOOL.js" ] && [ -f "$SRC_DIR/$VPI_TOOL.wasm" ]; then |
69 | 80 | cp -f "$SRC_DIR/$VPI_TOOL.js" "$DST_DIR/$VPI_TOOL.js" |
70 | 81 | cp -f "$SRC_DIR/$VPI_TOOL.wasm" "$DST_DIR/$VPI_TOOL.wasm" |
71 | | - patch_callmain_export "$DST_DIR/$VPI_TOOL.js" |
72 | | - HAVE_VPI=1 |
| 82 | +elif [ -f "$SRC_DIR/circt-sim.js" ] && [ -f "$SRC_DIR/circt-sim.wasm" ]; then |
| 83 | + echo "Note: $VPI_TOOL not in $SRC_DIR — using circt-sim as VPI-capable fallback" >&2 |
| 84 | + cp -f "$SRC_DIR/circt-sim.js" "$DST_DIR/$VPI_TOOL.js" |
| 85 | + cp -f "$SRC_DIR/circt-sim.wasm" "$DST_DIR/$VPI_TOOL.wasm" |
73 | 86 | else |
74 | | - echo "Note: $VPI_TOOL not found in $SRC_DIR — skipping (cocotb lessons will be unavailable)" >&2 |
| 87 | + echo "Note: $VPI_TOOL not found and no circt-sim fallback — skipping (cocotb lessons will be unavailable)" >&2 |
75 | 88 | HAVE_VPI=0 |
76 | 89 | fi |
| 90 | +if [ "${HAVE_VPI:-}" != "0" ]; then |
| 91 | + patch_callmain_export "$DST_DIR/$VPI_TOOL.js" |
| 92 | + HAVE_VPI=1 |
| 93 | +fi |
77 | 94 |
|
78 | 95 | if [ ! -d "$UVM_SRC_DIR" ]; then |
79 | 96 | echo "Missing full UVM source directory: $UVM_SRC_DIR" >&2 |
|
257 | 274 | echo "Synced full UVM source files:" |
258 | 275 | echo " source dir: $UVM_DST_DIR" |
259 | 276 | echo " manifest: $UVM_MANIFEST_PATH" |
| 277 | + |
| 278 | +# --publish: upload artifacts to the circt-wasm GitHub release and update the |
| 279 | +# toolchain lock so CI rebuilds from the same commit. |
| 280 | +if [ "$PUBLISH" -eq 1 ]; then |
| 281 | + ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 282 | + source "$ROOT_DIR/scripts/toolchain.lock.sh" |
| 283 | + |
| 284 | + CIRCT_COMMIT="$(git -C "${CIRCT_DIR:-vendor/circt}" rev-parse HEAD 2>/dev/null || true)" |
| 285 | + if [ -z "$CIRCT_COMMIT" ]; then |
| 286 | + echo "--publish: could not determine CIRCT commit from ${CIRCT_DIR:-vendor/circt}" >&2 |
| 287 | + exit 1 |
| 288 | + fi |
| 289 | + |
| 290 | + # Bundle UVM sources for the release asset. |
| 291 | + UVM_BUNDLE="$(mktemp /tmp/uvm-core.XXXXXX.tar.gz)" |
| 292 | + tar -czf "$UVM_BUNDLE" -C "$DST_DIR" uvm-core |
| 293 | + echo "Created UVM bundle: $UVM_BUNDLE" |
| 294 | + |
| 295 | + # Upload all artifacts, replacing existing assets on the release. |
| 296 | + RELEASE_ASSETS=( |
| 297 | + "$DST_DIR/circt-bmc.js" "$DST_DIR/circt-bmc.wasm" |
| 298 | + "$DST_DIR/circt-sim.js" "$DST_DIR/circt-sim.wasm" |
| 299 | + "$DST_DIR/circt-verilog.js" "$DST_DIR/circt-verilog.wasm" |
| 300 | + "$UVM_BUNDLE" |
| 301 | + ) |
| 302 | + if [ "$HAVE_VPI" -eq 1 ]; then |
| 303 | + RELEASE_ASSETS+=("$DST_DIR/$VPI_TOOL.js" "$DST_DIR/$VPI_TOOL.wasm") |
| 304 | + fi |
| 305 | + |
| 306 | + echo "Uploading to GitHub release 'circt-wasm'..." |
| 307 | + gh release upload circt-wasm "${RELEASE_ASSETS[@]}" --clobber |
| 308 | + rm -f "$UVM_BUNDLE" |
| 309 | + echo "GitHub release updated." |
| 310 | + |
| 311 | + # Update toolchain lock to the current CIRCT commit. |
| 312 | + LOCK_FILE="$ROOT_DIR/scripts/toolchain.lock.sh" |
| 313 | + sed -i.bak "s|^readonly CIRCT_REF_LOCKED=.*|readonly CIRCT_REF_LOCKED=\"$CIRCT_COMMIT\"|" "$LOCK_FILE" |
| 314 | + rm -f "$LOCK_FILE.bak" |
| 315 | + echo "Updated CIRCT_REF_LOCKED to $CIRCT_COMMIT in $LOCK_FILE" |
| 316 | +fi |
0 commit comments