Skip to content

Commit 9385d79

Browse files
author
Daniele Briggi
committed
fix(makefile): variables declaration before usage
1 parent c29ef75 commit 9385d79

File tree

2 files changed

+87
-76
lines changed

2 files changed

+87
-76
lines changed

.github/workflows/main.yml

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
include:
18-
- name: linux-vulkan
19-
os: ubuntu-latest
20-
arch: x86_64
21-
make: LLAMA="-DGGML_BACKEND_DL=ON -DGGML_NATIVE=OFF -DGGML_CPU_ALL_VARIANTS=ON -DGGML_VULKAN=ON"
18+
# - name: linux-vulkan
19+
# os: ubuntu-latest
20+
# arch: x86_64
21+
# make: LLAMA="-DGGML_BACKEND_DL=ON -DGGML_NATIVE=OFF -DGGML_CPU_ALL_VARIANTS=ON -DGGML_VULKAN=ON"
2222
- name: macos
2323
os: macos-latest
24-
- name: windows
25-
os: windows-latest
26-
arch: x86_64
27-
- name: android
28-
os: ubuntu-latest
29-
arch: arm64-v8a
30-
make: PLATFORM=android ARCH=arm64-v8a
31-
- name: android
32-
os: ubuntu-latest
33-
arch: x86_64
34-
make: PLATFORM=android ARCH=x86_64
35-
sqlite-amalgamation-zip: https://sqlite.org/2025/sqlite-amalgamation-3490100.zip
36-
- name: ios
37-
os: macos-latest
38-
make: PLATFORM=ios
39-
- name: isim
40-
os: macos-latest
41-
make: PLATFORM=isim
24+
# - name: windows
25+
# os: windows-latest
26+
# arch: x86_64
27+
# - name: android
28+
# os: ubuntu-latest
29+
# arch: arm64-v8a
30+
# make: PLATFORM=android ARCH=arm64-v8a
31+
# - name: android
32+
# os: ubuntu-latest
33+
# arch: x86_64
34+
# make: PLATFORM=android ARCH=x86_64
35+
# sqlite-amalgamation-zip: https://sqlite.org/2025/sqlite-amalgamation-3490100.zip
36+
# - name: ios
37+
# os: macos-latest
38+
# make: PLATFORM=ios
39+
# - name: isim
40+
# os: macos-latest
41+
# make: PLATFORM=isim
4242

4343
defaults:
4444
run:
@@ -92,7 +92,7 @@ jobs:
9292
if: matrix.name == 'windows'
9393
run: make extension ${{ matrix.make && matrix.make || ''}}
9494
shell: msys2 {0}
95-
95+
9696
- name: build sqlite-ai
9797
if: matrix.name != 'windows'
9898
run: make extension ${{ matrix.make && matrix.make || ''}}
@@ -101,7 +101,6 @@ jobs:
101101
if: matrix.name == 'macos'
102102
run: brew link sqlite --force
103103

104-
105104
- name: android setup test environment
106105
if: matrix.name == 'android' && matrix.arch != 'arm64-v8a'
107106
run: |
@@ -149,6 +148,15 @@ jobs:
149148
run: make test
150149
shell: msys2 {0}
151150

151+
- name: check whisper CoreML linking (macOS)
152+
if: matrix.name == 'macos'
153+
run: |
154+
echo "Checking if whisper CoreML symbols are present..."
155+
nm -D dist/ai.dylib | grep -i coreml || echo "CoreML symbols not found in binary"
156+
otool -L dist/ai.dylib | grep CoreML || echo "CoreML framework not linked"
157+
nm build/whisper.cpp/src/libwhisper.a | grep coreml
158+
nm build/whisper.cpp/src/libwhisper.coreml.a | grep coreml
159+
152160
- name: test sqlite-ai
153161
if: matrix.name == 'linux' || matrix.name == 'macos'
154162
run: make test

Makefile

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ endif
2424
# Speed up builds by using all available CPU cores
2525
MAKEFLAGS += -j$(CPUS)
2626

