e8fd359f54
Add scripts/build-release-linux.sh for building musl-linked release archives (x86_64 and aarch64) on Linux. Uses `cross` for cross- compilation so no host toolchain beyond Docker/Podman is required. Also add mdrs-*.tar.gz and mdrs-*.zip to .gitignore to prevent generated release archives from being tracked. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
105 lines
3.2 KiB
Bash
Executable File
105 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build release archives for Linux (x86_64 and aarch64, musl static linking).
|
|
#
|
|
# Usage:
|
|
# ./scripts/build-release-linux.sh [VERSION]
|
|
#
|
|
# If VERSION is not provided, it is read from Cargo.toml.
|
|
# Set GITEA_TOKEN (and optionally GITEA_SERVER_URL / GITEA_REPOSITORY)
|
|
# to upload the archives to a Gitea release automatically.
|
|
# These can be provided via scripts/.env.
|
|
#
|
|
# Prerequisites:
|
|
# - cross (https://github.com/cross-rs/cross): cargo install cross
|
|
# - Docker or Podman (required by cross)
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
|
|
|
# Load .env if present (existing env vars take precedence)
|
|
if [[ -f "${SCRIPT_DIR}/.env" ]]; then
|
|
while IFS='=' read -r key value; do
|
|
[[ "${key}" =~ ^#.*$ || -z "${key}" ]] && continue
|
|
key="${key%%[[:space:]]}"
|
|
value="${value##[[:space:]]}"
|
|
[[ -z "${!key+x}" ]] && export "${key}=${value}"
|
|
done < "${SCRIPT_DIR}/.env"
|
|
fi
|
|
|
|
# Determine version
|
|
if [[ $# -ge 1 ]]; then
|
|
VERSION="$1"
|
|
else
|
|
VERSION="$(grep -m1 '^version' "${REPO_ROOT}/Cargo.toml" | sed 's/.*= *"\(.*\)"/\1/')"
|
|
fi
|
|
|
|
TAG="v${VERSION}"
|
|
TARGETS=(x86_64-unknown-linux-musl aarch64-unknown-linux-musl)
|
|
|
|
cd "${REPO_ROOT}"
|
|
|
|
# Verify that cross is available
|
|
if ! command -v cross &> /dev/null; then
|
|
echo "Error: 'cross' is not installed." >&2
|
|
echo "Install it with: cargo install cross" >&2
|
|
echo "Docker or Podman is also required." >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "==> Building mdrs ${VERSION} for Linux"
|
|
|
|
ARCHIVES=()
|
|
for TARGET in "${TARGETS[@]}"; do
|
|
echo "--- Target: ${TARGET}"
|
|
rustup target add "${TARGET}"
|
|
cross build --release --target "${TARGET}"
|
|
|
|
ARCHIVE="mdrs-${VERSION}-${TARGET}.tar.gz"
|
|
tar -czf "${ARCHIVE}" -C "target/${TARGET}/release" mdrs
|
|
ARCHIVES+=("${ARCHIVE}")
|
|
echo " Created: ${ARCHIVE}"
|
|
done
|
|
|
|
echo ""
|
|
echo "==> Archives ready:"
|
|
for A in "${ARCHIVES[@]}"; do echo " ${A}"; done
|
|
|
|
# Upload to Gitea if token is provided
|
|
if [[ -z "${GITEA_TOKEN:-}" ]]; then
|
|
echo ""
|
|
echo "GITEA_TOKEN not set — skipping upload."
|
|
echo "Set GITEA_TOKEN (and GITEA_SERVER_URL, GITEA_REPOSITORY) in scripts/.env to enable upload."
|
|
exit 0
|
|
fi
|
|
|
|
: "${GITEA_SERVER_URL:?GITEA_SERVER_URL is required for upload}"
|
|
: "${GITEA_REPOSITORY:?GITEA_REPOSITORY is required for upload}"
|
|
|
|
echo ""
|
|
echo "==> Creating Gitea release ${TAG} ..."
|
|
curl -sf -X POST \
|
|
-H "Authorization: Bearer ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
"${GITEA_SERVER_URL}/api/v1/repos/${GITEA_REPOSITORY}/releases" \
|
|
-d "{\"tag_name\": \"${TAG}\", \"name\": \"${TAG}\"}" > /dev/null || true
|
|
|
|
RELEASE_ID="$(curl -sf \
|
|
-H "Authorization: Bearer ${GITEA_TOKEN}" \
|
|
"${GITEA_SERVER_URL}/api/v1/repos/${GITEA_REPOSITORY}/releases/tags/${TAG}" \
|
|
| python3 -c 'import sys,json; print(json.load(sys.stdin)["id"])')"
|
|
|
|
echo "==> Uploading assets (release id: ${RELEASE_ID}) ..."
|
|
for ARCHIVE in "${ARCHIVES[@]}"; do
|
|
echo " Uploading ${ARCHIVE} ..."
|
|
curl -sf -X POST \
|
|
-H "Authorization: Bearer ${GITEA_TOKEN}" \
|
|
-F "attachment=@${ARCHIVE}" \
|
|
"${GITEA_SERVER_URL}/api/v1/repos/${GITEA_REPOSITORY}/releases/${RELEASE_ID}/assets" > /dev/null
|
|
echo " Done."
|
|
done
|
|
|
|
echo ""
|
|
echo "==> Upload complete: ${GITEA_SERVER_URL}/${GITEA_REPOSITORY}/releases/tag/${TAG}"
|