Able to build the FreeBSD binary
Some checks failed
CI / Format (push) Has been cancelled
CI / Test (Linux) (push) Has been cancelled
CI / Test (Windows MSVC) (push) Has been cancelled
CI / Clippy (push) Has been cancelled

This commit is contained in:
Eric Ratliff
2026-03-16 17:49:40 -05:00
parent bb4b2f4162
commit 13ab202880

127
build-release.sh Normal file → Executable file
View File

@@ -1,16 +1,36 @@
#!/bin/bash #!/bin/sh
# Build release binaries for distribution # Build release binaries for distribution.
# This script builds both Linux and Windows binaries (cross-compile) # Builds a native binary for the current OS, plus Windows (cross-compile).
# #
# Usage: # Usage:
# ./build-release.sh # version from Cargo.toml (e.g. 1.0.0) # ./build-release.sh # version from Cargo.toml (e.g. 1.0.0)
# ./build-release.sh beta1 # appends suffix (e.g. 1.0.0-beta1) # ./build-release.sh beta1 # appends suffix (e.g. 1.0.0-beta1)
# ./build-release.sh rc1 # appends suffix (e.g. 1.0.0-rc1) # ./build-release.sh rc1 # appends suffix (e.g. 1.0.0-rc1)
# #
# For Windows-only builds, use build-release.ps1 on Windows # Supported host platforms:
# For Linux-only builds, comment out the Windows section below # Linux -- builds linux-x86_64 + windows-x86_64 (via MinGW)
# FreeBSD -- builds freebsd-x86_64 + windows-x86_64 (via MinGW)
# Windows -- use build-release.ps1 instead
#
# To produce all three native binaries, run this script on both
# Linux and FreeBSD, then collect artifacts from both runs.
#
# Cross-compile Linux<->FreeBSD is not supported (requires a full sysroot).
set -e set -e
# Detect host OS
OS="$(uname -s)"
case "$OS" in
Linux) HOST="linux" ;;
FreeBSD) HOST="freebsd" ;;
Darwin) HOST="macos" ;;
*)
echo "Unsupported host OS: $OS"
echo "Use build-release.ps1 on Windows."
exit 1
;;
esac
# Read version from the single source of truth: Cargo.toml # Read version from the single source of truth: Cargo.toml
BASE_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/' | tr -d '\r') BASE_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/' | tr -d '\r')
if [ -z "$BASE_VERSION" ]; then if [ -z "$BASE_VERSION" ]; then
@@ -18,9 +38,11 @@ if [ -z "$BASE_VERSION" ]; then
exit 1 exit 1
fi fi
# Optional suffix (beta1, rc1, etc.) # Optional pre-release suffix (beta1, rc1, etc.)
if [ -n "$1" ]; then # Strip a leading 'v' if passed by accident (e.g. v1.0.0 -> ignored, 1.0.0 used from Cargo.toml)
VERSION="${BASE_VERSION}-${1}" SUFFIX="${1#v}"
if [ -n "$SUFFIX" ]; then
VERSION="${BASE_VERSION}-${SUFFIX}"
else else
VERSION="$BASE_VERSION" VERSION="$BASE_VERSION"
fi fi
@@ -28,9 +50,10 @@ fi
RELEASE_DIR="release-artifacts" RELEASE_DIR="release-artifacts"
echo "Building Anvil v${VERSION} release binaries..." echo "Building Anvil v${VERSION} release binaries..."
echo " Host platform: ${HOST}"
echo " Version base: ${BASE_VERSION} (from Cargo.toml)" echo " Version base: ${BASE_VERSION} (from Cargo.toml)"
if [ -n "$1" ]; then if [ -n "$SUFFIX" ]; then
echo " Suffix: ${1}" echo " Suffix: ${SUFFIX}"
fi fi
echo "" echo ""
@@ -38,51 +61,70 @@ echo ""
rm -rf "$RELEASE_DIR" rm -rf "$RELEASE_DIR"
mkdir -p "$RELEASE_DIR" mkdir -p "$RELEASE_DIR"
# Build Linux binary (optimized) # -- Native binary -----------------------------------------------------------
echo "Building Linux x86_64 binary..." echo "Building ${HOST} x86_64 binary..."
cargo build --release cargo build --release
strip target/release/anvil strip target/release/anvil 2>/dev/null || true
# Package Linux binary echo "Packaging ${HOST} binary..."
echo "Packaging Linux binaries..."
cd target/release cd target/release
tar -czf "../../$RELEASE_DIR/anvil-${VERSION}-linux-x86_64.tar.gz" anvil tar -czf "../../$RELEASE_DIR/anvil-${VERSION}-${HOST}-x86_64.tar.gz" anvil
zip -q "../../$RELEASE_DIR/anvil-${VERSION}-linux-x86_64.zip" anvil
cd ../.. cd ../..
# Build Windows binary (cross-compile) # -- Windows binary (cross-compile via MinGW) --------------------------------
echo "" echo ""
echo "Building Windows x86_64 binary..." echo "Building Windows x86_64 binary (cross-compile)..."
# Check if Windows target is installed # rustup is required to add cross-compile targets.
if ! rustup target list | grep -q "x86_64-pc-windows-gnu (installed)"; then # On FreeBSD, Rust is typically installed via pkg and rustup is not available.
echo "Installing Windows target..." if ! command -v rustup > /dev/null 2>&1; then
rustup target add x86_64-pc-windows-gnu echo " rustup not found -- Windows cross-compile requires rustup."
fi case "$HOST" in
freebsd) echo " On FreeBSD, install rustup via: curl https://sh.rustup.rs -sSf | sh" ;;
# Check if MinGW is installed *) echo " Install rustup from: https://rustup.rs" ;;
if ! command -v x86_64-w64-mingw32-gcc &> /dev/null; then esac
echo "Warning: MinGW not found. Install with: sudo apt install mingw-w64" echo "Skipping Windows build."
elif ! command -v x86_64-w64-mingw32-gcc > /dev/null 2>&1; then
case "$HOST" in
linux)
echo " MinGW not found. Install with: sudo apt install mingw-w64"
;;
freebsd)
echo " MinGW not available in FreeBSD pkg repos."
echo " Windows binary must be built on Linux (boot into Linux or use a bhyve VM)."
;;
esac
echo "Skipping Windows build." echo "Skipping Windows build."
else else
cargo build --release --target x86_64-pc-windows-gnu # Ensure Windows target is installed
x86_64-w64-mingw32-strip target/x86_64-pc-windows-gnu/release/anvil.exe if ! rustup target list | grep -q "x86_64-pc-windows-gnu (installed)"; then
echo "Installing Windows cross-compile target..."
rustup target add x86_64-pc-windows-gnu
fi
cargo build --release --target x86_64-pc-windows-gnu
x86_64-w64-mingw32-strip target/x86_64-pc-windows-gnu/release/anvil.exe 2>/dev/null || true
# Package Windows binary
echo "Packaging Windows binary..." echo "Packaging Windows binary..."
cd target/x86_64-pc-windows-gnu/release cd target/x86_64-pc-windows-gnu/release
zip -q "../../../$RELEASE_DIR/anvil-${VERSION}-windows-x86_64.zip" anvil.exe zip -q "../../../$RELEASE_DIR/anvil-${VERSION}-windows-x86_64.zip" anvil.exe
cd ../../.. cd ../../..
fi fi
# Generate checksums # -- Checksums ---------------------------------------------------------------
echo "" echo ""
echo "Generating checksums..." echo "Generating checksums..."
cd "$RELEASE_DIR" cd "$RELEASE_DIR"
sha256sum * > SHA256SUMS
# sha256sum on Linux, sha256 on FreeBSD/macOS
if command -v sha256sum > /dev/null 2>&1; then
sha256sum * > SHA256SUMS
else
shasum -a 256 * > SHA256SUMS
fi
cd .. cd ..
# Display results # -- Summary -----------------------------------------------------------------
echo "" echo ""
echo "===========================================================" echo "==========================================================="
echo " Anvil v${VERSION} release artifacts built successfully!" echo " Anvil v${VERSION} release artifacts built successfully!"
@@ -94,7 +136,22 @@ echo ""
echo "Checksums:" echo "Checksums:"
cat "$RELEASE_DIR/SHA256SUMS" cat "$RELEASE_DIR/SHA256SUMS"
echo "" echo ""
echo "Upload these files to your Gitea release:" case "$HOST" in
freebsd)
echo "FreeBSD binary built. To also ship a Linux binary:"
echo " Option 1 (easiest): boot into Linux and run ./build-release.sh"
echo " Option 2: run this script inside a Linux bhyve VM"
echo " Option 3: set up a Linux CI runner (e.g. Gitea Actions)"
echo " Then collect all artifacts before uploading to Gitea."
;;
linux)
echo "Linux binary built. To also ship a FreeBSD binary:"
echo " Boot into FreeBSD and run ./build-release.sh"
echo " Then collect all artifacts before uploading to Gitea."
;;
esac
echo ""
echo "Upload to Gitea:"
echo " 1. Create release: Releases -> New Release -> Tag: v${VERSION}" echo " 1. Create release: Releases -> New Release -> Tag: v${VERSION}"
echo " 2. Drag and drop files from $RELEASE_DIR/" echo " 2. Drag and drop files from $RELEASE_DIR/"
echo " 3. Save" echo " 3. Save"