27-
# Compiler and flags
28-
CC = gcc
29-
CXX = g++
30-
CFLAGS = -Wall -Wextra -Wno-unused-parameter -I$(SRC_DIR) -I$(LLAMA_DIR)/ggml/include -I$(LLAMA_DIR)/include -I$(WHISPER_DIR)/include -I$(MINIAUDIO_DIR)
31-
LDFLAGS = $(LLAMA_LDFLAGS) $(WHISPER_LDFLAGS) $(MINIAUDIO_LDFLAGS)
32-
LLAMA_OPTIONS = $(LLAMA) -DLLAMA_CURL=OFF -DLLAMA_BUILD_EXAMPLES=OFF -DLLAMA_BUILD_TESTS=OFF -DLLAMA_BUILD_TOOLS=OFF -DLLAMA_BUILD_SERVER=OFF
33-
WHISPER_OPTIONS = $(WHISPER) -DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_SERVER=OFF
34-
MINIAUDIO_OPTIONS = -DMINIAUDIO_BUILD_EXAMPLES=OFF -DMINIAUDIO_BUILD_TESTS=OFF
35-
36-
# Module-specific linking flags
37-
LLAMA_LDFLAGS = -L./$(BUILD_LLAMA)/common -L./$(BUILD_LLAMA)/ggml/src -L./$(BUILD_LLAMA)/src -lcommon -lggml -lggml-cpu -lggml-base -lllama
38-
WHISPER_LDFLAGS = -L./$(BUILD_WHISPER)/src -lwhisper
39-
MINIAUDIO_LDFLAGS = -L./$(BUILD_MINIAUDIO) -lminiaudio
40-
4127
# Directories
4228
SRC_DIR = src
4329
DIST_DIR = dist
@@ -50,6 +36,21 @@ BUILD_LLAMA = $(BUILD_DIR)/llama.cpp
5036
BUILD_WHISPER = $(BUILD_DIR)/whisper.cpp
5137
BUILD_MINIAUDIO = $(BUILD_DIR)/miniaudio
5238

39+
# Compiler and flags
40+
CC = gcc
41+
CXX = g++
42+
CFLAGS = -Wall -Wextra -Wno-unused-parameter -I$(SRC_DIR) -I$(LLAMA_DIR)/ggml/include -I$(LLAMA_DIR)/include -I$(WHISPER_DIR)/include -I$(MINIAUDIO_DIR)
43+
LLAMA_OPTIONS = -DLLAMA_CURL=OFF -DLLAMA_BUILD_EXAMPLES=OFF -DLLAMA_BUILD_TESTS=OFF -DLLAMA_BUILD_TOOLS=OFF -DLLAMA_BUILD_SERVER=OFF
44+
WHISPER_OPTIONS = -DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BUILD_TESTS=OFF -DWHISPER_BUILD_SERVER=OFF
45+
MINIAUDIO_OPTIONS = -DMINIAUDIO_BUILD_EXAMPLES=OFF -DMINIAUDIO_BUILD_TESTS=OFF
46+
47+
# Module-specific linking flags
48+
LLAMA_LDFLAGS = -L./$(BUILD_LLAMA)/common -L./$(BUILD_LLAMA)/ggml/src -L./$(BUILD_LLAMA)/src -lcommon -lggml -lggml-cpu -lggml-base -lllama
49+
WHISPER_LDFLAGS = -L./$(BUILD_WHISPER)/src -lwhisper
50+
MINIAUDIO_LDFLAGS = -L./$(BUILD_MINIAUDIO) -lminiaudio
51+
52+
LDFLAGS = $(LLAMA_LDFLAGS) $(WHISPER_LDFLAGS) $(MINIAUDIO_LDFLAGS)
53+
5354
# Files
5455
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
5556
OBJ_FILES = $(patsubst %.c, $(BUILD_DIR)/%.o, $(notdir $(SRC_FILES)))
@@ -67,12 +68,14 @@ ifeq ($(PLATFORM),windows)
6768
else ifeq ($(PLATFORM),macos)
6869
TARGET := $(DIST_DIR)/ai.dylib
6970
LLAMA_LIBS += $(BUILD_LLAMA)/ggml/src/ggml-metal/libggml-metal.a $(BUILD_LLAMA)/ggml/src/ggml-blas/libggml-blas.a
70-
LDFLAGS += -arch x86_64 -arch arm64 -L./$(BUILD_LLAMA)/ggml/src/ggml-metal -lggml-metal -L./$(BUILD_LLAMA)/ggml/src/ggml-blas -lggml-blas -framework Metal -framework Foundation -framework CoreFoundation -framework QuartzCore -framework Accelerate -framework CoreML -dynamiclib -undefined dynamic_lookup
71+
WHISPER_LIBS += $(BUILD_WHISPER)/src/libwhisper.coreml.a
72+
LDFLAGS += -arch x86_64 -arch arm64 -L./$(BUILD_LLAMA)/ggml/src/ggml-metal -lggml-metal -L./$(BUILD_LLAMA)/ggml/src/ggml-blas -lggml-blas -Wl,-force_load,$(BUILD_WHISPER)/src/libwhisper.coreml.a -framework Metal -framework Foundation -framework CoreFoundation -framework QuartzCore -framework Accelerate -framework CoreML -dynamiclib -undefined dynamic_lookup
7173
CFLAGS += -arch x86_64 -arch arm64
7274
LLAMA_OPTIONS += -DBUILD_SHARED_LIBS=OFF -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
73-
WHISPER_OPTIONS += -DBUILD_SHARED_LIBS=OFF -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DWHISPER_COREML=ON
75+
WHISPER_OPTIONS += -DBUILD_SHARED_LIBS=OFF -DWHISPER_SHARED_LIB=OFF -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DWHISPER_COREML=ON
7476
MINIAUDIO_OPTIONS += -DBUILD_SHARED_LIBS=OFF -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
75-
STRIP = strip -x -S $@
77+
STRIP = true
78+
# STRIP = strip -x -S $@ # Disabled for debugging symbol issues
7679
else ifeq ($(PLATFORM),android)
7780
# Set ARCH to find Android NDK's Clang compiler, the user should set the ARCH
7881
ifeq ($(filter %,$(ARCH)),)
@@ -134,9 +137,9 @@ endif
134137
# Windows .def file generation
135138
$(DEF_FILE):
136139
ifeq ($(PLATFORM),windows)
137-
@echo "LIBRARY ai.dll" > $@
138-
@echo "EXPORTS" >> $@
139-
@echo " sqlite3_ai_init" >> $@
140+
@echo "LIBRARY ai.dll" > $@
141+
@echo "EXPORTS" >> $@
142+
@echo " sqlite3_ai_init" >> $@
140143
endif
141144

