forked from mazdak/AudioWhisper
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·397 lines (345 loc) · 13 KB
/
build.sh
File metadata and controls
executable file
·397 lines (345 loc) · 13 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/bin/bash
# FluidVoice Release Build Script
# For development, use: swift build && swift run
# This script is for creating distributable releases
# Parse command line arguments
NOTARIZE=false
while [[ $# -gt 0 ]]; do
case $1 in
--notarize)
NOTARIZE=true
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--notarize]"
exit 1
;;
esac
done
# Load environment variables from .env file if it exists
if [[ -f .env ]]; then
echo "📁 Loading environment from .env..."
set -a # Automatically export all variables
source .env
set +a # Disable automatic export
if [[ -n "$CODE_SIGN_IDENTITY" ]]; then
echo "🔐 Code signing identity loaded from .env"
fi
fi
# Generate version info
GIT_HASH=$(git rev-parse HEAD 2>/dev/null || echo "unknown")
BUILD_DATE=$(date '+%Y-%m-%d')
# Read version from VERSION file or use environment variable
DEFAULT_VERSION=$(cat VERSION | tr -d '[:space:]')
VERSION="${AUDIO_WHISPER_VERSION:-$DEFAULT_VERSION}"
echo "🎙️ Building FluidVoice version $VERSION..."
# Update Info.plist with current version
if [ -f "Info.plist" ]; then
echo "Updating Info.plist version to $VERSION..."
# Update CFBundleShortVersionString
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $VERSION" Info.plist 2>/dev/null ||
sed -i '' "s|<key>CFBundleShortVersionString</key>[[:space:]]*<string>[^<]*</string>|<key>CFBundleShortVersionString</key><string>$VERSION</string>|" Info.plist
# Update CFBundleVersion (remove dots for build number)
BUILD_NUMBER="${VERSION//./}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" Info.plist 2>/dev/null ||
sed -i '' "s|<key>CFBundleVersion</key>[[:space:]]*<string>[^<]*</string>|<key>CFBundleVersion</key><string>$BUILD_NUMBER</string>|" Info.plist
fi
# Clean previous builds (but preserve cache)
rm -rf .build/apple/Products/Release
rm -rf FluidVoice.app
rm -f Sources/AudioProcessorCLI
# Preserve .build directory for incremental builds
# Create version file from template
if [ -f "Sources/VersionInfo.swift.template" ]; then
sed -e "s/VERSION_PLACEHOLDER/$VERSION/g" \
-e "s/GIT_HASH_PLACEHOLDER/$GIT_HASH/g" \
-e "s/BUILD_DATE_PLACEHOLDER/$BUILD_DATE/g" \
Sources/VersionInfo.swift.template >Sources/VersionInfo.swift
echo "Generated VersionInfo.swift from template"
else
echo "Warning: VersionInfo.swift.template not found, using fallback"
cat >Sources/VersionInfo.swift <<EOF
import Foundation
struct VersionInfo {
static let version = "$VERSION"
static let gitHash = "$GIT_HASH"
static let buildDate = "$BUILD_DATE"
static var displayVersion: String {
if gitHash != "unknown" && !gitHash.isEmpty {
let shortHash = String(gitHash.prefix(7))
return "\(version) (\(shortHash))"
}
return version
}
static var fullVersionInfo: String {
var info = "FluidVoice \(version)"
if gitHash != "unknown" && !gitHash.isEmpty {
let shortHash = String(gitHash.prefix(7))
info += " • \(shortHash)"
}
if buildDate.count > 0 {
info += " • \(buildDate)"
}
return info
}
}
EOF
fi
# Set build cache for performance
export SWIFT_BUILD_CACHE_PATH="${SWIFT_BUILD_CACHE_PATH:-$HOME/.swift-build-cache}"
mkdir -p "$SWIFT_BUILD_CACHE_PATH"
# Build for release with optimizations
echo "📦 Building for release with cache at $SWIFT_BUILD_CACHE_PATH..."
CORE_COUNT=$(sysctl -n hw.logicalcpu)
swift build \
-c release \
--arch arm64 --arch x86_64 \
-j $CORE_COUNT \
-Xswiftc -enforce-exclusivity=unchecked \
-Xswiftc -whole-module-optimization
if [ $? -ne 0 ]; then
echo "❌ Build failed!"
exit 1
fi
# Create app bundle
echo "Creating app bundle..."
mkdir -p FluidVoice.app/Contents/MacOS
mkdir -p FluidVoice.app/Contents/Resources
mkdir -p FluidVoice.app/Contents/Resources/bin
# Set build number for Info.plist
BUILD_NUMBER="${VERSION//./}"
# Copy executable (universal binary)
cp .build/apple/Products/Release/FluidVoice FluidVoice.app/Contents/MacOS/
# Copy Python scripts for Parakeet and MLX support
if [ -f "Sources/parakeet_transcribe_pcm.py" ]; then
cp Sources/parakeet_transcribe_pcm.py FluidVoice.app/Contents/Resources/
echo "Copied Parakeet PCM Python script"
else
echo "⚠️ parakeet_transcribe_pcm.py not found, Parakeet functionality will not work"
fi
if [ -f "Sources/parakeet_daemon.py" ]; then
cp Sources/parakeet_daemon.py FluidVoice.app/Contents/Resources/
echo "Copied Parakeet daemon Python script"
else
echo "⚠️ parakeet_daemon.py not found, Parakeet daemon mode will not work"
fi
if [ -f "Sources/mlx_semantic_correct.py" ]; then
cp Sources/mlx_semantic_correct.py FluidVoice.app/Contents/Resources/
echo "Copied MLX semantic correction Python script"
else
echo "⚠️ mlx_semantic_correct.py not found, MLX semantic correction will not work"
fi
# Bundle uv (Apple Silicon). Download if needed, prefer repo copy, else fall back to system uv
if [ -f "Sources/Resources/bin/uv" ]; then
cp Sources/Resources/bin/uv FluidVoice.app/Contents/Resources/bin/uv
chmod +x FluidVoice.app/Contents/Resources/bin/uv
echo "Bundled uv binary (from repo)"
else
echo "📦 Downloading UV binary for Python package management..."
mkdir -p "Sources/Resources/bin"
# Detect architecture for the correct UV binary
ARCH=$(uname -m)
if [ "$ARCH" = "arm64" ]; then
UV_URL="https://github.com/astral-sh/uv/releases/latest/download/uv-aarch64-apple-darwin.tar.gz"
else
UV_URL="https://github.com/astral-sh/uv/releases/latest/download/uv-x86_64-apple-darwin.tar.gz"
fi
# Download and extract UV binary
curl -L "$UV_URL" | tar -xz -C "Sources/Resources/bin" --strip-components=1
chmod +x "Sources/Resources/bin/uv"
# Now copy to app bundle
cp Sources/Resources/bin/uv FluidVoice.app/Contents/Resources/bin/uv
chmod +x FluidVoice.app/Contents/Resources/bin/uv
echo "✅ UV binary downloaded and bundled"
fi
# Bundle pyproject.toml and uv.lock if present
if [ -f "Sources/Resources/pyproject.toml" ]; then
cp Sources/Resources/pyproject.toml FluidVoice.app/Contents/Resources/pyproject.toml
echo "Bundled pyproject.toml"
else
echo "ℹ️ No pyproject.toml found in Sources/Resources"
fi
# Note: AudioProcessorCLI binary no longer needed - using direct Swift audio processing
# Create proper Info.plist
echo "Creating Info.plist..."
cat >FluidVoice.app/Contents/Info.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>FluidVoice</string>
<key>CFBundleIdentifier</key>
<string>com.fluidvoice.app</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>FluidVoice</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$VERSION</string>
<key>CFBundleVersion</key>
<string>$BUILD_NUMBER</string>
<key>LSMinimumSystemVersion</key>
<string>14.0</string>
<key>NSMicrophoneUsageDescription</key>
<string>FluidVoice needs access to your microphone to record audio for transcription.</string>
<key>LSUIElement</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>api.openai.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>generativelanguage.googleapis.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>huggingface.co</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
</dict>
</plist>
EOF
# Generate app icon from our source image
if [ -f "FluidVoiceIcon.png" ]; then
./generate-icons.sh
# Create proper icns file directly in app bundle
if command -v iconutil >/dev/null 2>&1; then
iconutil -c icns FluidVoice.iconset -o FluidVoice.app/Contents/Resources/AppIcon.icns 2>/dev/null || echo "Note: iconutil failed, app will use default icon"
fi
# Clean up temporary files
rm -rf FluidVoice.iconset
rm -f AppIcon.icns # Remove any stray icns file from root
else
echo "⚠️ FluidVoiceIcon.png not found, app will use default icon"
fi
# Make executable
chmod +x FluidVoice.app/Contents/MacOS/FluidVoice
# Use existing entitlements file
if [ ! -f "FluidVoice.entitlements" ]; then
echo "❌ FluidVoice.entitlements not found - required for hardened runtime"
exit 1
fi
echo "🔐 Using existing FluidVoice.entitlements for hardened runtime..."
# Function to sign the app with a given identity
sign_app() {
local identity="$1"
local identity_name="$2"
if [ -n "$identity_name" ]; then
echo "🔏 Code signing app with: $identity_name ($identity)"
else
echo "🔏 Code signing app with: $identity"
fi
# Sign uv binary if present (nested executable)
if [ -f "FluidVoice.app/Contents/Resources/bin/uv" ]; then
codesign --force --sign "$identity" --options runtime --entitlements FluidVoice.entitlements FluidVoice.app/Contents/Resources/bin/uv
fi
codesign --force --deep --sign "$identity" --options runtime --entitlements FluidVoice.entitlements --identifier "com.fluidvoice.app" FluidVoice.app
if [ $? -eq 0 ]; then
echo "🔍 Verifying signature..."
codesign --verify --verbose FluidVoice.app
echo "✅ App signed successfully"
return 0
else
echo "❌ Code signing failed"
return 1
fi
}
# Optional: Code sign the app (requires Apple Developer account)
SIGNING_IDENTITY=""
SIGNING_NAME=""
if [ -n "$CODE_SIGN_IDENTITY" ]; then
SIGNING_IDENTITY="$CODE_SIGN_IDENTITY"
else
# Try to auto-detect Developer ID (use the first one found)
DETECTED_HASH=$(security find-identity -v -p codesigning | grep "Developer ID Application" | head -1 | awk '{print $2}')
DETECTED_NAME=$(security find-identity -v -p codesigning | grep "Developer ID Application" | head -1 | awk '{print $3}' | tr -d '"')
if [ -n "$DETECTED_HASH" ]; then
echo "🔍 Auto-detected signing identity: $DETECTED_NAME"
SIGNING_IDENTITY="$DETECTED_HASH"
SIGNING_NAME="$DETECTED_NAME"
fi
fi
if [ -n "$SIGNING_IDENTITY" ]; then
sign_app "$SIGNING_IDENTITY" "$SIGNING_NAME"
else
echo "💡 No Developer ID found. App will be unsigned."
echo "💡 To sign the app, get a Developer ID certificate from Apple Developer Portal."
fi
# Keep entitlements file (shared with dev builds)
# Notarization (requires code signing first)
if [ "$NOTARIZE" = true ]; then
echo ""
echo "🔐 Starting notarization process..."
# Check for required environment variables
if [ -z "$AUDIO_WHISPER_APPLE_ID" ] || [ -z "$AUDIO_WHISPER_APPLE_PASSWORD" ] || [ -z "$AUDIO_WHISPER_TEAM_ID" ]; then
echo "❌ Notarization requires the following environment variables:"
echo " AUDIO_WHISPER_APPLE_ID - Your Apple ID email"
echo " AUDIO_WHISPER_APPLE_PASSWORD - App-specific password for notarization"
echo " AUDIO_WHISPER_TEAM_ID - Your Apple Developer Team ID"
echo ""
echo "To create an app-specific password:"
echo "1. Go to https://appleid.apple.com/account/manage"
echo "2. Sign in and go to Security > App-Specific Passwords"
echo "3. Generate a new password for FluidVoice notarization"
echo ""
exit 1
fi
# Check if app is signed
if codesign -dvvv FluidVoice.app 2>&1 | grep -q "Signature=adhoc"; then
echo "❌ App must be properly signed before notarization (not adhoc signed)"
echo "Please ensure CODE_SIGN_IDENTITY is set or a Developer ID is available"
exit 1
fi
# Create a zip file for notarization
echo "Creating zip for notarization..."
ditto -c -k --keepParent FluidVoice.app FluidVoice.zip
# Submit for notarization
echo "📤 Submitting to Apple for notarization..."
xcrun notarytool submit FluidVoice.zip \
--apple-id "$AUDIO_WHISPER_APPLE_ID" \
--password "$AUDIO_WHISPER_APPLE_PASSWORD" \
--team-id "$AUDIO_WHISPER_TEAM_ID" \
--wait 2>&1 | tee notarization.log
# Check if notarization was successful
if grep -q "status: Accepted" notarization.log; then
# Staple the notarization ticket to the app
echo "📎 Stapling notarization ticket..."
xcrun stapler staple FluidVoice.app
if [ $? -eq 0 ]; then
echo "✅ Notarization ticket stapled successfully!"
else
echo "⚠️ Failed to staple notarization ticket, but app is notarized"
fi
else
echo "❌ Notarization failed. Check notarization.log for details"
echo ""
echo "Common issues:"
echo "- Ensure your Apple ID has accepted all developer agreements"
echo "- Check that your app-specific password is correct"
echo "- Verify your Team ID is correct"
exit 1
fi
# Clean up
rm -f FluidVoice.zip
rm -f notarization.log
fi
echo "✅ Build complete!"
echo ""
open -R FluidVoice.app