Repository navigation
Expand file tree
/
Copy pathbuild-release.sh
More file actions
executable file
·96 lines (80 loc) · 2.74 KB
/
Copy pathbuild-release.sh
File metadata and controls
executable file
·96 lines (80 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
# Build release artifacts locally.
#
# Usage:
# ./scripts/build-release.sh # Build for current platform
# ./scripts/build-release.sh all # Build all macOS targets (arm64 + amd64)
set -euo pipefail
BINARY_NAME="zero"
DIST_DIR="dist"
# Read version from Cargo.toml
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
echo "Building ${BINARY_NAME} v${VERSION}"
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "macos" ;;
*) echo "unknown" ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
*) echo "unknown" ;;
esac
}
rust_target() {
local os="$1" arch="$2"
case "${os}-${arch}" in
macos-arm64) echo "aarch64-apple-darwin" ;;
macos-amd64) echo "x86_64-apple-darwin" ;;
linux-amd64) echo "x86_64-unknown-linux-gnu" ;;
linux-arm64) echo "aarch64-unknown-linux-gnu" ;;
*) echo ""; return 1 ;;
esac
}
package_artifact() {
local target="$1" os_arch="$2"
local artifact_name="${BINARY_NAME}-${VERSION}-${os_arch}"
echo "Building for ${target}..."
cargo build --release --target "${target}" -p zero-cli
mkdir -p "${DIST_DIR}/${artifact_name}"
cp "target/${target}/release/${BINARY_NAME}" "${DIST_DIR}/${artifact_name}/"
cp LICENSE README.md "${DIST_DIR}/${artifact_name}/" 2>/dev/null || true
# Include macOS app icon for bundle creation during install
if [[ "$os_arch" == macos-* ]] && [ -f "assets/AppIcon.icns" ]; then
cp "assets/AppIcon.icns" "${DIST_DIR}/${artifact_name}/"
fi
cd "${DIST_DIR}"
tar -czf "${artifact_name}.tgz" "${artifact_name}"
shasum -a 512 "${artifact_name}.tgz" | cut -d' ' -f1 > "${artifact_name}.tgz.sha512"
cd ..
echo " → ${DIST_DIR}/${artifact_name}.tgz"
echo " → ${DIST_DIR}/${artifact_name}.tgz.sha512"
}
# Clean previous dist
rm -rf "${DIST_DIR}"
mkdir -p "${DIST_DIR}"
OS=$(detect_os)
ARCH=$(detect_arch)
if [ "${1:-}" = "all" ]; then
if [ "$OS" != "macos" ]; then
echo "Error: 'all' only supports macOS (cross-compiles arm64 + amd64)"
exit 1
fi
# Ensure both targets are installed
rustup target add aarch64-apple-darwin x86_64-apple-darwin 2>/dev/null || true
package_artifact "aarch64-apple-darwin" "macos-arm64"
package_artifact "x86_64-apple-darwin" "macos-amd64"
else
TARGET=$(rust_target "$OS" "$ARCH")
if [ -z "$TARGET" ]; then
echo "Error: unsupported platform ${OS}-${ARCH}"
exit 1
fi
package_artifact "$TARGET" "${OS}-${ARCH}"
fi
echo ""
echo "Done. Artifacts in ${DIST_DIR}/:"
ls -lh "${DIST_DIR}"/*.tgz "${DIST_DIR}"/*.sha512 2>/dev/null