142145
# Make sure the build and dist directories exist
@@ -151,67 +154,67 @@ compile: $(OBJ_FILES)
151154

152155
# Loadable library
153156
$(TARGET): $(DEF_FILE) $(LLAMA_LIBS) $(WHISPER_LIBS) $(MINIAUDIO_LIBS)
154-
$(CXX) $(OBJ_FILES) $(DEF_FILE) -o $@ $(LDFLAGS)
157+
$(CXX) $(OBJ_FILES) $(DEF_FILE) -o $@ $(LDFLAGS)
155158
ifeq ($(PLATFORM),windows)
156159
# Generate import library for Windows
157-
dlltool -D $@ -d $(DEF_FILE) -l $(DIST_DIR)/ai.lib
160+
dlltool -D $@ -d $(DEF_FILE) -l $(DIST_DIR)/ai.lib
158161
endif
159162
# Strip debug symbols
160163
$(STRIP)
161164

162165
# Object files
163166
$(BUILD_DIR)/%.o: %.c
164-
$(CC) $(CFLAGS) -O3 -fPIC -c $< -o $@
167+
$(CC) $(CFLAGS) -O3 -fPIC -c $< -o $@
165168

166169
test: $(TARGET)
167-
$(SQLITE3) ":memory:" -cmd ".bail on" ".load ./dist/ai" "SELECT ai_version();"
170+
$(SQLITE3) ":memory:" -cmd ".bail on" ".load ./dist/ai" "SELECT ai_version();"
168171

169172
# Build submodules (only after successful compilation of the extension)
170173
build/llama.cpp.stamp: | compile
171-
cmake -B $(BUILD_LLAMA) $(LLAMA_OPTIONS) $(LLAMA_DIR)
172-
cmake --build $(BUILD_LLAMA) --config Release -- -j$(CPUS)
173-
touch $@
174+
cmake -B $(BUILD_LLAMA) $(LLAMA_OPTIONS) $(LLAMA_DIR)
175+
cmake --build $(BUILD_LLAMA) --config Release -- -j$(CPUS)
176+
touch $@
174177

