Skip to content

Commit 902ed7d

Browse files
authored
Turso Support
2 parents 38d2d6d + 2e5f16e commit 902ed7d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4011
-477
lines changed

.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ runs:
55
using: composite
66
steps:
77
- name: Setup Node.js
8-
uses: actions/setup-node@v3
8+
uses: actions/setup-node@v6
99
with:
1010
node-version-file: .nvmrc
1111

.github/workflows/ci.yml

Lines changed: 108 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
runs-on: ubuntu-latest
77
steps:
88
- name: Checkout
9-
uses: actions/checkout@v4
9+
uses: actions/checkout@v5
1010

1111
- name: Setup
1212
uses: ./.github/actions/setup
@@ -18,7 +18,7 @@ jobs:
1818
runs-on: macos-latest
1919
steps:
2020
- name: Checkout
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@v5
2222

2323
- name: Xcode Select
2424
run: sudo xcode-select -s /Applications/Xcode_16.4.app
@@ -60,7 +60,7 @@ jobs:
6060
runs-on: macos-latest
6161
steps:
6262
- name: Checkout
63-
uses: actions/checkout@v4
63+
uses: actions/checkout@v5
6464

6565
- name: Xcode Select
6666
run: sudo xcode-select -s /Applications/Xcode_16.4.app
@@ -102,7 +102,7 @@ jobs:
102102
runs-on: macos-latest
103103
steps:
104104
- name: Checkout
105-
uses: actions/checkout@v4
105+
uses: actions/checkout@v5
106106

107107
- name: Xcode Select
108108
run: sudo xcode-select -s /Applications/Xcode_16.4.app
@@ -144,7 +144,7 @@ jobs:
144144
runs-on: macos-latest
145145
steps:
146146
- name: Checkout
147-
uses: actions/checkout@v4
147+
uses: actions/checkout@v5
148148

149149
- name: Xcode Select
150150
run: sudo xcode-select -s /Applications/Xcode_16.4.app
@@ -203,7 +203,7 @@ jobs:
203203
# docker-images: true
204204

205205
- name: Checkout
206-
uses: actions/checkout@v4
206+
uses: actions/checkout@v5
207207

208208
- name: Turn off addons
209209
run: |
@@ -287,7 +287,7 @@ jobs:
287287
# swap-storage: true
288288
# docker-images: true
289289
- name: Checkout
290-
uses: actions/checkout@v4
290+
uses: actions/checkout@v5
291291

292292
- name: Turn on SQLCipher
293293
run: |
@@ -359,7 +359,7 @@ jobs:
359359
env:
360360
TURBO_CACHE_DIR: .turbo/android
361361
steps:
362-
- uses: actions/checkout@v4
362+
- uses: actions/checkout@v5
363363

364364
- run: node ./scripts/turnOnLibsql.js
365365

