Skip to content

Commit 350396d

Browse files
authored
fix: restore local build scripts to scripts/ (#50)
* chore: move remaining test files to sandbox * chore: fix markdown referential links and sandbox movement * chore: move root-level markdown files into docs/ and docs/profiling/ * fix: restore build.sh and build_swiftbuddy.sh to scripts/ (accidentally deleted)
1 parent 641648d commit 350396d

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

scripts/build.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
echo "=============================================="
5+
echo " SwiftLM Build Script "
6+
echo "=============================================="
7+
8+
# --- 1. Submodules ---
9+
echo ""
10+
echo "=> [1/4] Initializing submodules..."
11+
# git submodule update --init --recursive
12+
13+
# --- 2. Check for cmake and resolve Swift dependencies ---
14+
echo ""
15+
echo "=> [2/4] Checking dependencies and resolving packages..."
16+
swift package resolve
17+
echo "=> [2/4] Checking build dependencies..."
18+
if ! command -v cmake &> /dev/null; then
19+
echo "cmake not found. Installing via Homebrew..."
20+
if ! command -v brew &> /dev/null; then
21+
echo "❌ Homebrew is required to install cmake."
22+
echo " Install Homebrew: https://brew.sh"
23+
exit 1
24+
fi
25+
brew install cmake
26+
fi
27+
echo " cmake: $(cmake --version | head -1)"
28+
29+
# --- 3. Build the Metal kernel library (mlx.metallib) from source ---
30+
echo ""
31+
echo "=> [3/4] Building Metal kernels (mlx.metallib)..."
32+
33+
MLX_SRC=".build/checkouts/mlx-swift/Source/Cmlx/mlx"
34+
METALLIB_BUILD_DIR=".build/metallib_build"
35+
METALLIB_DEST=".build/arm64-apple-macosx/release"
36+
37+
rm -rf "$METALLIB_BUILD_DIR"
38+
mkdir -p "$METALLIB_BUILD_DIR"
39+
40+
pushd "$METALLIB_BUILD_DIR" > /dev/null
41+
42+
cmake "../../$MLX_SRC" \
43+
-DMLX_BUILD_TESTS=OFF \
44+
-DMLX_BUILD_EXAMPLES=OFF \
45+
-DMLX_BUILD_BENCHMARKS=OFF \
46+
-DMLX_BUILD_PYTHON_BINDINGS=OFF \
47+
-DMLX_METAL_JIT=OFF \
48+
-DMLX_ENABLE_NAX=1 \
49+
-DCMAKE_BUILD_TYPE=Release \
50+
2>&1 | tail -40
51+
52+
echo " Compiling Metal shaders..."
53+
if ! make mlx-metallib -j$(sysctl -n hw.ncpu) 2>&1 | tail -80; then
54+
echo "❌ Failed to build mlx.metallib. If you see 'missing Metal Toolchain', run:"
55+
echo " xcodebuild -downloadComponent MetalToolchain"
56+
exit 1
57+
fi
58+
59+
popd > /dev/null
60+
61+
# Copy the freshly built metallib next to the binary, explicitly naming it default.metallib for mlx-c
62+
mkdir -p "$METALLIB_DEST"
63+
if [ -f "$METALLIB_BUILD_DIR/lib/mlx.metallib" ]; then
64+
cp "$METALLIB_BUILD_DIR/lib/mlx.metallib" "$METALLIB_DEST/default.metallib"
65+
echo "✅ Built and copied default.metallib to $METALLIB_DEST/"
66+
elif [ -f "$METALLIB_BUILD_DIR/mlx.metallib" ]; then
67+
cp "$METALLIB_BUILD_DIR/mlx.metallib" "$METALLIB_DEST/default.metallib"
68+
echo "✅ Built and copied default.metallib to $METALLIB_DEST/"
69+
else
70+
# Search for it anywhere in the build dir
71+
BUILT=$(find "$METALLIB_BUILD_DIR" -name "mlx.metallib" | head -1)
72+
if [ -n "$BUILT" ]; then
73+
cp "$BUILT" "$METALLIB_DEST/default.metallib"
74+
echo "✅ Built and copied default.metallib to $METALLIB_DEST/"
75+
else
76+
echo "❌ Failed to build mlx.metallib. Check cmake output above."
77+
exit 1
78+
fi
79+
fi
80+
81+
# --- 4. Build SwiftLM ---
82+
echo ""
83+
echo "=> [4/4] Building SwiftLM (release)..."
84+
swift build -c release
85+
86+
echo ""
87+
echo "=============================================="
88+
echo "✅ Build complete!"
89+
echo " Binary: .build/release/SwiftLM"
90+
echo " Metallib: $METALLIB_DEST/mlx.metallib"
91+
echo "=============================================="

scripts/build_swiftbuddy.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# Navigate to the script's directory, then into SwiftBuddy
4+
cd "$(dirname "$0")/SwiftBuddy" || exit
5+
6+
echo "🔄 Generating SwiftBuddy Xcode Project..."
7+
python3 generate_xcodeproj.py
8+
9+
echo "🚀 Opening SwiftBuddy.xcodeproj in Xcode..."
10+
open SwiftBuddy.xcodeproj

0 commit comments

Comments
 (0)