|
| 1 | +name: cli build |
| 2 | + |
| 3 | +# Build prebuilt `burn` binaries for every platform we publish to npm under |
| 4 | +# `@relayburn/cli-*`. PRs validate the matrix; tags / manual dispatch *would* |
| 5 | +# publish, but the publish step is stubbed off for now — the cutover publish |
| 6 | +# workflow integration lands as a follow-up to this PR. |
| 7 | +# |
| 8 | +# Mirrors `.github/workflows/napi-build.yml`: the napi-rs SDK uses the same |
| 9 | +# umbrella + per-platform-package shape, just with `.node` artifacts instead |
| 10 | +# of native executables. |
| 11 | + |
| 12 | +on: |
| 13 | + pull_request: |
| 14 | + paths: |
| 15 | + - 'crates/relayburn-cli/**' |
| 16 | + - 'crates/relayburn-sdk/**' |
| 17 | + - 'Cargo.toml' |
| 18 | + - 'Cargo.lock' |
| 19 | + - 'rust-toolchain.toml' |
| 20 | + - 'packages/relayburn/**' |
| 21 | + - '.github/workflows/cli-build.yml' |
| 22 | + push: |
| 23 | + branches: [main] |
| 24 | + paths: |
| 25 | + - 'crates/relayburn-cli/**' |
| 26 | + - 'crates/relayburn-sdk/**' |
| 27 | + - 'Cargo.toml' |
| 28 | + - 'Cargo.lock' |
| 29 | + - 'rust-toolchain.toml' |
| 30 | + - 'packages/relayburn/**' |
| 31 | + - '.github/workflows/cli-build.yml' |
| 32 | + workflow_dispatch: |
| 33 | + inputs: |
| 34 | + publish: |
| 35 | + description: 'Publish prebuilt artifacts to npm under the `next` tag (stubbed; full wiring lands with the cutover publish workflow)' |
| 36 | + type: boolean |
| 37 | + default: false |
| 38 | + |
| 39 | +permissions: |
| 40 | + contents: read |
| 41 | + |
| 42 | +concurrency: |
| 43 | + group: cli-build-${{ github.ref }} |
| 44 | + cancel-in-progress: true |
| 45 | + |
| 46 | +jobs: |
| 47 | + build: |
| 48 | + name: build ${{ matrix.short }} |
| 49 | + strategy: |
| 50 | + fail-fast: false |
| 51 | + matrix: |
| 52 | + include: |
| 53 | + - target: x86_64-apple-darwin |
| 54 | + os: macos-15-intel |
| 55 | + short: darwin-x64 |
| 56 | + - target: aarch64-apple-darwin |
| 57 | + os: macos-14 |
| 58 | + short: darwin-arm64 |
| 59 | + - target: x86_64-unknown-linux-gnu |
| 60 | + os: ubuntu-latest |
| 61 | + short: linux-x64-gnu |
| 62 | + - target: aarch64-unknown-linux-gnu |
| 63 | + os: ubuntu-latest |
| 64 | + short: linux-arm64-gnu |
| 65 | + runs-on: ${{ matrix.os }} |
| 66 | + steps: |
| 67 | + - name: Checkout |
| 68 | + uses: actions/checkout@v6 |
| 69 | + |
| 70 | + - name: Setup Rust toolchain |
| 71 | + # rust-toolchain.toml at the repo root pins the channel + components. |
| 72 | + run: | |
| 73 | + rustup toolchain install |
| 74 | + rustup target add ${{ matrix.target }} |
| 75 | +
|
| 76 | + - name: Install aarch64-linux cross toolchain (linux-arm64 only) |
| 77 | + if: matrix.target == 'aarch64-unknown-linux-gnu' |
| 78 | + # `libsqlite3-sys` (a transitive dep via `rusqlite`) compiles bundled |
| 79 | + # SQLite C source via `cc-rs`, which probes for `aarch64-linux-gnu-gcc`. |
| 80 | + # Same setup as `napi-build.yml`'s aarch64-linux leg. |
| 81 | + run: | |
| 82 | + sudo apt-get update |
| 83 | + sudo apt-get install -y gcc-aarch64-linux-gnu |
| 84 | +
|
| 85 | + - name: Cache cargo registry + target |
| 86 | + uses: actions/cache@v4 |
| 87 | + with: |
| 88 | + path: | |
| 89 | + ~/.cargo/registry |
| 90 | + ~/.cargo/git |
| 91 | + target |
| 92 | + key: cargo-cli-${{ runner.os }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', 'rust-toolchain.toml') }} |
| 93 | + restore-keys: | |
| 94 | + cargo-cli-${{ runner.os }}-${{ matrix.target }}- |
| 95 | + cargo-cli-${{ runner.os }}- |
| 96 | +
|
| 97 | + - name: Build burn binary for ${{ matrix.target }} |
| 98 | + # The binary name is `burn` (the `[[bin]]` rename in |
| 99 | + # `crates/relayburn-cli/Cargo.toml`); the crate is `relayburn-cli`. |
| 100 | + # CC_/linker env vars only take effect on the aarch64-linux leg |
| 101 | + # (cargo ignores per-target vars when host == target); native legs |
| 102 | + # are unaffected. |
| 103 | + env: |
| 104 | + CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc |
| 105 | + CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++ |
| 106 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
| 107 | + run: | |
| 108 | + cargo build --release --target ${{ matrix.target }} --bin burn -p relayburn-cli |
| 109 | +
|
| 110 | + - name: Strip binary |
| 111 | + # Stripping cuts ~half the size off a release `burn` (debug info, |
| 112 | + # symbol tables that aren't needed at runtime). On macOS use `-x` to |
| 113 | + # strip non-global symbols only — fully stripping a Mach-O binary |
| 114 | + # breaks codesigning. On linux, default `strip` is fine; when |
| 115 | + # cross-compiling for aarch64 we use the matching cross-strip. |
| 116 | + run: | |
| 117 | + BIN="target/${{ matrix.target }}/release/burn" |
| 118 | + case "${{ matrix.target }}" in |
| 119 | + *-apple-darwin) |
| 120 | + strip -x "$BIN" |
| 121 | + ;; |
| 122 | + aarch64-unknown-linux-gnu) |
| 123 | + aarch64-linux-gnu-strip "$BIN" |
| 124 | + ;; |
| 125 | + *-unknown-linux-gnu) |
| 126 | + strip "$BIN" |
| 127 | + ;; |
| 128 | + esac |
| 129 | + ls -lh "$BIN" |
| 130 | +
|
| 131 | + - name: Stage binary into platform package |
| 132 | + # Mirror the layout the publish step will rely on: |
| 133 | + # `packages/relayburn/npm/<short>/bin/burn`. The directory is |
| 134 | + # gitignored at rest; the artifact upload below is what survives |
| 135 | + # the matrix run for the publish job to download. |
| 136 | + run: | |
| 137 | + mkdir -p packages/relayburn/npm/${{ matrix.short }}/bin |
| 138 | + cp target/${{ matrix.target }}/release/burn packages/relayburn/npm/${{ matrix.short }}/bin/burn |
| 139 | + chmod +x packages/relayburn/npm/${{ matrix.short }}/bin/burn |
| 140 | +
|
| 141 | + - name: Upload artifact |
| 142 | + uses: actions/upload-artifact@v4 |
| 143 | + with: |
| 144 | + name: relayburn-cli-${{ matrix.short }} |
| 145 | + path: packages/relayburn/npm/${{ matrix.short }}/bin/burn |
| 146 | + if-no-files-found: error |
| 147 | + retention-days: 7 |
| 148 | + |
| 149 | + - name: Smoke test (`burn --help`) |
| 150 | + # Native legs only. The aarch64-linux leg cross-compiles on an x64 |
| 151 | + # host so the runner's interpreter cannot execute the binary. |
| 152 | + if: matrix.target != 'aarch64-unknown-linux-gnu' |
| 153 | + run: | |
| 154 | + set -euo pipefail |
| 155 | + packages/relayburn/npm/${{ matrix.short }}/bin/burn --help |
| 156 | + packages/relayburn/npm/${{ matrix.short }}/bin/burn --version |
| 157 | +
|
| 158 | + smoke_dir="$(mktemp -d)" |
| 159 | + umbrella_dir="$(mktemp -d)" |
| 160 | + trap 'rm -rf "$smoke_dir" "$umbrella_dir"' EXIT |
| 161 | + npm install --prefix "$smoke_dir" --no-save --omit=optional \ |
| 162 | + --ignore-scripts --no-audit --no-fund \ |
| 163 | + ./packages/relayburn/npm/${{ matrix.short }} |
| 164 | + "$smoke_dir/node_modules/.bin/burn" --help |
| 165 | + "$smoke_dir/node_modules/.bin/burn" --version |
| 166 | +
|
| 167 | + npm install --prefix "$umbrella_dir" --no-save --omit=optional \ |
| 168 | + --ignore-scripts --no-audit --no-fund \ |
| 169 | + ./packages/relayburn |
| 170 | + NODE_PATH="$smoke_dir/node_modules" "$umbrella_dir/node_modules/.bin/burn" --help |
| 171 | + NODE_PATH="$smoke_dir/node_modules" "$umbrella_dir/node_modules/.bin/burn" --version |
| 172 | +
|
| 173 | + publish: |
| 174 | + # Stub. Real publish wiring lands as a follow-up that integrates with |
| 175 | + # `.github/workflows/publish.yml`: download the matrix artifacts, drop |
| 176 | + # each into the right `packages/relayburn/npm/<short>/bin/` directory, |
| 177 | + # and `npm publish` the umbrella + each per-platform package via OIDC |
| 178 | + # trusted publisher. Until then, calling `workflow_dispatch` with |
| 179 | + # `publish: true` exercises the artifact download path so we catch |
| 180 | + # wiring errors early without actually pushing to npm. |
| 181 | + needs: build |
| 182 | + if: github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true' |
| 183 | + runs-on: ubuntu-latest |
| 184 | + permissions: |
| 185 | + contents: read |
| 186 | + id-token: write |
| 187 | + steps: |
| 188 | + - name: Checkout |
| 189 | + uses: actions/checkout@v6 |
| 190 | + |
| 191 | + - name: Download all artifacts |
| 192 | + uses: actions/download-artifact@v4 |
| 193 | + with: |
| 194 | + path: packages/relayburn/npm-artifacts |
| 195 | + |
| 196 | + - name: Inspect artifacts (publish stub) |
| 197 | + run: | |
| 198 | + echo 'Publish step is currently a stub. Full wiring lands in the cutover publish.yml integration follow-up.' |
| 199 | + ls -lahR packages/relayburn/npm-artifacts || true |
0 commit comments