-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathbuild.gradle
More file actions
263 lines (220 loc) · 7.2 KB
/
build.gradle
File metadata and controls
263 lines (220 loc) · 7.2 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
import java.nio.file.Paths
import groovy.json.JsonSlurper
buildscript {
ext.getExtOrDefault = {name ->
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['OPSQLite_' + name]
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:8.7.2")
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
}
}
apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "com.facebook.react"
def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["OPSQLite_" + name]).toInteger()
}
def useSQLCipher = false
def useLibsql = false
def useCRSQLite = false
def performanceMode = false
def sqliteFlags = ""
def enableFTS5 = false
def useSqliteVec = false
def enableRtree = false
def tokenizers = []
// On the example app, the package.json is located at the root of the project
// On the user app, the package.json is located at the root of the node_modules directory
def isUserApp = rootDir.absolutePath.contains("node_modules")
def packageJsonFile
if (isUserApp) {
// Start from the root + 1 level up (to avoid detecting the op-sqlite/package.json) and traverse upwards to find the first package.json
File currentDir = new File("$rootDir/../")
packageJsonFile = null
// Try to find package.json by traversing upwards
while (currentDir != null) {
File potential = new File(currentDir, "package.json")
if (potential.exists()) {
packageJsonFile = potential
break
}
currentDir = currentDir.parentFile
}
} else {
packageJsonFile = new File("$rootDir/../package.json")
}
def packageJson = new JsonSlurper().parseText(packageJsonFile.text)
def opsqliteConfig = packageJson["op-sqlite"]
if(opsqliteConfig) {
println "[OP-SQLITE] Detected op-sqlite config from package.json at: " + packageJsonFile.absolutePath
useSQLCipher = opsqliteConfig["sqlcipher"]
useCRSQLite = opsqliteConfig["crsqlite"]
useSqliteVec = opsqliteConfig["sqliteVec"]
performanceMode = opsqliteConfig["performanceMode"]
sqliteFlags = opsqliteConfig["sqliteFlags"] ? opsqliteConfig["sqliteFlags"] : ""
enableFTS5 = opsqliteConfig["fts5"]
useLibsql = opsqliteConfig["libsql"]
enableRtree = opsqliteConfig["rtree"]
tokenizers = opsqliteConfig["tokenizers"] ? opsqliteConfig["tokenizers"] : []
}
if(useSQLCipher) {
println "[OP-SQLITE] using sqlcipher."
} else if(useLibsql) {
println "[OP-SQLITE] using libsql. Report any issues to Turso"
}
if(useCRSQLite) {
println "[OP-SQLITE] using CR-SQLite"
}
if(performanceMode) {
println "[OP-SQLITE] Performance mode enabled"
}
if(enableFTS5) {
println "[OP-SQLITE] FTS5 enabled"
}
if(enableRtree) {
println "[OP-SQLITE] RTree enabled"
}
if(useSqliteVec) {
println "[OP-SQLITE] Sqlite-vec enabled"
}
if(!tokenizers.isEmpty()) {
if(useLibsql) {
throw new GradleException("[OP-SQLITE] Error: libsql does not support tokenizers. Please disable tokenizers or do not enable libsql.")
}
println "[OP-SQLITE] Tokenizers enabled. Detected tokenizers: " + tokenizers
}
android {
namespace "com.op.sqlite"
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
defaultConfig {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
buildConfigField "boolean", "USE_LIBSQL", "${useLibsql}"
externalNativeBuild {
cmake {
if(useSQLCipher) {
cFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
cppFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
}
if(useLibsql) {
cFlags += "-DOP_SQLITE_USE_LIBSQL=1"
cppFlags += "-DOP_SQLITE_USE_LIBSQL=1"
}
if(useCRSQLite) {
cFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
cppFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
}
if(performanceMode) {
cFlags += ["-DSQLITE_DQS=0", "-DSQLITE_DEFAULT_MEMSTATUS=0", "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1", "-DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1", "-DSQLITE_MAX_EXPR_DEPTH=0", "-DSQLITE_OMIT_DEPRECATED=1", "-DSQLITE_OMIT_PROGRESS_CALLBACK=1", "-DSQLITE_OMIT_SHARED_CACHE=1", "-DSQLITE_USE_ALLOCA=1", "-DSQLITE_THREADSAFE=1"]
}
if(enableFTS5) {
cFlags += ["-DSQLITE_ENABLE_FTS5=1"]
}
if(enableRtree) {
cFlags += ["-DSQLITE_ENABLE_RTREE=1"]
}
if(useSqliteVec) {
cFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
cppFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
}
// This are zeroes because they will be passed as C flags, so they become falsy
def sourceFiles = 0
// def tokenizerInitStrings = 0
def tokenizersHeaderPath = 0
if (!tokenizers.isEmpty()) {
def sourceDir = isUserApp ? file("$rootDir/../../../c_sources") : file("$rootDir/../c_sources")
def destDir = file("$buildscript.sourceFile.parentFile/c_sources")
copy {
from sourceDir
into destDir
include "**/*.cpp", "**/*.h"
}
sourceFiles = fileTree(dir: destDir, include: ["**/*.cpp", "**/*.h"]).files.join(";")
tokenizersHeaderPath = "../c_sources/tokenizers.h"
}
cppFlags "-O3 -frtti -fexceptions -Wall -fstack-protector-all"
arguments "-DANDROID_STL=c++_shared",
"-DSQLITE_FLAGS='$sqliteFlags'",
"-DUSE_SQLCIPHER=${useSQLCipher ? 1 : 0}",
"-DUSE_CRSQLITE=${useCRSQLite ? 1 : 0}",
"-DUSE_LIBSQL=${useLibsql ? 1 : 0}",
"-DUSE_SQLITE_VEC=${useSqliteVec ? 1 : 0}",
"-DUSER_DEFINED_SOURCE_FILES=${sourceFiles}",
"-DUSER_DEFINED_TOKENIZERS_HEADER_PATH='${tokenizersHeaderPath}'",
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
}
}
}
buildFeatures {
buildConfig true
prefab true
prefabPublishing true
}
buildTypes {
release {
minifyEnabled false
}
}
prefab {
"op-sqlite" {
headers "${project.buildDir}/headers/op-sqlite/"
}
}
lintOptions {
disable "GradleCompatible"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
java.srcDirs += [
"generated/java",
"generated/jni"
]
jniLibs {
srcDirs = []
if (useLibsql) {
srcDirs += 'src/main/jniLibs'
}
if (useCRSQLite) {
srcDirs += 'src/main/libcrsqlite'
}
if (useSqliteVec) {
srcDirs += 'src/main/libsqlitevec'
}
}
}
}
}
repositories {
mavenCentral()
google()
}
def kotlin_version = getExtOrDefault("kotlinVersion")
dependencies {
implementation "com.facebook.react:react-android"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
if (useSQLCipher) {
implementation('io.github.ronickg:openssl:3.3.2-1')
}
}
tasks.register('prepareHeaders', Copy) {
from('../cpp')
include "**/*.h", "**/*.hpp"
into "${project.buildDir}/headers/op-sqlite/op-engineering_op-sqlite/"
includeEmptyDirs = false
}
preBuild.dependsOn(prepareHeaders)