101 lines
2.9 KiB
Bash
101 lines
2.9 KiB
Bash
#!/bin/bash
|
|
# Build release binaries for distribution
|
|
# This script builds both Linux and Windows binaries (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
|
|
set -e
|
|
|
|
# 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
|
|
echo "Error: Could not read version from Cargo.toml"
|
|
exit 1
|
|
fi
|
|
|
|
# Optional suffix (beta1, rc1, etc.)
|
|
if [ -n "$1" ]; then
|
|
VERSION="${BASE_VERSION}-${1}"
|
|
else
|
|
VERSION="$BASE_VERSION"
|
|
fi
|
|
|
|
RELEASE_DIR="release-artifacts"
|
|
|
|
echo "Building Anvil v${VERSION} release binaries..."
|
|
echo " Version base: ${BASE_VERSION} (from Cargo.toml)"
|
|
if [ -n "$1" ]; then
|
|
echo " Suffix: ${1}"
|
|
fi
|
|
echo ""
|
|
|
|
# Clean previous artifacts
|
|
rm -rf "$RELEASE_DIR"
|
|
mkdir -p "$RELEASE_DIR"
|
|
|
|
# Build Linux binary (optimized)
|
|
echo "Building Linux x86_64 binary..."
|
|
cargo build --release
|
|
strip target/release/anvil
|
|
|
|
# Package Linux binary
|
|
echo "Packaging Linux binaries..."
|
|
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
|
|
cd ../..
|
|
|
|
# Build Windows binary (cross-compile)
|
|
echo ""
|
|
echo "Building Windows x86_64 binary..."
|
|
|
|
# Check if Windows target is installed
|
|
if ! rustup target list | grep -q "x86_64-pc-windows-gnu (installed)"; then
|
|
echo "Installing Windows 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"
|
|
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
|
|
|
|
# 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
|
|
echo ""
|
|
echo "Generating checksums..."
|
|
cd "$RELEASE_DIR"
|
|
sha256sum * > SHA256SUMS
|
|
cd ..
|
|
|
|
# Display results
|
|
echo ""
|
|
echo "==========================================================="
|
|
echo " Anvil v${VERSION} release artifacts built successfully!"
|
|
echo "==========================================================="
|
|
echo ""
|
|
echo "Artifacts in $RELEASE_DIR/:"
|
|
ls -lh "$RELEASE_DIR"
|
|
echo ""
|
|
echo "Checksums:"
|
|
cat "$RELEASE_DIR/SHA256SUMS"
|
|
echo ""
|
|
echo "Upload these files to your Gitea release:"
|
|
echo " 1. Create release: Releases -> New Release -> Tag: v${VERSION}"
|
|
echo " 2. Drag and drop files from $RELEASE_DIR/"
|
|
echo " 3. Save"
|
|
echo "" |