-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup native code and update package name
- Loading branch information
Showing
17 changed files
with
454 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
project(PowersyncOpSqlite) | ||
cmake_minimum_required(VERSION 3.9.0) | ||
|
||
set (PACKAGE_NAME "powersync-opsqlite") | ||
set (CMAKE_VERBOSE_MAKEFILE ON) | ||
set (CMAKE_CXX_STANDARD 17) | ||
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build) | ||
|
||
add_library( | ||
${PACKAGE_NAME} | ||
SHARED | ||
) | ||
|
||
set_target_properties( | ||
${PACKAGE_NAME} PROPERTIES | ||
CXX_STANDARD 17 | ||
CXX_EXTENSIONS OFF | ||
POSITION_INDEPENDENT_CODE ON | ||
) | ||
|
||
find_package(ReactAndroid REQUIRED CONFIG) | ||
find_package(fbjni REQUIRED CONFIG) | ||
find_package(powersync_sqlite_core REQUIRED CONFIG) | ||
find_library(LOG_LIB log) | ||
|
||
if(${USE_HERMES}) | ||
set(JSEXECUTOR_LIB ReactAndroid::hermes_executor) | ||
else() | ||
set(JSEXECUTOR_LIB ReactAndroid::jscexecutor) | ||
endif() | ||
|
||
|
||
target_link_libraries( | ||
${PACKAGE_NAME} | ||
${LOG_LIB} | ||
fbjni::fbjni | ||
ReactAndroid::jsi | ||
ReactAndroid::turbomodulejsijni | ||
ReactAndroid::react_nativemodule_core | ||
${JSEXECUTOR_LIB} | ||
android | ||
powersync_sqlite_core::powersync | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
buildscript { | ||
ext.safeExtGet = {prop, fallback -> | ||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
} | ||
repositories { | ||
google() | ||
gradlePluginPortal() | ||
} | ||
dependencies { | ||
classpath("com.android.tools.build:gradle:7.3.1") | ||
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.22") | ||
} | ||
} | ||
|
||
def reactNativeArchitectures() { | ||
def value = project.getProperties().get("reactNativeArchitectures") | ||
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] | ||
} | ||
|
||
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" | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'com.facebook.react' | ||
apply plugin: 'org.jetbrains.kotlin.android' | ||
|
||
android { | ||
compileSdkVersion safeExtGet('compileSdkVersion', 33) | ||
namespace "com.powersync.opsqlite" | ||
|
||
// 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 | ||
} | ||
|
||
defaultConfig { | ||
minSdkVersion 23 | ||
targetSdkVersion safeExtGet('targetSdkVersion', 34) | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
externalNativeBuild { | ||
cmake { | ||
|
||
cppFlags "-O2", "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID" | ||
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' | ||
arguments "-DANDROID_STL=c++_shared" | ||
abiFilters (*reactNativeArchitectures()) | ||
} | ||
} | ||
|
||
packagingOptions { | ||
doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : '' | ||
excludes = [ | ||
"META-INF", | ||
"META-INF/**", | ||
"**/libjsi.so", | ||
"**/libreact_nativemodule_core.so", | ||
"**/libturbomodulejsijni.so", | ||
"**/libfbjni.so" | ||
] | ||
} | ||
|
||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
externalNativeBuild { | ||
cmake { | ||
path "CMakeLists.txt" | ||
} | ||
} | ||
|
||
sourceSets.main { | ||
java { | ||
if (isNewArchitectureEnabled()) { | ||
srcDirs += [ | ||
"src/turbo", | ||
// This is needed to build Kotlin project with NewArch enabled | ||
"${project.buildDir}/generated/source/codegen/java" | ||
] | ||
} else { | ||
srcDirs += ["src/legacy"] | ||
} | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
google() | ||
} | ||
|
||
dependencies { | ||
implementation 'com.facebook.react:react-native' | ||
implementation 'co.powersync:powersync-sqlite-core:0.2.1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.powersync.opsqlite"> | ||
|
||
</manifest> |
12 changes: 12 additions & 0 deletions
12
packages/op-sqlite/android/src/main/java/com/powersyncopsqlite/PowersyncOpSqlitePackage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.powersyncopsqlite; | ||
|
||
import com.facebook.react.TurboReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.model.ReactModuleInfoProvider | ||
|
||
class CalculatorPackage : TurboReactPackage() { | ||
override fun getModule(name: String?, reactContext: ReactApplicationContext): NativeModule? = null | ||
|
||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider? = null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
#import "PowersyncOpSqliteSpec.h" | ||
|
||
@interface PowersyncOpSqlite : NSObject <NativePowersyncOpSqliteSpec> | ||
#else | ||
#import <React/RCTBridgeModule.h> | ||
|
||
@interface PowersyncOpSqlite : NSObject <RCTBridgeModule> | ||
#endif | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#import "PowersyncOpSqlite.h" | ||
|
||
@implementation PowersyncOpSqlite | ||
RCT_EXPORT_MODULE() | ||
|
||
// Example method | ||
// See // https://reactnative.dev/docs/native-modules-ios | ||
RCT_REMAP_METHOD(multiply, | ||
multiplyWithA:(double)a withB:(double)b | ||
withResolver:(RCTPromiseResolveBlock)resolve | ||
withRejecter:(RCTPromiseRejectBlock)reject) | ||
{ | ||
NSNumber *result = @(a * b); | ||
|
||
resolve(result); | ||
} | ||
|
||
// Don't compile this code when we build for the old architecture. | ||
#ifdef RCT_NEW_ARCH_ENABLED | ||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule: | ||
(const facebook::react::ObjCTurboModule::InitParams &)params | ||
{ | ||
return std::make_shared<facebook::react::NativePowersyncOpSqliteSpecJSI>(params); | ||
} | ||
#endif | ||
|
||
@end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.