|
| 1 | +name: Compiler |
| 2 | +description: Rust compiler crate. check = shear + clippy; build = wasm build/opt + test + upload. |
| 3 | + |
| 4 | +inputs: |
| 5 | + mode: |
| 6 | + description: "check | build" |
| 7 | + required: true |
| 8 | + github-token: |
| 9 | + description: Token for the tag Release upload (build mode, tags only). |
| 10 | + required: false |
| 11 | + default: "" |
| 12 | + |
| 13 | +runs: |
| 14 | + using: composite |
| 15 | + steps: |
| 16 | + - name: Cache Rust |
| 17 | + uses: Swatinem/rust-cache@v2 |
| 18 | + |
| 19 | + - name: Toolchain (clippy) |
| 20 | + if: inputs.mode == 'check' |
| 21 | + uses: dtolnay/rust-toolchain@stable |
| 22 | + with: |
| 23 | + components: clippy |
| 24 | + |
| 25 | + - name: Install cargo-shear |
| 26 | + if: inputs.mode == 'check' |
| 27 | + shell: bash |
| 28 | + run: cargo install cargo-shear |
| 29 | + |
| 30 | + # Detects declared but unused dependencies across the workspace. |
| 31 | + - name: Shear |
| 32 | + if: inputs.mode == 'check' |
| 33 | + shell: bash |
| 34 | + run: cargo shear |
| 35 | + |
| 36 | + # --no-default-features skips the prebuilt wasm download in build.rs. |
| 37 | + - name: Clippy (host) |
| 38 | + if: inputs.mode == 'check' |
| 39 | + shell: bash |
| 40 | + run: cargo clippy --all-targets --no-default-features -- -D warnings |
| 41 | + |
| 42 | + - name: Install wasm target (check) |
| 43 | + if: inputs.mode == 'check' |
| 44 | + shell: bash |
| 45 | + run: rustup target add wasm32-unknown-unknown |
| 46 | + |
| 47 | + - name: Clippy (wasm) |
| 48 | + if: inputs.mode == 'check' |
| 49 | + shell: bash |
| 50 | + run: cargo clippy --lib --target wasm32-unknown-unknown -p edge-python -p slugify-mod -- -D warnings |
| 51 | + |
| 52 | + # build-std needs nightly plus rust-src. |
| 53 | + - name: Toolchain (nightly) |
| 54 | + if: inputs.mode == 'build' |
| 55 | + uses: dtolnay/rust-toolchain@nightly |
| 56 | + with: |
| 57 | + components: rust-src |
| 58 | + |
| 59 | + - name: Install wasm target (build) |
| 60 | + if: inputs.mode == 'build' |
| 61 | + shell: bash |
| 62 | + run: rustup target add wasm32-unknown-unknown |
| 63 | + |
| 64 | + # apt ships an old binaryen, so fetch the upstream release. |
| 65 | + - name: Install wasm-opt |
| 66 | + if: inputs.mode == 'build' |
| 67 | + shell: bash |
| 68 | + run: | |
| 69 | + curl -sSL https://github.com/WebAssembly/binaryen/releases/download/version_121/binaryen-version_121-x86_64-linux.tar.gz \ |
| 70 | + | tar -xz --strip-components=2 -C /usr/local/bin binaryen-version_121/bin/wasm-opt |
| 71 | + wasm-opt --version |
| 72 | +
|
| 73 | + - name: Build |
| 74 | + if: inputs.mode == 'build' |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + RUSTFLAGS="-Z location-detail=none -Z fmt-debug=none -Z unstable-options -C panic=immediate-abort" \ |
| 78 | + cargo +nightly build \ |
| 79 | + --target wasm32-unknown-unknown \ |
| 80 | + --lib \ |
| 81 | + --release \ |
| 82 | + -p edge-python \ |
| 83 | + -Z build-std=std,panic_abort |
| 84 | +
|
| 85 | + - name: Size (unoptimized) |
| 86 | + if: inputs.mode == 'build' |
| 87 | + shell: bash |
| 88 | + run: ls -lh target/wasm32-unknown-unknown/release/compiler_lib.wasm |
| 89 | + |
| 90 | + # Two passes: -Oz with traps-never-happen, then reflatten for a fresh CFG. |
| 91 | + - name: Optimize |
| 92 | + if: inputs.mode == 'build' |
| 93 | + shell: bash |
| 94 | + run: | |
| 95 | + INPUT=target/wasm32-unknown-unknown/release/compiler_lib.wasm |
| 96 | +
|
| 97 | + wasm-opt -Oz --converge \ |
| 98 | + --generate-global-effects \ |
| 99 | + --strip-debug --strip-producers \ |
| 100 | + --enable-bulk-memory-opt \ |
| 101 | + --enable-nontrapping-float-to-int \ |
| 102 | + --enable-sign-ext \ |
| 103 | + -tnh \ |
| 104 | + -o /tmp/wasm_stage1.wasm "$INPUT" |
| 105 | +
|
| 106 | + wasm-opt --flatten --rereloop -Oz -Oz \ |
| 107 | + --enable-bulk-memory-opt \ |
| 108 | + --enable-nontrapping-float-to-int \ |
| 109 | + --enable-sign-ext \ |
| 110 | + -o "$INPUT" /tmp/wasm_stage1.wasm |
| 111 | +
|
| 112 | + rm /tmp/wasm_stage1.wasm |
| 113 | +
|
| 114 | + - name: Size (optimized) |
| 115 | + if: inputs.mode == 'build' |
| 116 | + shell: bash |
| 117 | + run: ls -lh target/wasm32-unknown-unknown/release/compiler_lib.wasm |
| 118 | + |
| 119 | + - name: Test |
| 120 | + if: inputs.mode == 'build' |
| 121 | + shell: bash |
| 122 | + run: cargo test -p edge-python --no-default-features |
| 123 | + |
| 124 | + - name: Upload wasm artifact |
| 125 | + if: inputs.mode == 'build' |
| 126 | + uses: actions/upload-artifact@v6 |
| 127 | + with: |
| 128 | + name: compiler_lib_wasm |
| 129 | + path: target/wasm32-unknown-unknown/release/compiler_lib.wasm |
| 130 | + retention-days: 1 |
| 131 | + |
| 132 | + - name: Upload WASM Release |
| 133 | + if: inputs.mode == 'build' && startsWith(github.ref, 'refs/tags/') |
| 134 | + uses: softprops/action-gh-release@v2 |
| 135 | + with: |
| 136 | + token: ${{ inputs.github-token }} |
| 137 | + files: target/wasm32-unknown-unknown/release/compiler_lib.wasm |
| 138 | + fail_on_unmatched_files: true |
| 139 | + generate_release_notes: true |
0 commit comments