mirror of
https://github.com/storytold/materialcraft.git
synced 2026-11-24 08:21:01 +01:00
Build FreeBSD on a larger runner while the repo is private
A private repo's ubuntu-latest has about 7 GB, and the shared workflows start a 12 GB FreeBSD VM, so QEMU fails at startup. The shared workflows have no runner input, so release.yml turns off their FreeBSD job and runs its own copy on github-ubuntu-16core, then adds the archives and checksums to the draft release. freebsd.yml would fail the same way, so it is manual-only until the repo is public. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
90e9529d4b
commit
8e91074c68
2 files changed
+279
-12
No files matched your search
@@ -5,19 +5,11 @@
|
||||
# uploaded and no secrets are used.
|
||||
name: FreeBSD
|
||||
|
||||
# The VM build takes one to several hours, so it runs nightly on main rather than on every push
|
||||
# or dependency change: a drifted dependency still shows up within a day. PRs that change the
|
||||
# FreeBSD packaging itself still run it.
|
||||
# Manual only while this repo is private: the shared workflow's VM needs 12 GB, and a private
|
||||
# repo's ubuntu-latest has about 7 GB, so it can't start. release.yml builds FreeBSD on a larger
|
||||
# runner. When the repo is public, restore the push to release, the nightly schedule and the
|
||||
# pull_request paths that the other apps use.
|
||||
on:
|
||||
push:
|
||||
branches: [release]
|
||||
schedule:
|
||||
- cron: "17 2 * * *"
|
||||
pull_request:
|
||||
paths:
|
||||
- .github/workflows/freebsd.yml
|
||||
- packaging/freebsd/**
|
||||
- packaging/env.sh
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
|
||||
@@ -27,6 +27,9 @@ jobs:
|
||||
app-title: "MaterialCraft"
|
||||
craft-fonts-ref: 3d9ab3a132ed0eff457e424226a435a901da30d3
|
||||
web-craft-fonts: true
|
||||
# The shared FreeBSD job needs more memory than a private repo's ubuntu-latest has. The
|
||||
# freebsd job below builds it here on a larger runner instead.
|
||||
has-freebsd: false
|
||||
version: ${{ inputs.version }}
|
||||
secrets:
|
||||
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
|
||||
@@ -43,3 +46,275 @@ jobs:
|
||||
AZURE_SIGNING_ENDPOINT: ${{ secrets.AZURE_SIGNING_ENDPOINT }}
|
||||
AZURE_SIGNING_ACCOUNT: ${{ secrets.AZURE_SIGNING_ACCOUNT }}
|
||||
AZURE_CERT_PROFILE: ${{ secrets.AZURE_CERT_PROFILE }}
|
||||
|
||||
# The jobs below stay here only while this repo is private. They follow the shared workflow's
|
||||
# FreeBSD job, on a larger runner. When the repo is public, remove them and has-freebsd: false.
|
||||
version:
|
||||
timeout-minutes: 10
|
||||
name: version
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
outputs:
|
||||
version: ${{ steps.v.outputs.version }}
|
||||
date: ${{ steps.v.outputs.date }}
|
||||
prerelease: ${{ steps.v.outputs.prerelease }}
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
- id: v
|
||||
name: Resolve version
|
||||
uses: storytold/craft-common-actions/actions/resolve-version@main
|
||||
with:
|
||||
input-version: ${{ inputs.version }}
|
||||
app-title: "MaterialCraft"
|
||||
|
||||
freebsd:
|
||||
name: FreeBSD ${{ matrix.arch }}
|
||||
needs: [version]
|
||||
# A private repo's ubuntu-latest has about 7 GB, too little for the VM's 12 GB.
|
||||
runs-on: github-ubuntu-16core
|
||||
permissions:
|
||||
contents: read
|
||||
timeout-minutes: 300
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
arch: [x86_64, aarch64]
|
||||
env:
|
||||
APP_NAME: materialcraft
|
||||
CARGO_HOME: /var/tmp/craft-cargo
|
||||
CARGO_TARGET_DIR: /var/tmp/craft-target
|
||||
CARGO_BUILD_JOBS: 4
|
||||
CARGO_TERM_COLOR: always
|
||||
CARGO_INCREMENTAL: 0
|
||||
RUST_BACKTRACE: 1
|
||||
VERSION: ${{ needs.version.outputs.version }}
|
||||
BUILD_DATE: ${{ needs.version.outputs.date }}
|
||||
BUILD_SHA: ${{ github.sha }}
|
||||
MATERIALCRAFT_VERSION: ${{ needs.version.outputs.version }}
|
||||
MATERIALCRAFT_BUILD_DATE: ${{ needs.version.outputs.date }}
|
||||
MATERIALCRAFT_BUILD_SHA: ${{ github.sha }}
|
||||
INPUT_VERSION: ${{ inputs.version }}
|
||||
steps:
|
||||
- name: Check the FreeBSD architecture
|
||||
env:
|
||||
ARCH: ${{ matrix.arch }}
|
||||
run: |
|
||||
# The guest is always x86_64 and only aarch64 is cross-compiled: any other value
|
||||
# would build x86_64 binaries and package them under its own name.
|
||||
case "$ARCH" in
|
||||
x86_64 | aarch64) ;;
|
||||
*)
|
||||
echo "::error::unsupported FreeBSD architecture '$ARCH' in freebsd-architectures; use x86_64 or aarch64"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
- name: Check out craft-fonts
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-fonts@main
|
||||
with:
|
||||
ref: 3d9ab3a132ed0eff457e424226a435a901da30d3
|
||||
- name: Check out craft-i18n
|
||||
uses: storytold/craft-common-actions/actions/checkout-craft-i18n@main
|
||||
- name: Start the FreeBSD VM
|
||||
uses: vmactions/freebsd-vm@c46abacb49f09938ca4e1702d15d836285d694cc # v1.5.9
|
||||
with:
|
||||
release: "15.1"
|
||||
# Always an x86_64 guest, which KVM accelerates: aarch64 is cross-compiled in it,
|
||||
# because an emulated aarch64 guest takes over 5 hours for most apps (#39).
|
||||
usesh: true
|
||||
cpu: 4
|
||||
mem: 12288
|
||||
copyback: false
|
||||
envs: "APP_NAME CARGO_HOME CARGO_TARGET_DIR CARGO_INCREMENTAL CARGO_BUILD_JOBS VERSION BUILD_DATE BUILD_SHA INPUT_VERSION MATERIALCRAFT_VERSION MATERIALCRAFT_BUILD_DATE MATERIALCRAFT_BUILD_SHA"
|
||||
prepare: |
|
||||
# Keep rustup/proxies outside the Cargo data cache.
|
||||
unset CARGO_HOME CARGO_TARGET_DIR
|
||||
if [ "${{ matrix.arch }}" = aarch64 ]; then
|
||||
# The host compiler and the aarch64 standard library come from the amd64 and
|
||||
# aarch64 lang/rust packages, which must be the same build. "latest" can build
|
||||
# them days apart; the quarterly branch keeps them in step.
|
||||
mkdir -p /usr/local/etc/pkg/repos
|
||||
printf 'FreeBSD-ports: { url: "https://pkg.FreeBSD.org/${ABI}/quarterly" }\n' > /usr/local/etc/pkg/repos/FreeBSD.conf
|
||||
pkg update -f -q
|
||||
fi
|
||||
pkg install -y bash git curl pkgconf cmake python3 libxkbcommon wayland libX11 libXcursor libXrandr libXi libxcb mesa-libs vulkan-loader gtk3 fontconfig freetype2 alsa-lib
|
||||
# aarch64-unknown-freebsd is a tier-3 Rust target: rustup publishes no toolchain
|
||||
# or standard library for it ("installer for platform not found"), so use
|
||||
# FreeBSD's lang/rust package.
|
||||
if [ "${{ matrix.arch }}" = aarch64 ]; then
|
||||
pkg install -y rust
|
||||
else
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
|
||||
fi
|
||||
- name: Set up the aarch64 cross toolchain
|
||||
if: matrix.arch == 'aarch64'
|
||||
shell: freebsd {0}
|
||||
run: |
|
||||
set -eu
|
||||
# Stable Rust, no -Zbuild-std: the aarch64 standard library is copied from FreeBSD's
|
||||
# aarch64 lang/rust package, and C code links with base clang and lld against an
|
||||
# arm64 sysroot (base.txz plus the libraries the prepare step installs).
|
||||
target=aarch64-unknown-freebsd
|
||||
X=/var/tmp/craft-cross
|
||||
S=$X/sysroot
|
||||
mkdir -p "$X/db" "$X/cache" "$S"
|
||||
release=$(freebsd-version -u | sed 's/-p[0-9]*$//')
|
||||
P="-o ABI=FreeBSD:${release%%.*}:aarch64 -o OSVERSION=$(uname -U) -o PKG_DBDIR=$X/db -o PKG_CACHEDIR=$X/cache -o IGNORE_OSVERSION=yes"
|
||||
pkg $P update -q
|
||||
host=$(pkg query %v rust)
|
||||
cross=$(pkg $P rquery %v rust)
|
||||
if [ "$host" != "$cross" ]; then
|
||||
echo "error: lang/rust is $host for amd64 but $cross for aarch64; the standard library must match the compiler" >&2
|
||||
exit 1
|
||||
fi
|
||||
pkg $P fetch -y -q rust
|
||||
# pkg links each name-version.pkg to its hashed file.
|
||||
tar -xf "$X/cache/rust-$cross.pkg" -C "$X" --include "*usr/local/lib/rustlib/$target/*"
|
||||
cp -R "$X/usr/local/lib/rustlib/$target" /usr/local/lib/rustlib/
|
||||
base=https://download.freebsd.org/releases/arm64/aarch64/$release
|
||||
fetch -q -o "$X/MANIFEST" "$base/MANIFEST"
|
||||
fetch -q -o "$X/base.txz" "$base/base.txz"
|
||||
if [ "$(awk '$1 == "base.txz" { print $2 }' "$X/MANIFEST")" != "$(sha256 -q "$X/base.txz")" ]; then
|
||||
echo "error: arm64 base.txz does not match its MANIFEST" >&2
|
||||
exit 1
|
||||
fi
|
||||
tar -xf "$X/base.txz" -C "$S" ./lib ./usr/lib ./usr/include ./usr/libdata
|
||||
# The libraries the prepare step installs; the build tools and fonts stay host-only.
|
||||
pkg $P fetch -y -q -d libxkbcommon wayland libX11 libXcursor libXrandr libXi libxcb mesa-libs vulkan-loader gtk3 fontconfig freetype2 alsa-lib
|
||||
for p in "$X"/cache/*.pkg; do
|
||||
[ ! -L "$p" ] || continue
|
||||
case "$p" in */rust-*) continue ;; esac
|
||||
tar -xf "$p" -C "$S" --exclude '+*'
|
||||
done
|
||||
for tool in cc c++; do
|
||||
printf '#!/bin/sh\nexec %s --target=%s%s --sysroot=%s -fuse-ld=lld -I%s/usr/local/include -L%s/usr/local/lib -Wl,-rpath-link,%s/usr/local/lib "$@"\n' \
|
||||
"$tool" "$target" "${release%%-*}" "$S" "$S" "$S" "$S" > "$X/$tool"
|
||||
chmod +x "$X/$tool"
|
||||
done
|
||||
cat > "$X/env" <<EOF
|
||||
export CARGO_BUILD_TARGET=$target
|
||||
export CARGO_TARGET_AARCH64_UNKNOWN_FREEBSD_LINKER=$X/cc
|
||||
export CC_aarch64_unknown_freebsd=$X/cc CXX_aarch64_unknown_freebsd=$X/c++ AR_aarch64_unknown_freebsd=/usr/bin/ar
|
||||
export PKG_CONFIG_ALLOW_CROSS=1 PKG_CONFIG_SYSROOT_DIR=$S PKG_CONFIG_LIBDIR=$S/usr/local/libdata/pkgconfig:$S/usr/libdata/pkgconfig
|
||||
EOF
|
||||
rustc --print target-libdir --target "$target"
|
||||
- name: Restore FreeBSD release Cargo cache
|
||||
id: cargo-cache
|
||||
continue-on-error: true
|
||||
timeout-minutes: 10
|
||||
uses: storytold/craft-common-actions/actions/freebsd-cargo-cache@main
|
||||
with:
|
||||
profile: release
|
||||
configuration: ${{ toJSON(inputs) }}
|
||||
source-hash: ${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', '**/build.rs', '.cargo/**', 'rust-toolchain*', 'packaging/**', '.github/workflows/release.yml') }}
|
||||
- name: Build and package
|
||||
shell: freebsd {0}
|
||||
run: |
|
||||
set -eu
|
||||
# Only rustup writes this; the lang/rust package installs into /usr/local/bin.
|
||||
[ ! -f "$HOME/.cargo/env" ] || . "$HOME/.cargo/env"
|
||||
# A failed restore may leave partial files. Rebuild from an empty cache.
|
||||
if [ "${{ steps.cargo-cache.outcome }}" = failure ]; then
|
||||
rm -rf /var/tmp/craft-target /var/tmp/craft-cargo/registry /var/tmp/craft-cargo/git
|
||||
fi
|
||||
git config --global --add safe.directory "*"
|
||||
# Before the cross environment: xtask has to run on the guest.
|
||||
if [ -n "$INPUT_VERSION" ]; then cargo xtask version set "$VERSION" || cargo run -q -p xtask -- version set "$VERSION"; fi
|
||||
# Written by "Set up the aarch64 cross toolchain": cargo then builds for aarch64.
|
||||
[ ! -f /var/tmp/craft-cross/env ] || . /var/tmp/craft-cross/env
|
||||
# Cargo puts a cross build's binaries under target/<triple>/release.
|
||||
rel="${CARGO_BUILD_TARGET:+$CARGO_BUILD_TARGET/}release"
|
||||
export CRAFT_FONTS_DIR="$PWD/craft-fonts" CRAFT_FONTS_REQUIRED=1
|
||||
if [ -f craft-i18n.rev ]; then export CRAFT_I18N_DIR="$PWD/craft-i18n" CRAFT_I18N_REQUIRED=1; fi
|
||||
if [ -f packaging/freebsd/package.sh ]; then
|
||||
bash packaging/freebsd/package.sh
|
||||
else
|
||||
set -- -p "$APP_NAME"
|
||||
if cargo metadata --format-version 1 --no-deps | python3 -c 'import json, sys; sys.exit(not any(p["name"] == sys.argv[1] for p in json.load(sys.stdin)["packages"]))' "$APP_NAME-cli"; then
|
||||
set -- "$@" -p "$APP_NAME-cli"
|
||||
fi
|
||||
cargo build --release --locked "$@"
|
||||
name="$APP_NAME-$VERSION-freebsd-${{ matrix.arch }}"
|
||||
mkdir -p "dist/release/$name"
|
||||
cp "target/$rel/$APP_NAME" "dist/release/$name/" 2>/dev/null || cp "/var/tmp/craft-target/$rel/$APP_NAME" "dist/release/$name/"
|
||||
if [ -f "target/$rel/$APP_NAME-cli" ]; then
|
||||
cp "target/$rel/$APP_NAME-cli" "dist/release/$name/"
|
||||
elif [ -f "/var/tmp/craft-target/$rel/$APP_NAME-cli" ]; then
|
||||
cp "/var/tmp/craft-target/$rel/$APP_NAME-cli" "dist/release/$name/"
|
||||
fi
|
||||
cp README.md LICENSE-MIT LICENSE-APACHE NOTICE ATTRIBUTION.md "dist/release/$name/" 2>/dev/null || true
|
||||
if [ -f "packaging/linux/ai.storyteller.$APP_NAME.desktop" ]; then
|
||||
cp "packaging/linux/ai.storyteller.$APP_NAME.desktop" "dist/release/$name/"
|
||||
fi
|
||||
mkdir -p "dist/release/$name/icons"
|
||||
cp -R assets/app-icon/hicolor "dist/release/$name/icons/" 2>/dev/null || true
|
||||
tar -C dist/release -czf "dist/release/$name.tar.gz" "$name"
|
||||
rm -rf "dist/release/$name"
|
||||
fi
|
||||
# The guest is x86_64 either way: a package.sh that names its archive after uname -m
|
||||
# instead of CARGO_BUILD_TARGET would ship an x86_64-labelled aarch64 build, or worse.
|
||||
found=
|
||||
for archive in dist/release/*-freebsd-*.tar.gz; do
|
||||
[ -f "$archive" ] || continue
|
||||
case "$archive" in
|
||||
*-freebsd-${{ matrix.arch }}.tar.gz) found=1 ;;
|
||||
*)
|
||||
echo "error: $archive is not a FreeBSD ${{ matrix.arch }} archive; packaging/freebsd/package.sh must honor CARGO_BUILD_TARGET" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ -z "$found" ]; then
|
||||
echo "error: no FreeBSD ${{ matrix.arch }} archive was produced" >&2
|
||||
exit 1
|
||||
fi
|
||||
- name: Copy release archives from the VM
|
||||
run: |
|
||||
mkdir -p dist/release
|
||||
rsync -a --timeout=1800 --rsync-path='env PATH=/usr/local/bin:/usr/bin:/bin rsync' \
|
||||
-e 'ssh -o ServerAliveInterval=30 -o ServerAliveCountMax=60 -o ConnectTimeout=120' \
|
||||
"freebsd:$GITHUB_WORKSPACE/dist/release/" dist/release/
|
||||
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
|
||||
with:
|
||||
name: release-freebsd-${{ matrix.arch }}
|
||||
path: dist/release/*
|
||||
if-no-files-found: error
|
||||
- name: Save FreeBSD release Cargo cache
|
||||
if: github.event_name != 'pull_request' && github.event_name != 'pull_request_target' && steps.cargo-cache.outputs.key != '' && steps.cargo-cache.outputs.cache-hit != 'true'
|
||||
continue-on-error: true
|
||||
timeout-minutes: 10
|
||||
uses: storytold/craft-common-actions/actions/freebsd-cargo-cache@main
|
||||
with:
|
||||
phase: save
|
||||
profile: release
|
||||
configuration: ${{ toJSON(inputs) }}
|
||||
source-hash: ${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', '**/build.rs', '.cargo/**', 'rust-toolchain*', 'packaging/**', '.github/workflows/release.yml') }}
|
||||
key: ${{ steps.cargo-cache.outputs.key }}
|
||||
|
||||
# The shared draft job can run before FreeBSD finishes, so add its archives afterwards.
|
||||
freebsd-draft:
|
||||
timeout-minutes: 10
|
||||
name: Add FreeBSD to the draft release
|
||||
needs: [version, freebsd, release]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
||||
with:
|
||||
pattern: release-freebsd-*
|
||||
path: artifacts
|
||||
merge-multiple: true
|
||||
- name: Upload the archives and update the checksums
|
||||
working-directory: artifacts
|
||||
env:
|
||||
VERSION: ${{ needs.version.outputs.version }}
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GH_REPO: ${{ github.repository }}
|
||||
run: |
|
||||
tag="v$VERSION"
|
||||
[ "$(gh release view "$tag" --json isDraft --jq .isDraft)" = true ]
|
||||
gh release download "$tag" --pattern SHA256SUMS.txt --dir "$RUNNER_TEMP"
|
||||
# The shared draft job also picks up any archive that finished before it ran.
|
||||
{ grep -v -- '-freebsd-' "$RUNNER_TEMP/SHA256SUMS.txt" || true; sha256sum -- *; } | sort -k2 >SHA256SUMS.txt
|
||||
gh release upload "$tag" --clobber -- *
|
||||
cat SHA256SUMS.txt
|
||||
Reference in new issue
Block a user