diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aceb473..e06ba7e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -46,6 +46,8 @@ jobs: os: macos-14 - target: x86_64-unknown-linux-musl os: ubuntu-latest + - target: aarch64-unknown-linux-musl + os: ubuntu-latest runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -55,16 +57,69 @@ jobs: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" - - name: Add target + musl tooling - run: | - rustup target add ${{ matrix.target }} - if [ "${{ matrix.target }}" = "x86_64-unknown-linux-musl" ]; then - sudo apt-get update && sudo apt-get install -y musl-tools - fi + - name: Add target + run: rustup target add ${{ matrix.target }} - - name: Build + # Both Linux targets go through zig rather than through apt's musl-tools. + # `tree-sitter` and `tree-sitter-typescript` compile C with the `cc` crate, + # so `rustup target add` alone cannot produce an aarch64 binary — a real + # cross C toolchain is required, and Ubuntu ships none for aarch64 musl. + # zig is one, for both arches, which is also why the x86_64 leg moved onto + # it: one toolchain for Linux beats a working one plus a second one. + - name: Install zig cross toolchain + if: contains(matrix.target, 'linux') + run: | + # `--break-system-packages` is required from pip 23 (PEP 668) and is an + # unknown flag before it, so try the plain form first. + python3 -m pip install --user ziglang \ + || python3 -m pip install --user --break-system-packages ziglang + cargo install --locked cargo-zigbuild + + - name: Build (Linux, cross via zig) + if: contains(matrix.target, 'linux') + run: cargo zigbuild --release --locked --target ${{ matrix.target }} + + - name: Build (macOS) + if: contains(matrix.target, 'darwin') run: cargo build --release --locked --target ${{ matrix.target }} + # Run the artifact wherever the runner can actually execute it, and say so + # where it cannot. A binary that links and will not start is the failure a + # release pipeline must not leave for a user's terminal to find. + # + # A matching architecture always can. An x86_64 macOS binary on the arm64 + # macOS runners can too — through Rosetta, which is a system component + # shared by every user on the host, so the runner account inherits it. It + # is probed rather than assumed: a hosted runner may not have it, and a + # smoke that hard-failed there would block a release over the runner's + # configuration rather than over the binary. + # + # Across the two forges that leaves nothing unexecuted. Gitea's + # `ubuntu-latest` is arm64 Linux (containers in a colima VM on the macOS + # host), so it runs the aarch64 binary; GitHub's is x86_64 and runs the + # other. Both macOS binaries run on either forge's arm64 macOS runner. + - name: Smoke the binary + shell: bash + run: | + target='${{ matrix.target }}' + arch='${{ runner.arch }}' + bin="./target/$target/release/matcha" + runnable=no + case "$target:$arch" in + aarch64-*:ARM64|x86_64-*:X64) runnable=yes ;; + x86_64-apple-darwin:ARM64) + # An `if` rather than `[ … ] && …`: under `set -e` the AND-list's + # failure is the case branch's exit status, and whether that ends + # the step is a subtlety of the shell rather than a decision. A + # missing Rosetta must skip the smoke, never fail the release. + if [ -d /Library/Apple/usr/libexec/oah ]; then runnable=yes; fi ;; + esac + if [ "$runnable" = yes ]; then + "$bin" --version + else + echo "::notice::smoke skipped: this $arch runner cannot execute $target" + fi + - name: Package run: | TAR="matcha-${{ matrix.target }}.tar.gz" @@ -87,6 +142,36 @@ jobs: matcha-${{ matrix.target }}.tar.gz matcha-${{ matrix.target }}.tar.gz.sha256 + # Guarantees the arm64 Linux binary is executed before it reaches anyone. + # + # The `Smoke the binary` step above runs each artifact only where the runner + # can, which depends on what `ubuntu-latest` resolves to on the forge that + # fired — so whether the aarch64 Linux binary gets started is a property of the + # runner pool rather than of the pipeline. This job removes that dependency: + # it pins an arm64 Linux runner, so the answer is the same on every release. + # + # GitHub offers such runners and Gitea does not, and a job pinned to a label a + # forge lacks would queue there forever — hence the same `server_url` guard + # `publish-crate` below already uses, which skips the job before a runner is + # ever looked for. + # + # It goes through `install.sh` rather than running the binary directly, so the + # same job also covers the installer's arm64 branch and its checksum + # verification against the release assets exactly as a user receives them. + verify-linux-arm64: + needs: build + if: ${{ github.server_url == 'https://github.com' }} + runs-on: ubuntu-24.04-arm + steps: + - uses: actions/checkout@v4 + - name: Install the published arm64 binary and run it + run: | + set -eu + test "$(uname -m)" = aarch64 || { echo "expected an arm64 runner, got $(uname -m)"; exit 1; } + MATCHA_VERSION="$GITHUB_REF_NAME" MATCHA_INSTALL_DIR="$PWD/.bin" sh ./install.sh + "$PWD/.bin/matcha" --version + "$PWD/.bin/matcha" --help > /dev/null + # crates.io = production only. # crates.io = production only, via OIDC Trusted Publishing (no CARGO_TOKEN). # Requires a trusted publisher configured on crates.io (Expressive-Tea/matcha, release.yml). diff --git a/CHANGELOG.md b/CHANGELOG.md index 29b9df3..67a0e14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,6 +104,25 @@ is pinned to is `CORE_VERSION` in `src/template.rs`, and each entry below says w was `TS2868: Cannot find name 'Bun'` — meaning `tsc --noEmit`, and therefore `matcha create --check`, failed on every bun project the CLI has ever scaffolded. +- **A prebuilt binary for Linux arm64.** The installer used to refuse that platform and + send you to `cargo install --git` — so Graviton, a Raspberry Pi, an ARM CI runner and + Docker on Apple Silicon all needed a Rust toolchain. `rustup target add` alone could + never have produced it: `tree-sitter` and `tree-sitter-typescript` compile C through the + `cc` crate, and Ubuntu ships no aarch64 musl cross compiler. Both Linux targets now build + through zig, which is one, so the arch that was missing and the arch that worked share a + toolchain instead of having two. + + Each release job also runs the binary it just built, wherever the runner can execute it — + a binary that links and will not start is the failure a release pipeline must not leave + for a user's terminal to find. Both macOS binaries run on the arm64 macOS runner, the + Intel one through Rosetta, which is probed rather than assumed since a runner without it + would otherwise fail a release over its own configuration; and each Linux binary runs wherever + `ubuntu-latest` resolves to its architecture. Because that last part depends on the + runner pool rather than on the pipeline, a separate job pins an arm64 Linux runner and + installs the published binary there through `install.sh` — so the arm64 artifact is + started before it reaches anyone, on every release, and the installer's arm64 branch and + checksum verification are exercised against the real assets on the way. + - **`install.sh` resolves `latest` without the release API.** The API is rate-limited to 60 requests an hour per IP unauthenticated — an office behind one NAT or a CI runner burns through it — and a throttled response carries no `tag_name`, so the installer diff --git a/README.md b/README.md index dec3632..f53e80b 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ binary. Needs a Rust toolchain; takes a few seconds. curl -fsSL https://raw.githubusercontent.com/Expressive-Tea/matcha/main/install.sh | sh ``` -Drops the binary in `~/.local/bin`. Env vars go on the `sh` side of the pipe: +Drops the binary in `~/.local/bin`. Prebuilt for macOS (arm64, x86_64) and Linux +(arm64, x86_64), statically linked against musl so any distro works, Alpine +included. Env vars go on the `sh` side of the pipe: ```bash curl -fsSL …/install.sh | MATCHA_VERSION=v26.7.0 MATCHA_INSTALL_DIR=/usr/local/bin sh diff --git a/install.sh b/install.sh index 995155b..d8ec987 100755 --- a/install.sh +++ b/install.sh @@ -45,7 +45,7 @@ case "$os" in Linux) case "$arch" in x86_64|amd64) triple="x86_64-unknown-linux-musl" ;; - arm64|aarch64) err "linux arm64 has no prebuilt binary yet — use: cargo install --git $REPO_BASE" ;; + arm64|aarch64) triple="aarch64-unknown-linux-musl" ;; *) err "unsupported Linux arch: $arch" ;; esac ;; *) err "unsupported OS: $os — try: cargo install --git $REPO_BASE" ;; diff --git a/test_install.sh b/test_install.sh index 686eebe..129463b 100755 --- a/test_install.sh +++ b/test_install.sh @@ -8,7 +8,10 @@ fail() { echo "FAIL: $*" >&2; exit 1; } os=$(uname -s); arch=$(uname -m) case "$os" in Darwin) case "$arch" in arm64|aarch64) triple=aarch64-apple-darwin;; x86_64) triple=x86_64-apple-darwin;; esac;; - Linux) case "$arch" in x86_64|amd64) triple=x86_64-unknown-linux-musl;; esac;; + Linux) case "$arch" in + x86_64|amd64) triple=x86_64-unknown-linux-musl;; + arm64|aarch64) triple=aarch64-unknown-linux-musl;; + esac;; esac [ -n "${triple:-}" ] || { echo "SKIP: unsupported test host"; exit 0; }