Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
261 lines (241 loc) · 12 KB
/
Copy pathMakefile
File metadata and controls
261 lines (241 loc) · 12 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
APP_NAME ?= LocalFlow Dev
.DEFAULT_GOAL := all
BUNDLE_ID ?= com.ajbarryiii.localflow.dev
BUILD_DIR = build
APP_BUNDLE = $(BUILD_DIR)/$(APP_NAME).app
CODESIGN_IDENTITY ?= -
CONTENTS = $(APP_BUNDLE)/Contents
MACOS_DIR = $(CONTENTS)/MacOS
empty :=
space := $(empty) $(empty)
APP_EXECUTABLE = $(MACOS_DIR)/$(APP_NAME)
APP_EXECUTABLE_TARGET := $(subst $(space),\ ,$(APP_EXECUTABLE))
SOURCES = $(shell find Sources -name '*.swift' -type f | LC_ALL=C sort)
TEST_RUNNER = $(BUILD_DIR)/LocalFlowTests
TEST_PRODUCTION_SOURCES = \
Sources/AppName.swift \
Sources/ClipboardTransaction.swift \
Sources/DictationStats.swift \
Sources/InsertionContextFormatter.swift \
Sources/InsertionContextProbe.swift \
Sources/PermissionPanelCore.swift \
Sources/PrivacyPermission.swift \
Sources/LocalDictationCore.swift \
Sources/OverlayWaveformMetrics.swift \
Sources/PipelineHistoryItem.swift \
Sources/PipelineHistoryStore.swift \
Sources/SettingsKeys.swift \
Sources/SetupFlowCore.swift \
Sources/SpokenNumberFormatter.swift \
Sources/Dictionary/BiasGraph.swift \
Sources/Dictionary/BPEEncoder.swift \
Sources/Dictionary/CasingRestorer.swift \
Sources/Dictionary/CorrectionCandidates.swift \
Sources/Dictionary/CorrectionSessionStore.swift \
Sources/Dictionary/CorrectionWatcher.swift \
Sources/Dictionary/DictionaryEditor.swift \
Sources/Dictionary/DictionaryEntry.swift \
Sources/Dictionary/DictionaryText.swift \
Sources/Dictionary/StrengthProbe.swift \
Sources/Dictionary/SuggestionPresentationGate.swift \
Sources/Dictionary/VerifyDecision.swift \
Sources/DictionaryApps.swift \
Sources/Parakeet/LocalParakeetCore.swift \
Sources/Parakeet/LocalParakeetService.swift \
Sources/Parakeet/ParakeetAudioReader.swift \
Sources/Parakeet/ParakeetDecoder.swift \
Sources/Parakeet/ParakeetFrames.swift \
Sources/Parakeet/ParakeetFrontEnd.swift \
Sources/Parakeet/ParakeetModelStore.swift \
Sources/Parakeet/ParakeetSilenceCompactor.swift \
Sources/UpdateInstaller.swift \
Sources/UpdateManager.swift \
Sources/UpdateSignatureVerifier.swift \
Sources/RecordingLifecycle.swift \
Sources/ShortcutCore/DictationShortcutSessionController.swift \
Sources/ShortcutCore/DoubleTapPromptDetector.swift \
Sources/ShortcutCore/ShortcutMatcher.swift \
Sources/ShortcutCore/ShortcutModels.swift \
Sources/ShortcutCore/ShortcutStore.swift
TEST_SOURCES = $(shell find Tests -name '*.swift' -type f | LC_ALL=C sort)
SHELL_SCRIPTS = $(shell find .github/scripts .agents/skills -name '*.sh' -type f | LC_ALL=C sort)
YAML_FILES = $(shell find .github -type f \( -name '*.yml' -o -name '*.yaml' \) | LC_ALL=C sort)
RESOURCES = $(CONTENTS)/Resources
ARCH ?= $(shell uname -m)
# macOS 26 deprecates the legacy CBLAS declarations the Parakeet decoder calls;
# the new LAPACK headers keep the same 32-bit signatures.
ACCELERATE_FLAGS = -Xcc -DACCELERATE_NEW_LAPACK
PARAKEET_BUNDLE_DIR ?=
SWIFT_OPTIMIZATION ?= $(if $(strip $(PARAKEET_BUNDLE_DIR)),-O,-Onone)
PARAKEET_BUNDLE_STAMP = $(BUILD_DIR)/parakeet-bundle-selection
PARAKEET_INSTALL_KEY = $(BUILD_DIR)/$(APP_NAME).parakeet-installed
# Rebuild when switching between model bundles (including back to no bundle).
# Weights remain outside Git and are copied only into the local app bundle.
.PHONY: parakeet-selection
parakeet-selection:
@mkdir -p "$(BUILD_DIR)"
@printf '%s\n' "$(PARAKEET_BUNDLE_DIR)" > "$(PARAKEET_BUNDLE_STAMP).tmp"
@printf '%s\n' "$(SWIFT_OPTIMIZATION)" >> "$(PARAKEET_BUNDLE_STAMP).tmp"
ifneq ($(strip $(PARAKEET_BUNDLE_DIR)),)
@shasum -a 256 "$(PARAKEET_BUNDLE_DIR)/bundle.json" >> "$(PARAKEET_BUNDLE_STAMP).tmp"
endif
@cmp -s "$(PARAKEET_BUNDLE_STAMP).tmp" "$(PARAKEET_BUNDLE_STAMP)" || mv "$(PARAKEET_BUNDLE_STAMP).tmp" "$(PARAKEET_BUNDLE_STAMP)"
@rm -f "$(PARAKEET_BUNDLE_STAMP).tmp"
$(PARAKEET_BUNDLE_STAMP): parakeet-selection
# Pick the icon source based on which bundle we are building. Dev builds get
# a small amber badge on the waveform so a developer's dock shows at a glance
# which LocalFlow they are running when both are installed side by side.
ifeq ($(APP_NAME),LocalFlow Dev)
ICON_SOURCE = Resources/AppIcon-Dev-Source.png
ICON_ICNS = Resources/AppIcon-Dev.icns
else
ICON_SOURCE = Resources/AppIcon-Source.png
ICON_ICNS = Resources/AppIcon.icns
endif
.PHONY: all check clean run icon dmg codesign-dmg notarize release-preflight test typecheck validate
all: parakeet-selection $(APP_EXECUTABLE_TARGET)
$(APP_EXECUTABLE_TARGET): $(SOURCES) Info.plist $(ICON_ICNS) $(PARAKEET_BUNDLE_STAMP) $(wildcard Resources/Parakeet/*) Resources/Attribution.txt LICENSE scripts/label-localflow-model.py
@mkdir -p "$(MACOS_DIR)" "$(RESOURCES)"
ifneq ($(ARCH),arm64)
$(error LocalFlow builds for Apple Silicon only; set ARCH=arm64 (got "$(ARCH)"))
endif
swiftc \
-parse-as-library \
$(SWIFT_OPTIMIZATION) \
-o "$(MACOS_DIR)/$(APP_NAME)" \
-sdk $(shell xcrun --show-sdk-path) \
-target $(ARCH)-apple-macosx26.0 $(ACCELERATE_FLAGS) \
$(SOURCES)
@cp Info.plist "$(CONTENTS)/"
@plutil -replace CFBundleName -string "$(APP_NAME)" "$(CONTENTS)/Info.plist"
@plutil -replace CFBundleDisplayName -string "$(APP_NAME)" "$(CONTENTS)/Info.plist"
@plutil -replace CFBundleExecutable -string "$(APP_NAME)" "$(CONTENTS)/Info.plist"
@plutil -replace CFBundleIdentifier -string "$(BUNDLE_ID)" "$(CONTENTS)/Info.plist"
@cp $(ICON_ICNS) "$(RESOURCES)/AppIcon.icns"
@cp Resources/Attribution.txt "$(RESOURCES)/Attribution.txt"
@cp LICENSE "$(RESOURCES)/FreeFlow-LICENSE"
ifneq ($(strip $(PARAKEET_BUNDLE_DIR)),)
@test -f "$(PARAKEET_BUNDLE_DIR)/bundle.json" || { echo "Missing Parakeet bundle.json"; exit 1; }
@{ cat "$(PARAKEET_BUNDLE_STAMP)"; shasum -a 256 Resources/Parakeet/* scripts/label-localflow-model.py; } > "$(PARAKEET_INSTALL_KEY).tmp"
@# Re-copying gives the model new files, which forces a full Neural Engine
@# specialization on next launch. Keep the installed copy while it is unchanged.
@if [ -f "$(RESOURCES)/Parakeet/bundle.json" ] && cmp -s "$(PARAKEET_INSTALL_KEY).tmp" "$(PARAKEET_INSTALL_KEY)"; then \
echo "Reusing installed model files"; \
else \
rm -f "$(PARAKEET_INSTALL_KEY)" && rm -rf "$(RESOURCES)/Parakeet" && mkdir -p "$(RESOURCES)/Parakeet" && \
cp -R "$(PARAKEET_BUNDLE_DIR)/Encoder.mlmodelc" "$(RESOURCES)/Parakeet/" && \
cp "$(PARAKEET_BUNDLE_DIR)/bundle.json" "$(PARAKEET_BUNDLE_DIR)/frontend.json" "$(PARAKEET_BUNDLE_DIR)/frontend.f32bin" "$(PARAKEET_BUNDLE_DIR)/decoder_joint.json" "$(PARAKEET_BUNDLE_DIR)/decoder_joint.f32bin" "$(PARAKEET_BUNDLE_DIR)/vocabulary.json" "$(RESOURCES)/Parakeet/" && \
cp Resources/Parakeet/* "$(RESOURCES)/Parakeet/" && \
python3 scripts/label-localflow-model.py "$(RESOURCES)/Parakeet" && \
cp "$(PARAKEET_INSTALL_KEY).tmp" "$(PARAKEET_INSTALL_KEY)"; \
fi
@rm -f "$(PARAKEET_INSTALL_KEY).tmp"
else
@rm -rf "$(RESOURCES)/Parakeet" "$(PARAKEET_INSTALL_KEY)"
endif
@plutil -replace NSMicrophoneUsageDescription -string "$(APP_NAME) needs microphone access to transcribe your speech." "$(CONTENTS)/Info.plist"
@plutil -replace NSAccessibilityUsageDescription -string "$(APP_NAME) needs accessibility access to detect the text cursor position and paste transcribed text." "$(CONTENTS)/Info.plist"
@codesign --force --options runtime --sign "$(CODESIGN_IDENTITY)" --entitlements FreeFlow.entitlements "$(APP_BUNDLE)"
@echo "Built $(APP_BUNDLE)"
# Release builds must ship the model. Without PARAKEET_BUNDLE_DIR the app
# bundle is built without Resources/Parakeet and every dictation fails.
release-preflight:
@if [ -z "$(strip $(PARAKEET_BUNDLE_DIR))" ]; then \
echo "release-preflight: PARAKEET_BUNDLE_DIR is not set; a release build must include the model bundle." >&2; \
exit 1; \
fi
@if [ ! -f "$(PARAKEET_BUNDLE_DIR)/bundle.json" ]; then \
echo "release-preflight: PARAKEET_BUNDLE_DIR has no bundle.json; point it at a prepared model bundle." >&2; \
exit 1; \
fi
@echo "release-preflight: model bundle found."
check: typecheck test validate
# -warnings-as-errors does not promote every warning, and swiftc then exits 0.
# Swift 6.4 leaves at least "conformance of 'X' to 'Sendable' is only available
# in macOS N or newer" and "'M' was not imported by this file" as warnings:
# they carry no diagnostic group, so neither -warnings-as-errors,
# -Xfrontend -warnings-as-errors nor -Werror <group> can escalate them. Each
# compile below keeps its diagnostics in a log, prints the log however swiftc
# exits, and then fails if any warning is left.
TYPECHECK_LOG = $(BUILD_DIR)/typecheck-diagnostics.log
TEST_BUILD_LOG = $(BUILD_DIR)/test-build-diagnostics.log
print_log_on_exit = trap 'cat "$(1)" >&2' EXIT;
reject_warnings = if grep -Eq '(^|: )warning: ' "$(1)"; then echo "error: swiftc reported warnings (see above); every warning fails the check" >&2; exit 1; fi
typecheck:
@mkdir -p "$(BUILD_DIR)"
$(call print_log_on_exit,$(TYPECHECK_LOG)) swiftc 2> "$(TYPECHECK_LOG)" \
-parse-as-library \
-typecheck \
-warnings-as-errors \
-sdk $(shell xcrun --show-sdk-path) \
-target $(ARCH)-apple-macosx26.0 $(ACCELERATE_FLAGS) \
$(SOURCES)
@$(call reject_warnings,$(TYPECHECK_LOG))
test:
@mkdir -p "$(BUILD_DIR)"
$(call print_log_on_exit,$(TEST_BUILD_LOG)) swiftc 2> "$(TEST_BUILD_LOG)" \
-parse-as-library \
-warnings-as-errors \
-o "$(TEST_RUNNER)" \
-sdk $(shell xcrun --show-sdk-path) \
-target $(ARCH)-apple-macosx26.0 $(ACCELERATE_FLAGS) \
$(TEST_PRODUCTION_SOURCES) \
$(TEST_SOURCES)
@$(call reject_warnings,$(TEST_BUILD_LOG))
@$(TEST_RUNNER)
@python3 -m unittest discover -s Tests -p 'test_*.py'
validate:
plutil -lint Info.plist FreeFlow.entitlements
@set -e; for script in $(SHELL_SCRIPTS); do bash -n "$$script"; done
@ruby -e 'require "yaml"; ARGV.each { |file| YAML.load_file(file) }' $(YAML_FILES)
@python3 -I scripts/check-shared-vectors.py
icon: $(ICON_ICNS)
$(ICON_ICNS): $(ICON_SOURCE)
@mkdir -p $(BUILD_DIR)/AppIcon.iconset
@sips -z 16 16 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_16x16.png > /dev/null
@sips -z 32 32 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_16x16@2x.png > /dev/null
@sips -z 32 32 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_32x32.png > /dev/null
@sips -z 64 64 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_32x32@2x.png > /dev/null
@sips -z 128 128 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_128x128.png > /dev/null
@sips -z 256 256 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_128x128@2x.png > /dev/null
@sips -z 256 256 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_256x256.png > /dev/null
@sips -z 512 512 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_256x256@2x.png > /dev/null
@sips -z 512 512 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_512x512.png > /dev/null
@sips -z 1024 1024 $< --out $(BUILD_DIR)/AppIcon.iconset/icon_512x512@2x.png > /dev/null
@iconutil -c icns -o $@ $(BUILD_DIR)/AppIcon.iconset
@rm -rf $(BUILD_DIR)/AppIcon.iconset
@echo "Generated $@"
dmg: all
@rm -f "$(BUILD_DIR)/$(APP_NAME).dmg"
@rm -rf $(BUILD_DIR)/dmg-staging
@mkdir -p $(BUILD_DIR)/dmg-staging
@cp -R "$(APP_BUNDLE)" $(BUILD_DIR)/dmg-staging/
@osascript -e 'tell application "Finder" to make alias file to POSIX file "/Applications" at POSIX file "'"$$(cd $(BUILD_DIR)/dmg-staging && pwd)"'"'
@ALIAS=$$(find $(BUILD_DIR)/dmg-staging -maxdepth 1 -not -name '*.app' -not -name '.DS_Store' -type f | head -1) && mv "$$ALIAS" "$(BUILD_DIR)/dmg-staging/Applications"
@fileicon set "$(BUILD_DIR)/dmg-staging/Applications" /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/ApplicationsFolderIcon.icns
@echo "Creating DMG..."
@create-dmg \
--volname "$(APP_NAME)" \
--volicon "$(ICON_ICNS)" \
--background "Resources/dmg-background.tiff" \
--window-pos 200 120 \
--window-size 660 400 \
--icon-size 128 \
--icon "$(APP_NAME).app" 180 170 \
--hide-extension "$(APP_NAME).app" \
--icon "Applications" 480 170 \
--no-internet-enable \
"$(BUILD_DIR)/$(APP_NAME).dmg" \
"$(BUILD_DIR)/dmg-staging"
@rm -rf $(BUILD_DIR)/dmg-staging
@echo "Created $(BUILD_DIR)/$(APP_NAME).dmg"
codesign-dmg: dmg
codesign --force --sign "$(CODESIGN_IDENTITY)" "$(BUILD_DIR)/$(APP_NAME).dmg"
notarize:
xcrun notarytool submit "$(BUILD_DIR)/$(APP_NAME).dmg" \
--keychain-profile "$(NOTARIZE_PROFILE)" --wait
xcrun stapler staple "$(BUILD_DIR)/$(APP_NAME).dmg"
clean:
rm -rf $(BUILD_DIR)
run: all
open "$(APP_BUNDLE)"