Skip to content

Commit 05b49e1

Browse files
committed
fix Android test builds
1 parent c682a9b commit 05b49e1

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,18 @@ jobs:
343343
sudo udevadm trigger --name-match=kvm
344344
echo "::endgroup::"
345345
346-
echo "::group::build sqlite3 without SQLITE_OMIT_LOAD_EXTENSION"
346+
echo "::group::download sqlite3 amalgamation"
347347
curl -O ${{ matrix.sqlite-amalgamation-zip }}
348348
unzip sqlite-amalgamation-*.zip
349-
export ${{ matrix.make }}
350-
$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/${{ matrix.arch }}-linux-android26-clang sqlite-amalgamation-*/shell.c sqlite-amalgamation-*/sqlite3.c -o sqlite3 -ldl
351-
rm -rf sqlite-amalgamation-*.zip sqlite-amalgamation-*
349+
SQLITE_DIR=$(ls -d sqlite-amalgamation-*)
350+
echo "::endgroup::"
351+
352+
echo "::group::build sqlite3 shell for android"
353+
$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/${{ matrix.arch }}-linux-android26-clang ${SQLITE_DIR}/shell.c ${SQLITE_DIR}/sqlite3.c -o sqlite3 -ldl
352354
echo "::endgroup::"
353355
354356
echo "::group::build unittest binary for android"
355-
make build/unittest ${{ matrix.make }}
357+
make build/unittest ${{ matrix.make }} SQLITE_AMALGAM=${SQLITE_DIR}/sqlite3.c
356358
echo "::endgroup::"
357359
358360
- name: android test sqlite-memory

Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ else ifeq ($(PLATFORM),android)
105105
endif
106106

107107
LDFLAGS := -shared -static-libstdc++ -llog -Wl,-z,max-page-size=16384
108+
TEST_LDFLAGS := -ldl -llog
108109

109110
else ifeq ($(PLATFORM),ios)
110111
EXT := dylib
@@ -326,6 +327,13 @@ ifeq ($(OMIT_LOCAL_ENGINE),0)
326327
endif
327328
endif
328329

330+
# Android: compile SQLite amalgamation into unittest (set SQLITE_AMALGAM=path/to/sqlite3.c)
331+
SQLITE_AMALGAM ?=
332+
TEST_SQLITE_OBJ :=
333+
ifneq ($(SQLITE_AMALGAM),)
334+
TEST_SQLITE_OBJ := $(BUILD_DIR)/test-sqlite3.o
335+
endif
336+
329337
$(BUILD_DIR)/unittest.o: $(TEST_DIR)/unittest.c | $(BUILD_DIR)
330338
@echo "Compiling unittest.c..."
331339
@$(CC) $(CFLAGS) $(TEST_DEFINES) $(DEFINES) $(INCLUDES) -c $< -o $@
@@ -334,11 +342,15 @@ $(BUILD_DIR)/test-%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
334342
@echo "Compiling $< (for test)..."
335343
@$(CC) $(CFLAGS) $(TEST_DEFINES) $(DEFINES) $(INCLUDES) -c $< -o $@
336344

345+
$(BUILD_DIR)/test-sqlite3.o: $(SQLITE_AMALGAM) | $(BUILD_DIR)
346+
@echo "Compiling sqlite3.c (amalgamation)..."
347+
@$(CC) $(CFLAGS) -DSQLITE_ENABLE_FTS5 -c $< -o $@
348+
337349
TEST_C_OBJECTS := $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/test-%.o,$(C_SOURCES))
338350

339-
$(BUILD_DIR)/unittest: $(BUILD_DIR)/unittest.o $(TEST_C_OBJECTS) $(LLAMA_LIBS) | $(BUILD_DIR)
351+
$(BUILD_DIR)/unittest: $(BUILD_DIR)/unittest.o $(TEST_C_OBJECTS) $(TEST_SQLITE_OBJ) $(LLAMA_LIBS) | $(BUILD_DIR)
340352
@echo "Linking unittest..."
341-
@$(LINKER) $(BUILD_DIR)/unittest.o $(TEST_C_OBJECTS) $(LLAMA_LIBS) \
353+
@$(LINKER) $(BUILD_DIR)/unittest.o $(TEST_C_OBJECTS) $(TEST_SQLITE_OBJ) $(LLAMA_LIBS) \
342354
$(TEST_LDFLAGS) $(FRAMEWORKS) $(TEST_LINK_EXTRAS) \
343355
-o $@
344356

0 commit comments

Comments
 (0)