Skip to content

Commit 13e63bd

Browse files
committed
Add dist target and packaging to build.sh
Ignore dist/ and add a 'dist' mode to build.sh that builds release and creates a distributable tar.gz. The script now sets DIST for a new 'dist' case, skips Metal shader compilation when mlx.metallib is up-to-date, stages the CLI binary, metallib, LICENSE and README into dist/perspective-cli-<version>, archives it, computes a SHA-256 checksum, and prints install instructions. Version uses git describe with a 'dev' fallback.
1 parent 72dfff0 commit 13e63bd

2 files changed

Lines changed: 58 additions & 23 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Swift / Xcode
22
.build/
3+
dist/
34
.swiftpm/
45
*.xcodeproj/
56
*.xcworkspace/

build.sh

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# ./build.sh Build debug (default)
66
# ./build.sh release Build release (optimized)
77
# ./build.sh clean Clean build artifacts and rebuild debug
8+
# ./build.sh dist Build release + create distributable .tar.gz
89
#
910
# This script handles both Swift compilation and Metal shader compilation,
1011
# which swift build cannot do on its own.
@@ -13,10 +14,12 @@ set -euo pipefail
1314

1415
CONFIG="debug"
1516
CLEAN=false
17+
DIST=false
1618

1719
case "${1:-}" in
1820
release) CONFIG="release" ;;
1921
clean) CLEAN=true ;;
22+
dist) CONFIG="release"; DIST=true ;;
2023
esac
2124

2225
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
@@ -66,32 +69,63 @@ if [ -f "$METALLIB" ]; then
6669

6770
if ! $NEEDS_REBUILD; then
6871
echo "mlx.metallib is up to date, skipping."
69-
echo ""
70-
echo "Build complete."
71-
exit 0
72+
SKIP_METAL=true
7273
fi
7374
fi
7475

75-
WORK=$(mktemp -d)
76-
trap 'rm -rf "$WORK"' EXIT
77-
78-
echo "Compiling Metal shaders..."
79-
for f in $(find "$METAL_DIR" -name "*.metal"); do
80-
name=$(basename "$f" .metal)
81-
echo " $name"
82-
xcrun metal -c \
83-
-I "$METAL_DIR" \
84-
-I "$METAL_DIR/steel" \
85-
-I "$METAL_DIR/steel/gemm" \
86-
-I "$METAL_DIR/steel/conv" \
87-
-I "$METAL_DIR/steel/attn" \
88-
-I "$METAL_DIR/steel/attn/kernels" \
89-
-o "$WORK/$name.air" "$f"
90-
done
91-
92-
echo "Linking mlx.metallib..."
93-
xcrun metallib -o "$WORK/mlx.metallib" "$WORK"/*.air
94-
cp "$WORK/mlx.metallib" "$METALLIB"
76+
if [ "${SKIP_METAL:-false}" = false ]; then
77+
WORK=$(mktemp -d)
78+
trap 'rm -rf "$WORK"' EXIT
79+
80+
echo "Compiling Metal shaders..."
81+
for f in $(find "$METAL_DIR" -name "*.metal"); do
82+
name=$(basename "$f" .metal)
83+
echo " $name"
84+
xcrun metal -c \
85+
-I "$METAL_DIR" \
86+
-I "$METAL_DIR/steel" \
87+
-I "$METAL_DIR/steel/gemm" \
88+
-I "$METAL_DIR/steel/conv" \
89+
-I "$METAL_DIR/steel/attn" \
90+
-I "$METAL_DIR/steel/attn/kernels" \
91+
-o "$WORK/$name.air" "$f"
92+
done
93+
94+
echo "Linking mlx.metallib..."
95+
xcrun metallib -o "$WORK/mlx.metallib" "$WORK"/*.air
96+
cp "$WORK/mlx.metallib" "$METALLIB"
97+
fi
98+
9599
echo ""
96100

101+
# ── Dist ──────────────────────────────────────────────────────────────
102+
if $DIST; then
103+
VERSION=$(git describe --tags 2>/dev/null || echo "dev")
104+
DIST_DIR="$PROJECT_DIR/dist"
105+
STAGE="$DIST_DIR/perspective-cli-${VERSION}"
106+
ARCHIVE="$DIST_DIR/perspective-cli-${VERSION}-macos-arm64.tar.gz"
107+
108+
rm -rf "$STAGE"
109+
mkdir -p "$STAGE"
110+
111+
cp "$BIN_DIR/PerspectiveCLI" "$STAGE/perspective"
112+
cp "$METALLIB" "$STAGE/mlx.metallib"
113+
cp "$PROJECT_DIR/LICENSE" "$STAGE/" 2>/dev/null || true
114+
cp "$PROJECT_DIR/README.md" "$STAGE/"
115+
116+
tar -czf "$ARCHIVE" -C "$DIST_DIR" "perspective-cli-${VERSION}"
117+
rm -rf "$STAGE"
118+
119+
SHA=$(shasum -a 256 "$ARCHIVE" | cut -d' ' -f1)
120+
121+
echo "Distribution archive created:"
122+
echo " $ARCHIVE"
123+
echo " SHA-256: $SHA"
124+
echo ""
125+
echo "To install manually:"
126+
echo " tar xzf $(basename "$ARCHIVE")"
127+
echo " cp perspective-cli-${VERSION}/perspective /usr/local/bin/"
128+
echo " cp perspective-cli-${VERSION}/mlx.metallib /usr/local/bin/"
129+
fi
130+
97131
echo "Build complete."

0 commit comments

Comments
 (0)