|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +usage() { |
| 5 | + cat <<'EOF' |
| 6 | +Usage: scripts/build-release.sh --arch <arm64|x86_64> --version <tag> [--dist-root <dir>] |
| 7 | +
|
| 8 | +Builds release binaries and stages them under: |
| 9 | + <dist-root>/<arch>/bin/ |
| 10 | +EOF |
| 11 | +} |
| 12 | + |
| 13 | +arch="" |
| 14 | +version="" |
| 15 | +dist_root="dist" |
| 16 | + |
| 17 | +while [[ $# -gt 0 ]]; do |
| 18 | + case "$1" in |
| 19 | + --arch) |
| 20 | + arch="${2:-}" |
| 21 | + shift 2 |
| 22 | + ;; |
| 23 | + --version) |
| 24 | + version="${2:-}" |
| 25 | + shift 2 |
| 26 | + ;; |
| 27 | + --dist-root) |
| 28 | + dist_root="${2:-}" |
| 29 | + shift 2 |
| 30 | + ;; |
| 31 | + -h|--help) |
| 32 | + usage |
| 33 | + exit 0 |
| 34 | + ;; |
| 35 | + *) |
| 36 | + echo "Unknown argument: $1" >&2 |
| 37 | + usage |
| 38 | + exit 1 |
| 39 | + ;; |
| 40 | + esac |
| 41 | +done |
| 42 | + |
| 43 | +if [[ -z "$arch" ]]; then |
| 44 | + echo "--arch is required." >&2 |
| 45 | + usage |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +if [[ -z "$version" ]]; then |
| 50 | + echo "--version is required." >&2 |
| 51 | + usage |
| 52 | + exit 1 |
| 53 | +fi |
| 54 | + |
| 55 | +case "$arch" in |
| 56 | + arm64|x86_64) ;; |
| 57 | + *) |
| 58 | + echo "Unsupported arch: $arch (expected arm64 or x86_64)" >&2 |
| 59 | + exit 1 |
| 60 | + ;; |
| 61 | +esac |
| 62 | + |
| 63 | +repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 64 | +if [[ "$dist_root" = /* ]]; then |
| 65 | + dist_base="$dist_root" |
| 66 | +else |
| 67 | + dist_base="$repo_root/$dist_root" |
| 68 | +fi |
| 69 | + |
| 70 | +out_dir="$dist_base/$arch" |
| 71 | +bin_out="$out_dir/bin" |
| 72 | +products=( |
| 73 | + "xcode-mcp-proxy" |
| 74 | + "xcode-mcp-proxy-server" |
| 75 | + "xcode-mcp-proxy-install" |
| 76 | +) |
| 77 | + |
| 78 | +pushd "$repo_root" >/dev/null |
| 79 | + |
| 80 | +for product in "${products[@]}"; do |
| 81 | + swift build -c release \ |
| 82 | + -Xswiftc -strict-concurrency=minimal \ |
| 83 | + --arch "$arch" \ |
| 84 | + --product "$product" |
| 85 | +done |
| 86 | + |
| 87 | +bin_path="$(swift build -c release --arch "$arch" --show-bin-path)" |
| 88 | +rm -rf "$out_dir" |
| 89 | +mkdir -p "$bin_out" |
| 90 | + |
| 91 | +for product in "${products[@]}"; do |
| 92 | + source_path="$bin_path/$product" |
| 93 | + if [[ ! -f "$source_path" ]]; then |
| 94 | + source_path="$(find "$repo_root/.build" -type f -path "*/release/$product" | head -n 1 || true)" |
| 95 | + fi |
| 96 | + if [[ -z "$source_path" || ! -f "$source_path" ]]; then |
| 97 | + echo "Failed to locate built binary: $product" >&2 |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | + |
| 101 | + target_path="$bin_out/$product" |
| 102 | + cp "$source_path" "$target_path" |
| 103 | + chmod +x "$target_path" |
| 104 | + if command -v codesign >/dev/null 2>&1; then |
| 105 | + codesign --remove-signature "$target_path" >/dev/null 2>&1 || true |
| 106 | + fi |
| 107 | +done |
| 108 | + |
| 109 | +cat > "$out_dir/manifest.txt" <<EOF |
| 110 | +version=$version |
| 111 | +arch=$arch |
| 112 | +built_at=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 113 | +EOF |
| 114 | + |
| 115 | +popd >/dev/null |
| 116 | + |
| 117 | +echo "Staged release binaries at: $out_dir" |
0 commit comments