-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·55 lines (44 loc) · 1.53 KB
/
build.sh
File metadata and controls
executable file
·55 lines (44 loc) · 1.53 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
#!/usr/bin/env bash
# Build all native components (Swift dylib + Rust N-API addon)
set -euo pipefail
echo "🔨 Building Apple On-Device AI library components …"
# Check if we're on macOS
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "❌ Error: This library can only be built on macOS"
exit 1
fi
# Require macOS 26+ (FoundationModels)
MACOS_MAJOR=$(sw_vers -productVersion | cut -d. -f1)
if (( MACOS_MAJOR < 26 )); then
echo "❌ Need macOS 26.0+ (FoundationModels). Current: $(sw_vers -productVersion)" >&2
exit 1
fi
# Create build directory
mkdir -p build
# Build Swift dylib
echo "📦 Swift → build/libappleai.dylib"
swiftc \
-O -whole-module-optimization \
-emit-library -emit-module -module-name AppleOnDeviceAI \
-framework Foundation -framework FoundationModels \
-target arm64-apple-macos26.0 \
-Xlinker -install_name -Xlinker @rpath/libappleai.dylib \
-Xlinker -rpath -Xlinker @loader_path \
src/apple-ai.swift \
-o build/libappleai.dylib
echo "✅ Swift dylib built"
# Build Rust addon
echo "🦀 Cargo (release)"
pushd native >/dev/null
cargo build --release --quiet
popd >/dev/null
# Copy and rename the compiled addon to the build directory so Node/Bun can load it
ADDON_SRC="native/target/release/libapple_ai_napi.dylib"
ADDON_DST="build/apple_ai_napi.node"
if [[ -f "$ADDON_SRC" ]]; then
cp "$ADDON_SRC" "$ADDON_DST"
echo "📁 Native addon location: $ADDON_DST"
else
echo "⚠️ Rust addon not found at $ADDON_SRC. Did the build fail?"
fi
echo "🎉 All components built successfully!"