diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index 2d38f0ce..a6241c2a 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -53,6 +53,12 @@ else() target_sources(${PACKAGE_NAME} PRIVATE ../cpp/sqlite3.h ../cpp/sqlite3.c) endif() +if (OP_SQLITE_USE_CRSQLITE) + add_definitions( + -DOP_SQLITE_USE_CRSQLITE + ) +endif() + set_target_properties( ${PACKAGE_NAME} PROPERTIES CXX_STANDARD 20 @@ -64,7 +70,6 @@ find_package(ReactAndroid REQUIRED CONFIG) find_package(fbjni REQUIRED CONFIG) find_library(LOG_LIB log) - target_link_libraries( ${PACKAGE_NAME} ${LOG_LIB} diff --git a/android/build.gradle b/android/build.gradle index 80c3a990..65d1645b 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -87,7 +87,12 @@ android { if(System.getenv("OP_SQLITE_USE_SQLCIPHER") == '1') { println "OP-SQLITE using SQLCipher! 🔒" - cFlags += "-DOP_SQLITE_USE_SQLCIPHER=1" + cppFlags += "-DOP_SQLITE_USE_SQLCIPHER=1" + } + + if(System.getenv("OP_SQLITE_USE_CRSQLITE") == '1') { + println "OP-SQLITE using CR-SQLite! 🤖" + cppFlags += "-DOP_SQLITE_USE_CRSQLITE=1" } cppFlags "-O2", "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID" @@ -95,6 +100,7 @@ android { arguments "-DANDROID_STL=c++_shared", "-DSQLITE_FLAGS='${SQLITE_FLAGS ? SQLITE_FLAGS : ''}'" "-DOP_SQLITE_USE_SQLCIPHER='${System.getenv("OP_SQLITE_USE_SQLCIPHER") == '1'? 1 : 0}'" + "-DOP_SQLITE_USE_CRSQLITE='${System.getenv("OP_SQLITE_USE_CRSQLITE") == '1'? 1 : 0}'" abiFilters (*reactNativeArchitectures()) } } diff --git a/android/cpp-adapter.cpp b/android/cpp-adapter.cpp index 4b84563f..4b61d6c4 100644 --- a/android/cpp-adapter.cpp +++ b/android/cpp-adapter.cpp @@ -6,7 +6,8 @@ #include #include -// This file is not using raw jni but rather fbjni, do not change how the native functions are registered +// This file is not using raw jni but rather fbjni, do not change how the native +// functions are registered // https://github.com/facebookincubator/fbjni/blob/main/docs/quickref.md struct OPSQLiteBridge : jni::JavaClass { static constexpr auto kJavaDescriptor = "Lcom/op/sqlite/OPSQLiteBridge;"; @@ -27,7 +28,8 @@ struct OPSQLiteBridge : jni::JavaClass { auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker(); std::string dbPathStr = dbPath->toStdString(); - opsqlite::install(*jsiRuntime, jsCallInvoker, dbPathStr.c_str()); + opsqlite::install(*jsiRuntime, jsCallInvoker, dbPathStr.c_str(), + "libcrsqlite"); } static void clearStateNativeJsi(jni::alias_ref thiz) { diff --git a/android/src/main/jniLibs/arm64-v8a/libcrsqlite.so b/android/src/main/jniLibs/arm64-v8a/libcrsqlite.so new file mode 100644 index 00000000..4d584cc4 Binary files /dev/null and b/android/src/main/jniLibs/arm64-v8a/libcrsqlite.so differ diff --git a/android/src/main/jniLibs/armeabi-v7a/libcrsqlite.so b/android/src/main/jniLibs/armeabi-v7a/libcrsqlite.so new file mode 100644 index 00000000..b6ff67c4 Binary files /dev/null and b/android/src/main/jniLibs/armeabi-v7a/libcrsqlite.so differ diff --git a/android/src/main/jniLibs/x86/libcrsqlite.so b/android/src/main/jniLibs/x86/libcrsqlite.so new file mode 100644 index 00000000..568d1921 Binary files /dev/null and b/android/src/main/jniLibs/x86/libcrsqlite.so differ diff --git a/android/src/main/jniLibs/x86_64/libcrsqlite.so b/android/src/main/jniLibs/x86_64/libcrsqlite.so new file mode 100644 index 00000000..e04ab9b1 Binary files /dev/null and b/android/src/main/jniLibs/x86_64/libcrsqlite.so differ diff --git a/cpp/bridge.cpp b/cpp/bridge.cpp index cbe9fa5c..f9b97f0d 100644 --- a/cpp/bridge.cpp +++ b/cpp/bridge.cpp @@ -77,7 +77,8 @@ BridgeResult opsqlite_open(std::string const &dbName, nullptr, nullptr); #endif -#ifdef OP_SQLITE_CRSQLITE +#ifdef OP_SQLITE_USE_CRSQLITE + LOGI("Should load CRSQlite now"); char *errMsg; const char *crsqliteEntryPoint = "sqlite3_crsqlite_init"; @@ -87,10 +88,12 @@ BridgeResult opsqlite_open(std::string const &dbName, if (errMsg != nullptr) { return {.type = SQLiteError, .message = errMsg}; + } else { + LOGI("Loaded CRSQlite successfully"); } #endif - return BridgeResult{.type = SQLiteOk, .affectedRows = 0}; + return {.type = SQLiteOk, .affectedRows = 0}; } BridgeResult opsqlite_close(std::string const &dbName) { @@ -99,7 +102,7 @@ BridgeResult opsqlite_close(std::string const &dbName) { sqlite3 *db = dbMap[dbName]; -#ifdef OP_SQLITE_CRSQLITE +#ifdef OP_SQLITE_USE_CRSQLITE opsqlite_execute(dbName, "select crsql_finalize();", nullptr, nullptr, nullptr); #endif diff --git a/example/ios/OPSQLiteExample.xcodeproj/project.pbxproj b/example/ios/OPSQLiteExample.xcodeproj/project.pbxproj index 16858c5d..26478b26 100644 --- a/example/ios/OPSQLiteExample.xcodeproj/project.pbxproj +++ b/example/ios/OPSQLiteExample.xcodeproj/project.pbxproj @@ -430,7 +430,10 @@ ); MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; - OTHER_CFLAGS = "$(inherited) "; + OTHER_CFLAGS = ( + "$(inherited)", + " ", + ); OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "-DFOLLY_NO_CONFIG", @@ -512,7 +515,10 @@ "\"$(inherited)\"", ); MTL_ENABLE_DEBUG_INFO = NO; - OTHER_CFLAGS = "$(inherited) "; + OTHER_CFLAGS = ( + "$(inherited)", + " ", + ); OTHER_CPLUSPLUSFLAGS = ( "$(OTHER_CFLAGS)", "-DFOLLY_NO_CONFIG", diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index bf38ccb3..db9e4e8c 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1358,7 +1358,7 @@ SPEC CHECKSUMS: fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120 glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2 hermes-engine: 1a846a8f620a08c60f5f89aa65b8664f769f742f - op-sqlite: e3a7e3405530714f7b2c1ccb7897f3a95c0515ac + op-sqlite: 182bbbdd9a93ea385a81401a85b98683886f3f51 RCT-Folly: 045d6ecaa59d826c5736dfba0b2f4083ff8d79df RCTDeprecation: 82b53c4f460b7a5b27c6be8310a71bc84df583f5 RCTRequired: d1a99a9f78fcc4acca99ab397822f4e58601b134 diff --git a/example/package.json b/example/package.json index 7f5b6d27..82aaaab1 100644 --- a/example/package.json +++ b/example/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "android": "react-native run-android", - "ios": "react-native run-ios --simulator='iPhone 15' --scheme='debug'", + "ios": "react-native run-ios --scheme='debug'", "start": "react-native start", "pods": "cd ios && rm -rf Pods && rm -rf Podfile.lock && bundle exec pod install", "build:android": "cd android && ./gradlew assembleDebug --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a", diff --git a/example/src/tests/queries.spec.ts b/example/src/tests/queries.spec.ts index 813fb22d..66ed89f8 100644 --- a/example/src/tests/queries.spec.ts +++ b/example/src/tests/queries.spec.ts @@ -34,10 +34,10 @@ export function queriesTests() { }); describe('Queries tests', () => { - // it('Test crsqlite', async () => { - // const res = db.execute('select crsql_as_crr("User")'); - // console.warn(res); - // }); + it('Test crsqlite', async () => { + const res = db.execute('select crsql_as_crr("User")'); + console.warn(res); + }); it('Insert', async () => { const id = chance.integer(); diff --git a/op-sqlite.podspec b/op-sqlite.podspec index 88eaf143..86c53a0e 100644 --- a/op-sqlite.podspec +++ b/op-sqlite.podspec @@ -68,9 +68,9 @@ Pod::Spec.new do |s| xcconfig[:OTHER_CFLAGS] = optimizedCflags + ' -DSQLITE_THREADSAFE=1 ' end - if ENV['OP_SQLITE_CRSQLITE'] == '1' then + if ENV['OP_SQLITE_USE_CRSQLITE'] == '1' then log_message.call("[OP-SQLITE] using CRQSQLite! 🤖") - xcconfig[:GCC_PREPROCESSOR_DEFINITIONS] += " OP_SQLITE_CRSQLITE=1" + xcconfig[:GCC_PREPROCESSOR_DEFINITIONS] += "-DOP_SQLITE_USE_CRSQLITE=1" s.vendored_frameworks = "ios/crsqlite.xcframework" end