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.
This commit is contained in:
zuujiscom
2026-10-22 15:31:37 -05:00
parent 477b25e63f
commit 30149d765d
+5 -1
View File
@@ -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