Skip to content

Commit

Permalink
Merge pull request #85 from OP-Engineering/osp/update-sqlcipher
Browse files Browse the repository at this point in the history
Update SQLCipher
  • Loading branch information
ospfranco authored Apr 22, 2024
2 parents 5da0952 + 5fa5bb1 commit af4c7dd
Show file tree
Hide file tree
Showing 16 changed files with 14,703 additions and 5,253 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Turn on SQLCipher
run: |
node ./scripts/turnOnSQLCipher.js
- name: Setup
uses: ./.github/actions/setup

Expand Down Expand Up @@ -184,7 +188,7 @@ jobs:
# if: env.turbo_cache_hit != 1 && steps.cocoapods-cache.outputs.cache-hit != 'true'
run: |
cd example/ios
OP_SQLITE_USE_SQLCIPHER=1 bundle exec pod install
bundle exec pod install
env:
NO_FLIPPER: 1

Expand All @@ -200,6 +204,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Turn on SQLCipher
run: |
node ./scripts/turnOnSQLCipher.js
- name: Setup
uses: ./.github/actions/setup

Expand Down Expand Up @@ -234,4 +242,4 @@ jobs:
env:
JAVA_OPTS: '-XX:MaxHeapSize=6g'
run: |
OP_SQLITE_USE_SQLCIPHER=1 yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
yarn turbo run build:android --cache-dir="${{ env.TURBO_CACHE_DIR }}"
38 changes: 24 additions & 14 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ add_library(
cpp-adapter.cpp
)

if (OP_SQLITE_USE_SQLCIPHER)
if (USE_SQLCIPHER)
message("Using SQLCipher!")
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlcipher/sqlite3.h ../cpp/sqlcipher/sqlite3.c)

add_definitions(
Expand All @@ -53,7 +54,7 @@ else()
target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlite3.h ../cpp/sqlite3.c)
endif()

if (OP_SQLITE_USE_CRSQLITE)
if (USE_CRSQLITE)
add_definitions(
-DOP_SQLITE_USE_CRSQLITE=1
)
Expand All @@ -70,16 +71,25 @@ find_package(ReactAndroid REQUIRED CONFIG)
find_package(fbjni REQUIRED CONFIG)
find_library(LOG_LIB log)

target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::turbomodulejsijni
ReactAndroid::react_nativemodule_core
android
)

if (OP_SQLITE_USE_SQLCIPHER)
target_link_libraries(${PACKAGE_NAME} PRIVATE openssl::crypto)
if (USE_SQLCIPHER)
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::turbomodulejsijni
ReactAndroid::react_nativemodule_core
android
openssl::crypto
)
else()
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::turbomodulejsijni
ReactAndroid::react_nativemodule_core
android
)
endif()
18 changes: 13 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,21 @@ android {
}

defaultConfig {
minSdkVersion 21
minSdkVersion 23
targetSdkVersion safeExtGet('targetSdkVersion', 34)
versionCode 1
versionName "1.0"

externalNativeBuild {
cmake {
if(useSQLCipher) {
cFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
cppFlags += "-DOP_SQLITE_USE_SQLCIPHER=1"
}
if(useCRSQLite) {
cFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
cppFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
}
if(performanceMode == '1') {
cFlags += ["-DSQLITE_DQS=0", "-DSQLITE_THREADSAFE=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"]
}
Expand All @@ -117,9 +125,9 @@ android {
cppFlags "-O2", "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
arguments "-DANDROID_STL=c++_shared",
"-DSQLITE_FLAGS='$sqliteFlags'"
"-DOP_SQLITE_USE_SQLCIPHER='${useSQLCipher? 1 : 0}'"
"-DOP_SQLITE_USE_CRSQLITE='${useCRSQLite? 1 : 0}'"
"-DSQLITE_FLAGS='$sqliteFlags'",
"-DUSE_SQLCIPHER=${useSQLCipher ? 1 : 0}",
"-DUSE_CRSQLITE=${useCRSQLite ? 1 : 0}"
abiFilters (*reactNativeArchitectures())
}
}
Expand Down Expand Up @@ -170,7 +178,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
dependencies {
implementation 'com.facebook.react:react-native'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
if (System.getenv("OP_SQLITE_USE_SQLCIPHER") == '1') {
if (useSQLCipher) {
implementation('com.android.ndk.thirdparty:openssl:1.1.1q-beta-1')
}
}
Expand Down
9 changes: 9 additions & 0 deletions cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,14 @@ void install(jsi::Runtime &rt,
return jsi::String::createFromUtf8(rt, result);
});

auto is_sqlcipher = HOSTFN("isSQLCipher", 0) {
#ifdef OP_SQLITE_USE_SQLCIPHER
return true;
#else
return false;
#endif
});

jsi::Object module = jsi::Object(rt);

module.setProperty(rt, "open", std::move(open));
Expand All @@ -682,6 +690,7 @@ void install(jsi::Runtime &rt,
module.setProperty(rt, "loadExtension", std::move(load_extension));
module.setProperty(rt, "executeRawAsync", std::move(execute_raw_async));
module.setProperty(rt, "getDbPath", std::move(get_db_path));
module.setProperty(rt, "isSQLCipher", std::move(is_sqlcipher));

rt.global().setProperty(rt, "__OPSQLiteProxy", std::move(module));
}
Expand Down
Loading

0 comments on commit af4c7dd

Please sign in to comment.