@@ -412,3 +412,103 @@ jobs:
412412
name: android-logcat-${{ github.job }}
413413
path: example/android-logcat.txt
414414
if-no-files-found: ignore
415+
416+
ios-turso:
417+
runs-on: macos-latest
418+
steps:
419+
- name: Checkout
420+
uses: actions/checkout@v5
421+
422+
- name: Xcode Select
423+
run: sudo xcode-select -s /Applications/Xcode_16.4.app
424+
425+
- name: Turn on Turso
426+
run: |
427+
node ./scripts/turnOnTurso.js
428+
429+
- name: Setup
430+
uses: ./.github/actions/setup
431+
432+
- name: install bundler dependencies
433+
run: |
434+
cd example
435+
bundle install
436+
437+
- name: Cache cocoapods
438+
id: cocoapods-cache
439+
uses: actions/cache@v4
440+
with:
441+
path: |
442+
**/ios/Pods
443+
key: ${{ runner.os }}-cocoapods-${{ hashFiles('example/ios/Podfile.lock') }}
444+
restore-keys: |
445+
${{ runner.os }}-cocoapods-
446+
447+
- name: Install cocoapods
448+
run: |
449+
cd example/ios
450+
bundle exec pod install
451+
env:
452+
NO_FLIPPER: 1
453+
454+
- name: run tests
455+
run: |
456+
./scripts/test-ios.sh
457+
458+
android-turso:
459+
runs-on: ubuntu-latest
460+
timeout-minutes: 40
461+
steps:
462+
- uses: actions/checkout@v5
463+
464+
- run: node ./scripts/turnOnTurso.js
465+
466+
- name: Setup
467+
uses: ./.github/actions/setup
468+
469+
- name: Install JDK
470+
uses: actions/setup-java@v3
471+
with:
472+
distribution: "zulu"
473+
java-version: "17"
474+
475+
- name: Finalize Android SDK
476+
run: |
477+
/bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"
478+
479+
- name: Cache Gradle
480+
uses: actions/cache@v4
481+
with:
482+
path: |
483+
~/.gradle/wrapper
484+
~/.gradle/caches
485+
key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}
486+
restore-keys: |
487+
${{ runner.os }}-gradle-
488+
489+
- name: Enable KVM
490+
run: |
491+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
492+
sudo udevadm control --reload-rules
493+
sudo udevadm trigger --name-match=kvm
494+
495+
- name: Give execute permissions to script
496+
run: chmod +x ./scripts/test-android.sh
497+
498+
- name: run tests
499+
uses: reactivecircus/android-emulator-runner@v2
500+
with:
501+
api-level: 29
502+
emulator-options: -no-window -no-boot-anim -no-audio -no-snapshot-load
503+
script: |
504+
adb wait-for-device
505+
adb shell input keyevent 82
506+
./scripts/test-android.sh
507+
508+
- name: Upload Android diagnostics
509+
if: failure()
510+
uses: actions/upload-artifact@v4
511+
with:
512+
name: android-logcat-${{ github.job }}
513+
path: example/android-logcat.txt
514+
if-no-files-found: ignore

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,5 @@ android/c_sources
8989
# c_sources/
9090

9191
scripts/sqlite-vec-*
92+
turso/
93+
.tmp/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Some of the big supported features:
1414

1515
- iOS, Android, macOS and web support
1616
- Vanilla sqlite
17+
- Turso is supported as a compilation target
1718
- Libsql is supported as a compilation target
1819
- SQLCipher is supported as a compilation target
1920
- FTS5 plugin

android/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ if (USE_LIBSQL)
1515
include_directories(src/main/jniLibs/include)
1616
endif()
1717

18+
if (USE_TURSO)
19+
include_directories(src/main/tursoLibs/include)
20+
endif()
21+
1822
separate_arguments(SQLITE_FLAGS_LIST UNIX_COMMAND "${SQLITE_FLAGS}")
1923