175178
build/whisper.cpp.stamp: | compile
176-
cmake -B $(BUILD_WHISPER) $(WHISPER_OPTIONS) $(WHISPER_DIR)
177-
cmake --build $(BUILD_WHISPER) --config Release -- -j$(CPUS)
178-
touch $@
179+
cmake -B $(BUILD_WHISPER) $(WHISPER_OPTIONS) $(WHISPER_DIR)
180+
cmake --build $(BUILD_WHISPER) --config Release -- -j$(CPUS)
181+
touch $@
179182

180183
build/miniaudio.stamp: | compile
181-
cmake -B $(BUILD_MINIAUDIO) $(MINIAUDIO_OPTIONS) $(MINIAUDIO_DIR)
182-
cmake --build $(BUILD_MINIAUDIO) --config Release -- -j$(CPUS)
183-
touch $@
184+
cmake -B $(BUILD_MINIAUDIO) $(MINIAUDIO_OPTIONS) $(MINIAUDIO_DIR)
185+
cmake --build $(BUILD_MINIAUDIO) --config Release -- -j$(CPUS)
186+
touch $@
184187

185188
$(LLAMA_LIBS): build/llama.cpp.stamp
186189
$(WHISPER_LIBS): build/whisper.cpp.stamp
187190
$(MINIAUDIO_LIBS): build/miniaudio.stamp
188191

189192
# Tools
190193
version:
191-
@echo $(shell sed -n 's/^#define SQLITE_AI_VERSION[[:space:]]*"\([^"]*\)".*/\1/p' src/sqlite-ai.h)
194+
@echo $(shell sed -n 's/^#define SQLITE_AI_VERSION[[:space:]]*"\([^"]*\)".*/\1/p' src/sqlite-ai.h)
192195

193196
# Clean up generated files
194197
clean:
195-
rm -rf $(BUILD_DIR)/* $(DIST_DIR)/* *.gcda *.gcno *.gcov *.sqlite
198+
rm -rf $(BUILD_DIR)/* $(DIST_DIR)/* *.gcda *.gcno *.gcov *.sqlite
196199

197200
# Help message
198201
help:
199-
@echo "SQLite AI Extension Makefile"
200-
@echo "Usage:"
201-
@echo " make [PLATFORM=platform] [ARCH=arch] [ANDROID_NDK=\$$ANDROID_HOME/ndk/26.1.10909125] [target]"
202-
@echo ""
203-
@echo "Platforms:"
204-
@echo " linux (default on Linux)"
205-
@echo " macos (default on macOS)"
206-
@echo " windows (default on Windows)"
207-
@echo " android (needs ARCH to be set to x86_64 or arm64-v8a and ANDROID_NDK to be set)"
208-
@echo " ios (only on macOS)"
209-
@echo " isim (only on macOS)"
210-
@echo ""
211-
@echo "Targets:"
212-
@echo " all - Build the extension (default)"
213-
@echo " clean - Remove built files"
214-
@echo " test - Test the extension"
215-
@echo " help - Display this help message"
202+
@echo "SQLite AI Extension Makefile"
203+
@echo "Usage:"
204+
@echo " make [PLATFORM=platform] [ARCH=arch] [ANDROID_NDK=\$$ANDROID_HOME/ndk/26.1.10909125] [target]"
205+
@echo ""
206+
@echo "Platforms:"
207+
@echo " linux (default on Linux)"
208+
@echo " macos (default on macOS)"
209+
@echo " windows (default on Windows)"
210+
@echo " android (needs ARCH to be set to x86_64 or arm64-v8a and ANDROID_NDK to be set)"
211+
@echo " ios (only on macOS)"
212+
@echo " isim (only on macOS)"
213+
@echo ""
214+
@echo "Targets:"
215+
@echo " all - Build the extension (default)"
216+
@echo " clean - Remove built files"
217+
@echo " test - Test the extension"
218+
@echo " help - Display this help message"
216219

217220
.PHONY: all clean test extension help compile

0 commit comments

Comments
 (0)