-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathbuild.gradle
More file actions
266 lines (227 loc) · 8.02 KB
/
build.gradle
File metadata and controls
266 lines (227 loc) · 8.02 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
264
265
266
import java.nio.file.Paths
import groovy.json.JsonSlurper
buildscript {
repositories {
google()
gradlePluginPortal()
}
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["OPSQLite_kotlinVersion"]
dependencies {
classpath("com.android.tools.build:gradle:7.3.1")
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
def resolveBuildType() {
Gradle gradle = getGradle()
String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
return tskReqStr.contains('Release') ? 'release' : 'debug'
}
def isNewArchitectureEnabled() {
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}
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 = []
def isInsideNodeModules = rootDir.absolutePath.contains("node_modules")
def packageJson
if ( isInsideNodeModules ) {
def packageJsonFile = new File("$rootDir/../../../package.json")
packageJson = new JsonSlurper().parseText(packageJsonFile.text)
} else {
def packageJsonFile = new File("$rootDir/../package.json")
packageJson = new JsonSlurper().parseText(packageJsonFile.text)
}
def opsqliteConfig = packageJson["op-sqlite"]
if(opsqliteConfig) {
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 📦"
} else {
println "[OP-SQLITE] using Vanilla SQLite"
}
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()) {
println "[OP-SQLITE] Tokenizers enabled! 🧾 Tokenizers: " + tokenizers
}
if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}
apply plugin: 'com.android.library'
apply plugin: "kotlin-android"
def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["OPSQLite" + name]
}
android {
compileSdkVersion safeExtGet("compileSdkVersion", 33)
namespace "com.op.sqlite"
// Used to override the NDK path/version on internal CI or by allowing
// users to customize the NDK path/version from their root project (e.g. for M1 support)
if (rootProject.hasProperty("ndkPath")) {
ndkPath rootProject.ext.ndkPath
}
if (rootProject.hasProperty("ndkVersion")) {
ndkVersion rootProject.ext.ndkVersion
}
buildFeatures {
prefab true
}
defaultConfig {
minSdkVersion safeExtGet("minSdkVersion", 24)
targetSdkVersion safeExtGet('targetSdkVersion', 35)
versionCode 1
versionName "1.0"
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_THREADSAFE=1", "-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"]
}
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 = isInsideNodeModules ? 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 "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
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}'"
}
}
packagingOptions {
doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
excludes = [
"META-INF",
"META-INF/**",
"**/libjsi.so",
"**/libreact_nativemodule_core.so",
"**/libturbomodulejsijni.so",
"**/libc++_shared.so",
"**/libfbjni.so",
"**/libreactnative.so",
]
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets.main {
java {
// TODO removed the codegen config to allow the package to be built under bridgeless
// Once there is a stable API for C++ Turbo Modules, maybe this can be enabled again
// if (!isNewArchitectureEnabled()) {
srcDirs += 'src/paper/java'
// }
}
}
}
repositories {
mavenCentral()
google()
}
def kotlin_version = getExtOrDefault("kotlinVersion")
dependencies {
implementation 'com.facebook.react:react-native'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
if (useSQLCipher) {
implementation('io.github.ronickg:openssl:3.3.2')
}
}
// Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct".
tasks.whenTaskAdded { task ->
if (task.name.contains("configureCMakeDebug")) {
rootProject.getTasksByName("packageReactNdkDebugLibs", true).forEach {
task.dependsOn(it)
}
}
// We want to add a dependency for both configureCMakeRelease and configureCMakeRelWithDebInfo
if (task.name.contains("configureCMakeRel")) {
rootProject.getTasksByName("packageReactNdkReleaseLibs", true).forEach {
task.dependsOn(it)
}
}
}
if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = "opsqlite"
codegenJavaPackageName = "com.op.sqlite.example"
}
}