2024
add_definitions(
@@ -52,6 +56,12 @@ elseif (USE_LIBSQL)
5256
add_definitions(
5357
-DOP_SQLITE_USE_LIBSQL=1
5458
)
59+
elseif (USE_TURSO)
60+
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/turso_bridge.cpp)
61+
62+
add_definitions(
63+
-DOP_SQLITE_USE_TURSO=1
64+
)
5565
else()
5666
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlite3.c ../cpp/bridge.cpp)
5767
endif()
@@ -104,6 +114,22 @@ elseif (USE_LIBSQL)
104114
ReactAndroid::jsi
105115
fbjni::fbjni
106116
)
117+
elseif (USE_TURSO)
118+
cmake_path(SET TURSO_PATH ${CMAKE_CURRENT_SOURCE_DIR}/src/main/tursoLibs/${ANDROID_ABI}/libturso_sdk_kit.so NORMALIZE)
119+
add_library(turso_sdk_kit SHARED IMPORTED)
120+
set_target_properties(turso_sdk_kit PROPERTIES
121+
IMPORTED_LOCATION ${TURSO_PATH}
122+
IMPORTED_NO_SONAME TRUE
123+
)
124+
125+
target_link_libraries(
126+
${PACKAGE_NAME}
127+
turso_sdk_kit
128+
${LOG_LIB}
129+
ReactAndroid::reactnative
130+
ReactAndroid::jsi
131+
fbjni::fbjni
132+
)
107133
else ()
108134
target_link_libraries(
109135
${PACKAGE_NAME}

android/build.gradle

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def reactNativeArchitectures() {
3434

3535
def useSQLCipher = false
3636
def useLibsql = false
37+
def useTurso = false
3738
def useCRSQLite = false
3839
def performanceMode = false
3940
def sqliteFlags = ""
@@ -79,12 +80,19 @@ if(opsqliteConfig) {
7980
sqliteFlags = opsqliteConfig["sqliteFlags"] ? opsqliteConfig["sqliteFlags"] : ""
8081
enableFTS5 = !!opsqliteConfig["fts5"]
8182
useLibsql = !!opsqliteConfig["libsql"]
83+
useTurso = !!opsqliteConfig["turso"]
8284
enableRtree = !!opsqliteConfig["rtree"]
8385
tokenizers = opsqliteConfig["tokenizers"] ? opsqliteConfig["tokenizers"] : []
8486
}
8587

88+
if(useLibsql && useTurso) {
89+
throw new GradleException("[OP-SQLITE] Error: libsql and turso backends are mutually exclusive.")
90+
}
91+
8692
if(useSQLCipher) {
8793
println "[OP-SQLITE] using sqlcipher."
94+
} else if(useTurso) {
95+
println "[OP-SQLITE] using turso backend."
8896
} else if(useLibsql) {
8997
println "[OP-SQLITE] using libsql. Report any issues to Turso"
9098
}
@@ -114,6 +122,10 @@ if(!tokenizers.isEmpty()) {
114122
throw new GradleException("[OP-SQLITE] Error: libsql does not support tokenizers. Please disable tokenizers or do not enable libsql.")
115123
}
116124

125+
if(useTurso) {
126+
throw new GradleException("[OP-SQLITE] Error: turso backend does not support tokenizers. Please disable tokenizers or do not enable turso.")
127+
}
128+
117129
println "[OP-SQLITE] Tokenizers enabled. Detected tokenizers: " + tokenizers
118130
}
119131

@@ -127,6 +139,7 @@ android {
127139
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
128140

129141
buildConfigField "boolean", "USE_LIBSQL", "${useLibsql}"
142+
buildConfigField "boolean", "USE_TURSO", "${useTurso}"
130143

131144
externalNativeBuild {
132145
cmake {
@@ -138,6 +151,10 @@ android {
138151
cFlags += "-DOP_SQLITE_USE_LIBSQL=1"
139152
cppFlags += "-DOP_SQLITE_USE_LIBSQL=1"
140153
}
154+
if(useTurso) {
155+
cFlags += "-DOP_SQLITE_USE_TURSO=1"
156+
cppFlags += "-DOP_SQLITE_USE_TURSO=1"
157+
}
141158
if(useCRSQLite) {
142159
cFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
143160
cppFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
@@ -179,6 +196,7 @@ android {
179196
"-DUSE_SQLCIPHER=${useSQLCipher ? 1 : 0}",
180197
"-DUSE_CRSQLITE=${useCRSQLite ? 1 : 0}",
181198
"-DUSE_LIBSQL=${useLibsql ? 1 : 0}",
199+
"-DUSE_TURSO=${useTurso ? 1 : 0}",
182200
"-DUSE_SQLITE_VEC=${useSqliteVec ? 1 : 0}",
183201
"-DUSER_DEFINED_SOURCE_FILES=${sourceFiles}",
184202
"-DUSER_DEFINED_TOKENIZERS_HEADER_PATH='${tokenizersHeaderPath}'",
@@ -244,6 +262,9 @@ android {
244262
if (useLibsql) {
245263
srcDirs += 'src/main/jniLibs'
246264
}
265+
if (useTurso) {
266+
srcDirs += 'src/main/tursoLibs'
267+
}
247268
if (useCRSQLite) {
248269
srcDirs += 'src/main/libcrsqlite'
249270
}
60.1 MB
Binary file not shown.
45.5 MB
Binary file not shown.

0 commit comments

Comments
 (0)