From 9e3e067343516519b983c09c2902648d87ea6cc6 Mon Sep 17 00:00:00 2001 From: Eric Ratliff Date: Mon, 16 Mar 2026 17:49:40 -0500 Subject: [PATCH] Able to build the FreeBSD binary --- build-release.sh | 82 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 26 deletions(-) mode change 100644 => 100755 build-release.sh diff --git a/build-release.sh b/build-release.sh old mode 100644 new mode 100755 index e4bcaae..1ab80da --- a/build-release.sh +++ b/build-release.sh @@ -1,16 +1,36 @@ -#!/bin/bash -# Build release binaries for distribution -# This script builds both Linux and Windows binaries (cross-compile) +#!/bin/sh +# Build release binaries for distribution. +# Builds a native binary for the current OS, plus Windows (cross-compile). # # Usage: # ./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 rc1 # appends suffix (e.g. 1.0.0-rc1) # -# For Windows-only builds, use build-release.ps1 on Windows -# For Linux-only builds, comment out the Windows section below +# Supported host platforms: +# 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 +# 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 BASE_VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/' | tr -d '\r') if [ -z "$BASE_VERSION" ]; then @@ -28,9 +48,10 @@ fi RELEASE_DIR="release-artifacts" echo "Building Anvil v${VERSION} release binaries..." -echo " Version base: ${BASE_VERSION} (from Cargo.toml)" +echo " Host platform: ${HOST}" +echo " Version base: ${BASE_VERSION} (from Cargo.toml)" if [ -n "$1" ]; then - echo " Suffix: ${1}" + echo " Suffix: ${1}" fi echo "" @@ -38,51 +59,57 @@ echo "" rm -rf "$RELEASE_DIR" mkdir -p "$RELEASE_DIR" -# Build Linux binary (optimized) -echo "Building Linux x86_64 binary..." +# -- Native binary ----------------------------------------------------------- +echo "Building ${HOST} x86_64 binary..." cargo build --release -strip target/release/anvil +strip target/release/anvil 2>/dev/null || true -# Package Linux binary -echo "Packaging Linux binaries..." +echo "Packaging ${HOST} binary..." cd target/release -tar -czf "../../$RELEASE_DIR/anvil-${VERSION}-linux-x86_64.tar.gz" anvil -zip -q "../../$RELEASE_DIR/anvil-${VERSION}-linux-x86_64.zip" anvil +tar -czf "../../$RELEASE_DIR/anvil-${VERSION}-${HOST}-x86_64.tar.gz" anvil cd ../.. -# Build Windows binary (cross-compile) +# -- Windows binary (cross-compile via MinGW) -------------------------------- echo "" -echo "Building Windows x86_64 binary..." +echo "Building Windows x86_64 binary (cross-compile)..." # Check if Windows target is installed if ! rustup target list | grep -q "x86_64-pc-windows-gnu (installed)"; then - echo "Installing Windows target..." + echo "Installing Windows cross-compile target..." rustup target add x86_64-pc-windows-gnu fi -# Check if MinGW is installed -if ! command -v x86_64-w64-mingw32-gcc &> /dev/null; then - echo "Warning: MinGW not found. Install with: sudo apt install mingw-w64" +# Check for MinGW linker +if ! command -v x86_64-w64-mingw32-gcc > /dev/null 2>&1; then + case "$HOST" in + linux) echo " Install with: sudo apt install mingw-w64 (Debian/Ubuntu)" ;; + freebsd) echo " Install with: sudo pkg install mingw-w64" ;; + esac echo "Skipping Windows build." else cargo build --release --target x86_64-pc-windows-gnu - x86_64-w64-mingw32-strip target/x86_64-pc-windows-gnu/release/anvil.exe + 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..." cd target/x86_64-pc-windows-gnu/release zip -q "../../../$RELEASE_DIR/anvil-${VERSION}-windows-x86_64.zip" anvil.exe cd ../../.. fi -# Generate checksums +# -- Checksums --------------------------------------------------------------- echo "" echo "Generating checksums..." 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 .. -# Display results +# -- Summary ----------------------------------------------------------------- echo "" echo "===========================================================" echo " Anvil v${VERSION} release artifacts built successfully!" @@ -94,7 +121,10 @@ echo "" echo "Checksums:" cat "$RELEASE_DIR/SHA256SUMS" echo "" -echo "Upload these files to your Gitea release:" +echo "Note: run this script on both Linux and FreeBSD to produce" +echo "all native platform binaries before creating a Gitea release." +echo "" +echo "Upload to Gitea:" echo " 1. Create release: Releases -> New Release -> Tag: v${VERSION}" echo " 2. Drag and drop files from $RELEASE_DIR/" echo " 3. Save"