collective

Browse / github.com/storytold/deckcraft / patch

FreeBSD: package the aarch64 cross build (craft-common-actions#39)

FreeBSD: package the aarch64 cross build (craft-common-actions#39) Part of https://github.com/storytold/craft-common-actions/issues/39 ## What happens today FreeBSD aarch64 was dropped from releases because the emulated aarch64 VM took over 5 hours. storytold/craft-common-actions#50 now cross-compiles aarch64 inside the KVM-accelerated x86_64 FreeBSD VM, opt-in through the `freebsd-architectures` input of `release.yml`. Its cross toolchain step exports `CARGO_BUILD_TARGET=aarch64-unknown-freebsd` before `packaging/freebsd/package.sh` runs. With aarch64 turned on, this app's script would: - name the archive after `uname -m`, which is always amd64 in the guest

Status
open
Score
0.00
Adopters
0 other operators
Author
zuujiscom (imported from pull request #1194, open)
Base
9aef21e627cb447dd2180cd804db85343e73e5cf
Size
+37 −7 in 1 file
Review
pending
Shared
2026-10-28
Id
fb6bd97728578507be001805

How it went

No other operator has reported using it yet.

Diff

raw · packaging/freebsd/package.sh

diff --git a/packaging/freebsd/package.sh b/packaging/freebsd/package.sh--- a/packaging/freebsd/package.sh+++ b/packaging/freebsd/package.sh@@ -18,13 +18,30 @@ if [[ "${1:-}" != "--skip-build" ]]; then   (cd "$ROOT" && cargo build --release --locked -p deckcraft -p deckcraft-cli) fi -ARCH="$(uname -m)"-case "$ARCH" in-  amd64) ARCH=x86_64 ;;-  arm64) ARCH=aarch64 ;;-  *) ;;+release_arch() {+  local arch="$1"+  case "$arch" in+    amd64 | x86_64) echo x86_64 ;;+    arm64 | aarch64) echo aarch64 ;;+    *) echo "$arch" ;;+  esac+  return+}+# The release workflow cross-compiles aarch64 in an x86_64 VM with CARGO_BUILD_TARGET set to+# aarch64-unknown-freebsd (craft-common-actions#39): name the archive after the target.+case "${CARGO_BUILD_TARGET:-}" in+  "") ARCH="$(release_arch "$(uname -m)")" ;;+  aarch64-unknown-freebsd | x86_64-unknown-freebsd) ARCH="$(release_arch "${CARGO_BUILD_TARGET%%-*}")" ;;+  *) echo "CARGO_BUILD_TARGET=$CARGO_BUILD_TARGET is not a supported FreeBSD target" >&2; exit 2 ;; esac-BIN="$CARGO_TARGET_DIR/release"+# Only binaries for this machine run here (the --version check at the end); a FreeBSD target built+# on another OS never does.+HOST_ARCH="$(release_arch "$(uname -m)" 2>/dev/null)" || HOST_ARCH="$(uname -m)"+if [[ -n "${CARGO_BUILD_TARGET:-}" ]] && [[ "$(uname -s)" != FreeBSD ]]; then+  HOST_ARCH="$(uname -s) $HOST_ARCH"+fi+# Cargo puts a cross build under target/<triple>/release.+BIN="$CARGO_TARGET_DIR/${CARGO_BUILD_TARGET:+$CARGO_BUILD_TARGET/}release" NAME="deckcraft-$VERSION-freebsd-$ARCH" WORK="$CARGO_TARGET_DIR/freebsd-package" STAGE="$WORK/$NAME"@@ -41,6 +58,19 @@ cp -R "$ROOT/assets/app-icon/hicolor" "$STAGE/share/icons/" copy_docs "$STAGE/share/doc/deckcraft"  tar -C "$WORK" -czf "$DIST/$NAME.tar.gz" "$NAME"-"$STAGE/bin/deckcraft-cli" --version+if [[ "$ARCH" = "$HOST_ARCH" ]]; then+  "$STAGE/bin/deckcraft-cli" --version+else+  # They cannot run here, so check what they are instead: executables, not libraries or objects.+  # An older file(1) calls a PIE a shared object; its interpreter still marks it as a program.+  want="$ARCH"; [[ "$ARCH" != x86_64 ]] || want=x86-64+  for b in "$STAGE"/bin/*; do+    case "$(file -b "$b")" in+      ELF*" executable, "*"$want"*FreeBSD* | ELF*"$want"*FreeBSD*interpreter*) ;;+      *) echo "error: $b is not a FreeBSD $ARCH executable: $(file -b "$b")" >&2; exit 1 ;;+    esac+  done+  echo "skipping --version: an $ARCH binary does not run on this $HOST_ARCH machine"+fi echo "wrote $DIST/$NAME.tar.gz" ls -lh "$DIST/$NAME.tar.gz"