Files
RustProxy/build-release.sh
T
2026-10-31 23:42:58 +01:00

69 lines
1.9 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT"
DIST="$ROOT/dist"
CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT/target}"
export CARGO_TARGET_DIR
fail() {
printf 'error: %s\n' "$*" >&2
exit 1
}
need() {
command -v "$1" >/dev/null 2>&1 || fail "$1 is required"
}
need cargo
need rustc
need python3
need sha256sum
python3 -c 'import sys; sys.exit(0 if sys.version_info >= (3,10) else 1)' \
|| fail 'Python 3.10+ is required'
[[ -f Cargo.toml ]] || fail 'run this script from the RustProxy project root'
[[ -f Cargo.lock ]] || fail 'Cargo.lock is required for a reproducible release'
[[ -f scripts/preflight.py ]] || fail 'scripts/preflight.py is missing'
VERSION="$(python3 scripts/version.py)"
HOST="$(rustc -vV | sed -n 's/^host: //p')"
[[ -n "$VERSION" ]] || fail 'could not determine project version'
[[ -n "$HOST" ]] || fail 'could not determine Rust host target'
printf 'RustProxy %s release build for %s\n' "$VERSION" "$HOST"
python3 scripts/preflight.py
cargo fmt --all -- --check
cargo test --locked --all-targets
cargo clippy --locked --all-targets -- -D warnings
rm -rf "$CARGO_TARGET_DIR/release"
cargo build --locked --release
BIN="$CARGO_TARGET_DIR/release/rust-proxy"
[[ -x "$BIN" ]] || fail "release binary was not created: $BIN"
ACTUAL_VERSION="$($BIN --version)"
printf 'Built: %s\n' "$ACTUAL_VERSION"
rm -rf "$DIST"
mkdir -p "$DIST"
ARTIFACT="rust-proxy-${VERSION}-${HOST}"
cp "$BIN" "$DIST/$ARTIFACT"
chmod 0755 "$DIST/$ARTIFACT"
sha256sum "$DIST/$ARTIFACT" > "$DIST/$ARTIFACT.sha256"
SOURCE_ZIP="$DIST/RustProxy-${VERSION}-source.zip"
python3 make_zip.py "$SOURCE_ZIP"
sha256sum "$SOURCE_ZIP" > "$SOURCE_ZIP.sha256"
printf '\nRelease ready:\n'
printf ' binary: %s\n' "$DIST/$ARTIFACT"
printf ' checksum: %s\n' "$DIST/$ARTIFACT.sha256"
printf ' source zip: %s\n' "$SOURCE_ZIP"
printf ' checksum: %s\n' "$SOURCE_ZIP.sha256"