From 27ea0d4bdcb6ee1c1a0c250b33f9550972691a34 Mon Sep 17 00:00:00 2001 From: zuujiscom Date: Thu, 22 Oct 2026 14:14:09 -0500 Subject: [PATCH 1/5] FreeBSD package.sh: package the aarch64 cross build The release workflow now cross-compiles FreeBSD aarch64 inside the x86_64 VM (storytold/craft-common-actions#50) and sets CARGO_BUILD_TARGET=aarch64-unknown-freebsd. package.sh now reads the binaries from target//release when CARGO_BUILD_TARGET is set, names the archive after the target instead of uname -m, and skips the --version run when the binary is for another architecture than the machine. x86_64 packages are unchanged. Part of storytold/craft-common-actions#39. --- packaging/freebsd/package.sh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/packaging/freebsd/package.sh b/packaging/freebsd/package.sh index bb9a7799..107da888 100755 --- a/packaging/freebsd/package.sh +++ b/packaging/freebsd/package.sh @@ -31,12 +31,18 @@ while [ $# -gt 0 ]; do done # FreeBSD's uname says amd64; release file names use x86_64 like the Linux and Windows ones. -MACHINE="$(uname -m)" -case "$MACHINE" in - amd64 | x86_64) ARCH=x86_64 ;; - arm64 | aarch64) ARCH=aarch64 ;; - *) echo "unsupported architecture $MACHINE" >&2; exit 2 ;; -esac +release_arch() { + case "$1" in + amd64 | x86_64) echo x86_64 ;; + arm64 | aarch64) echo aarch64 ;; + *) echo "unsupported architecture $1" >&2; return 2 ;; + esac +} +HOST_ARCH="$(release_arch "$(uname -m)")" +# 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. +ARCH="$HOST_ARCH" +if [ -n "${CARGO_BUILD_TARGET:-}" ]; then ARCH="$(release_arch "${CARGO_BUILD_TARGET%%-*}")"; fi if [ "$DRY_RUN" = 0 ] && [ "$(uname -s)" != FreeBSD ]; then echo "error: build on FreeBSD (or pass --dry-run to check the tree layout)" >&2 exit 2 @@ -55,7 +61,8 @@ STAGE="$WORK/$BASENAME" rm -rf "$WORK" mkdir -p "$WORK" -BIN="$CARGO_TARGET_DIR/release" +# Cargo puts a cross build under target//release. +BIN="$CARGO_TARGET_DIR/${CARGO_BUILD_TARGET:+$CARGO_BUILD_TARGET/}release" OUT_DIR="$DIST" if [ "$DRY_RUN" = 1 ]; then # Stub binaries, and the tarball stays in the work dir so dist/ only ever holds real builds. @@ -99,7 +106,11 @@ mkdir -p "$OUT_DIR" tar -C "$WORK" -czf "$OUT_DIR/$BASENAME.tar.gz" "$BASENAME" echo "wrote $OUT_DIR/$BASENAME.tar.gz" -"$STAGE/bin/$(smoke_bin)" --version +if [ "$DRY_RUN" = 1 ] || [ "$ARCH" = "$HOST_ARCH" ]; then + "$STAGE/bin/$(smoke_bin)" --version +else + echo "skipping --version: an $ARCH binary does not run on this $HOST_ARCH machine" +fi if [ "$DRY_RUN" = 1 ]; then echo "==> dry run: tarball contents" tar -tzvf "$OUT_DIR/$BASENAME.tar.gz" From e366f61e8f7c16f8785b20714bfb9a47446324c4 Mon Sep 17 00:00:00 2001 From: zuujiscom Date: Thu, 22 Oct 2026 14:32:12 -0500 Subject: [PATCH 2/5] FreeBSD package.sh: accept only FreeBSD targets, check cross-built binaries Review follow-up. CARGO_BUILD_TARGET must now be a *-unknown-freebsd triple, so a Linux or macOS target can no longer be packaged under a FreeBSD name, and it is read before uname -m, so an unsupported host does not block a valid cross build. When the binaries are for another architecture and cannot run --version, file(1) must report each as a FreeBSD ELF executable for the target architecture. Part of storytold/craft-common-actions#39. --- packaging/freebsd/package.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packaging/freebsd/package.sh b/packaging/freebsd/package.sh index 107da888..b2348cc3 100755 --- a/packaging/freebsd/package.sh +++ b/packaging/freebsd/package.sh @@ -38,11 +38,15 @@ release_arch() { *) echo "unsupported architecture $1" >&2; return 2 ;; esac } -HOST_ARCH="$(release_arch "$(uname -m)")" # 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. -ARCH="$HOST_ARCH" -if [ -n "${CARGO_BUILD_TARGET:-}" ]; then ARCH="$(release_arch "${CARGO_BUILD_TARGET%%-*}")"; fi +case "${CARGO_BUILD_TARGET:-}" in + "") ARCH="$(release_arch "$(uname -m)")" ;; + *-unknown-freebsd) ARCH="$(release_arch "${CARGO_BUILD_TARGET%%-*}")" ;; + *) echo "CARGO_BUILD_TARGET=$CARGO_BUILD_TARGET is not a FreeBSD target" >&2; exit 2 ;; +esac +# Only binaries for this machine run here (the --version check at the end). +HOST_ARCH="$(release_arch "$(uname -m)" 2>/dev/null)" || HOST_ARCH="$(uname -m)" if [ "$DRY_RUN" = 0 ] && [ "$(uname -s)" != FreeBSD ]; then echo "error: build on FreeBSD (or pass --dry-run to check the tree layout)" >&2 exit 2 @@ -109,6 +113,14 @@ echo "wrote $OUT_DIR/$BASENAME.tar.gz" if [ "$DRY_RUN" = 1 ] || [ "$ARCH" = "$HOST_ARCH" ]; then "$STAGE/bin/$(smoke_bin)" --version else + # They cannot run here, so check what they are instead. + want="$ARCH"; [ "$ARCH" != x86_64 ] || want=x86-64 + for b in "$STAGE"/bin/*; do + case "$(file -b "$b")" in + ELF*"$want"*FreeBSD*) ;; + *) 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 if [ "$DRY_RUN" = 1 ]; then From 477b25e63fb2526a7daf717d76f5cb75aacb1fb3 Mon Sep 17 00:00:00 2001 From: zuujiscom Date: Thu, 22 Oct 2026 14:49:35 -0500 Subject: [PATCH 3/5] FreeBSD package.sh: accept only executables in the cross-build check Review follow-up. The file(1) check for binaries that cannot run here now needs an executable (file says "executable" or "pie executable") or an ELF with an interpreter, which is how an older file(1) still shows a PIE it calls a shared object. FreeBSD libraries, object files and core files for the target architecture are refused. Part of storytold/craft-common-actions#39. --- packaging/freebsd/package.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packaging/freebsd/package.sh b/packaging/freebsd/package.sh index b2348cc3..87e5e29f 100755 --- a/packaging/freebsd/package.sh +++ b/packaging/freebsd/package.sh @@ -113,11 +113,12 @@ echo "wrote $OUT_DIR/$BASENAME.tar.gz" if [ "$DRY_RUN" = 1 ] || [ "$ARCH" = "$HOST_ARCH" ]; then "$STAGE/bin/$(smoke_bin)" --version else - # They cannot run here, so check what they are instead. + # 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*"$want"*FreeBSD*) ;; + 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 From 30149d765d193103c3b8ddd960ac1f41c689df14 Mon Sep 17 00:00:00 2001 From: zuujiscom Date: Thu, 22 Oct 2026 15:31:37 -0500 Subject: [PATCH 4/5] FreeBSD package.sh: never run a FreeBSD target's binary on another OS Review follow-up. With CARGO_BUILD_TARGET set on a host that is not FreeBSD (say an x86_64 Mac building x86_64-unknown-freebsd), the architectures match but the binary still cannot run, so the --version run is skipped there and the file(1) check is used instead. Part of storytold/craft-common-actions#39. --- packaging/freebsd/package.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packaging/freebsd/package.sh b/packaging/freebsd/package.sh index 87e5e29f..7a3ae533 100755 --- a/packaging/freebsd/package.sh +++ b/packaging/freebsd/package.sh @@ -45,8 +45,12 @@ case "${CARGO_BUILD_TARGET:-}" in *-unknown-freebsd) ARCH="$(release_arch "${CARGO_BUILD_TARGET%%-*}")" ;; *) echo "CARGO_BUILD_TARGET=$CARGO_BUILD_TARGET is not a FreeBSD target" >&2; exit 2 ;; esac -# Only binaries for this machine run here (the --version check at the end). +# 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 if [ "$DRY_RUN" = 0 ] && [ "$(uname -s)" != FreeBSD ]; then echo "error: build on FreeBSD (or pass --dry-run to check the tree layout)" >&2 exit 2 From 03354ec7d3419949db98f51133d6aee744d9b336 Mon Sep 17 00:00:00 2001 From: zuujiscom Date: Thu, 22 Oct 2026 16:06:19 -0500 Subject: [PATCH 5/5] FreeBSD package.sh: accept only the two supported FreeBSD targets Review follow-up. CARGO_BUILD_TARGET must be aarch64-unknown-freebsd or x86_64-unknown-freebsd, the two the release builds; anything else, including made-up triples such as aarch64-foo-unknown-freebsd, stops with exit 2. Part of storytold/craft-common-actions#39. --- packaging/freebsd/package.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/freebsd/package.sh b/packaging/freebsd/package.sh index 7a3ae533..fafa51f7 100755 --- a/packaging/freebsd/package.sh +++ b/packaging/freebsd/package.sh @@ -42,8 +42,8 @@ release_arch() { # aarch64-unknown-freebsd (craft-common-actions#39): name the archive after the target. case "${CARGO_BUILD_TARGET:-}" in "") ARCH="$(release_arch "$(uname -m)")" ;; - *-unknown-freebsd) ARCH="$(release_arch "${CARGO_BUILD_TARGET%%-*}")" ;; - *) echo "CARGO_BUILD_TARGET=$CARGO_BUILD_TARGET is not a FreeBSD target" >&2; exit 2 ;; + 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 # Only binaries for this machine run here (the --version check at the end); a FreeBSD target built # on another OS never does.