From 9bd1c67e99d30a135dc3e3f8814ecd96cbac8e62 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Wed, 11 Nov 2026 18:32:16 -0700 Subject: [PATCH] build: build for apple --- .gitea/actions/cli-build/Dockerfile | 21 +++++++++ .gitea/actions/cli-build/action.yml | 13 ++++++ .gitea/actions/cli-build/entrypoint.sh | 19 +++++++++ .gitea/workflows/release.yaml | 59 +++++++------------------- 4 files changed, 69 insertions(+), 43 deletions(-) create mode 100644 .gitea/actions/cli-build/Dockerfile create mode 100644 .gitea/actions/cli-build/action.yml create mode 100644 .gitea/actions/cli-build/entrypoint.sh diff --git a/.gitea/actions/cli-build/Dockerfile b/.gitea/actions/cli-build/Dockerfile new file mode 100644 index 0000000..9869b57 --- /dev/null +++ b/.gitea/actions/cli-build/Dockerfile @@ -0,0 +1,21 @@ +FROM ghcr.io/rust-cross/cargo-zigbuild:latest + +# The image ships the toolchain, zig, a macOS SDK and cargo-zigbuild, but not the bits the build and +# packaging scripts need. +RUN apt-get update \ + && apt-get install -y --no-install-recommends ca-certificates zip zstd \ + && rm -rf /var/lib/apt/lists/* + +# Install every target up front so building needs no network access. `universal2-apple-darwin` is +# not a rustc target: cargo-zigbuild builds both architectures and merges them. +RUN rustup target install \ + aarch64-unknown-linux-musl \ + x86_64-unknown-linux-musl \ + x86_64-pc-windows-gnu \ + aarch64-apple-darwin \ + x86_64-apple-darwin + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/.gitea/actions/cli-build/action.yml b/.gitea/actions/cli-build/action.yml new file mode 100644 index 0000000..da947fe --- /dev/null +++ b/.gitea/actions/cli-build/action.yml @@ -0,0 +1,13 @@ +name: Build guac CLI +description: Cross-compile the guac CLI with cargo-zigbuild and package the artifact + +inputs: + target: + description: Rust target triple, or universal2-apple-darwin + required: true + +runs: + using: docker + image: Dockerfile + args: + - ${{ inputs.target }} diff --git a/.gitea/actions/cli-build/entrypoint.sh b/.gitea/actions/cli-build/entrypoint.sh new file mode 100644 index 0000000..ea8c4ab --- /dev/null +++ b/.gitea/actions/cli-build/entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/sh +set -eu + +target="$1" + +cd "${GITHUB_WORKSPACE:-$(pwd)}" + +# Keep the registry in the workspace so the runner can cache it between runs. +export CARGO_HOME="${PWD}/.cargo-cache" + +bin=guac-cli +case "$target" in + *windows*) bin=guac-cli.exe ;; +esac + +(cd cli && cargo zigbuild --release --target "$target") + +mkdir -p dist +zip -j "dist/guac-cli-${target}.zip" "target/${target}/release/${bin}" diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml index 069f6cb..c19b1f6 100644 --- a/.gitea/workflows/release.yaml +++ b/.gitea/workflows/release.yaml @@ -69,66 +69,39 @@ jobs: cli: runs-on: ubuntu-latest - container: - image: catthehacker/ubuntu:rust-latest strategy: - fail-fast: true + fail-fast: false matrix: target: - aarch64-unknown-linux-musl - x86_64-pc-windows-gnu - x86_64-unknown-linux-musl + - universal2-apple-darwin steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Cache rustup + # Building and packaging both happen in .gitea/actions/cli-build, whose image the runner + # builds from its Dockerfile and keeps in the Docker layer cache. That image carries the + # toolchain, zig, the macOS SDK and every target, so none of that is installed per job. + - name: Cache cargo registry uses: actions/cache@v4 with: - path: ${{ env.RUSTUP_HOME }} - key: rustup-cli-${{ matrix.target }}-${{ runner.os }} + path: .cargo-cache + key: cli-registry-${{ hashFiles('**/Cargo.lock') }} + restore-keys: cli-registry- - - name: Install Rust Toolchain - run: rustup target install ${{ matrix.target }} - - - name: Cache cargo - uses: Swatinem/rust-cache@v2 - with: - shared-key: cli-${{ matrix.target }} - - - name: Cache zigbuild install + - name: Cache build artifacts uses: actions/cache@v4 with: - path: /opt/zigvenv - key: zigbuild-venv-${{ runner.os }} - - # compiled libc/compiler-rt are per target, so these stay keyed on it - - name: Cache zig build artifacts - uses: actions/cache@v4 - with: - path: | - ~/.cache/zig - ~/.cache/cargo-zigbuild - key: zigbuild-cache-${{ matrix.target }}-${{ runner.os }} - - - name: Install cargo-zigbuild Toolchain - run: | - # venv keeps cargo-zigbuild and ziglang in one relocatable-by-path directory we can cache - [ -d /opt/zigvenv ] || python3 -m venv /opt/zigvenv - /opt/zigvenv/bin/pip install cargo-zigbuild - echo /opt/zigvenv/bin >> "$GITHUB_PATH" + path: target + key: cli-target-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} + restore-keys: cli-target-${{ matrix.target }}- - name: Build cli (${{ matrix.target }}) - working-directory: cli - run: cargo zigbuild --release --target ${{ matrix.target }} - - - name: Package - run: | - bin=guac-cli - [[ "${{ matrix.target }}" == *windows* ]] && bin=guac-cli.exe - mkdir -p dist - zip -j "dist/guac-cli-${{ matrix.target }}.zip" "target/${{ matrix.target }}/release/$bin" - shell: bash + uses: ./.gitea/actions/cli-build + with: + target: ${{ matrix.target }} - name: Upload artifact uses: actions/upload-artifact@v3