Skip to content

Commit

Permalink
Setup native code and update package name
Browse files Browse the repository at this point in the history
  • Loading branch information
mugikhan committed Sep 12, 2024
1 parent 44bba63 commit 8836706
Show file tree
Hide file tree
Showing 17 changed files with 454 additions and 97 deletions.
14 changes: 7 additions & 7 deletions demos/react-native-supabase-todolist/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ const config: ExpoConfig = {
ios: {
deploymentTarget: '13.4',
// TODO: New architecture is currently not yet supported by @journeyapps/react-native-quick-sqlite
newArchEnabled: false,
extraPods: [
{
name: 'powersync-sqlite-core',
version: '~> 0.1.6'
}
]
newArchEnabled: false
// extraPods: [
// {
// name: 'powersync-sqlite-core',
// version: '~> 0.1.6'
// }
// ]
},
android: {
minSdkVersion: 23,
Expand Down
45 changes: 40 additions & 5 deletions demos/react-native-supabase-todolist/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,34 @@ PODS:
- hermes-engine/Pre-built (= 0.74.1)
- hermes-engine/Pre-built (0.74.1)
- op-sqlite (7.4.0):
- powersync-sqlite-core (~> 0.1.7)
- React
- React-callinvoker
- React-Core
- powersync-sqlite-core (0.1.8)
- powersync-opsqlite (1.0.0):
- DoubleConversion
- glog
- hermes-engine
- powersync-sqlite-core (~> 0.2.1)
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React
- React-callinvoker
- React-Codegen
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- powersync-sqlite-core (0.2.1)
- RCT-Folly (2024.01.01.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -1010,6 +1033,11 @@ PODS:
- React-debug
- react-native-encrypted-storage (4.0.3):
- React-Core
- react-native-quick-sqlite (1.3.0):
- powersync-sqlite-core (~> 0.2.1)
- React
- React-callinvoker
- React-Core
- react-native-safe-area-context (4.10.1):
- React-Core
- React-nativeconfig (0.74.1)
Expand Down Expand Up @@ -1356,7 +1384,7 @@ DEPENDENCIES:
- glog (from `../../../node_modules/react-native/third-party-podspecs/glog.podspec`)
- hermes-engine (from `../../../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
- "op-sqlite (from `../../../node_modules/@op-engineering/op-sqlite`)"
- powersync-sqlite-core (~> 0.1.7)
- "powersync-opsqlite (from `../node_modules/@powersync/op-sqlite`)"
- RCT-Folly (from `../../../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
- RCT-Folly/Fabric (from `../../../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
- RCTDeprecation (from `../../../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation`)
Expand Down Expand Up @@ -1384,6 +1412,7 @@ DEPENDENCIES:
- React-logger (from `../../../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../../../node_modules/react-native/ReactCommon`)
- react-native-encrypted-storage (from `../../../node_modules/react-native-encrypted-storage`)
- "react-native-quick-sqlite (from `../../../node_modules/@journeyapps/react-native-quick-sqlite`)"
- react-native-safe-area-context (from `../../../node_modules/react-native-safe-area-context`)
- React-nativeconfig (from `../../../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../../../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
Expand Down Expand Up @@ -1461,6 +1490,8 @@ EXTERNAL SOURCES:
:tag: hermes-2024-04-25-RNv0.74.1-b54a3a01c531f4f5f1904cb0770033e8b7153dff
op-sqlite:
:path: "../../../node_modules/@op-engineering/op-sqlite"
powersync-opsqlite:
:path: "../node_modules/@powersync/op-sqlite"
RCT-Folly:
:podspec: "../../../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec"
RCTDeprecation:
Expand Down Expand Up @@ -1511,6 +1542,8 @@ EXTERNAL SOURCES:
:path: "../../../node_modules/react-native/ReactCommon"
react-native-encrypted-storage:
:path: "../../../node_modules/react-native-encrypted-storage"
react-native-quick-sqlite:
:path: "../../../node_modules/@journeyapps/react-native-quick-sqlite"
react-native-safe-area-context:
:path: "../../../node_modules/react-native-safe-area-context"
React-nativeconfig:
Expand Down Expand Up @@ -1591,8 +1624,9 @@ SPEC CHECKSUMS:
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
hermes-engine: 16b8530de1b383cdada1476cf52d1b52f0692cbc
op-sqlite: 7d8e4d98813a06d1c938868d565ccc81a77a158f
powersync-sqlite-core: 9325150c88515df0b5ea992007708588c3f01518
op-sqlite: 93397f1a6cc24e9662ee8c0ee5e59466baa06f4a
powersync-opsqlite: fe90a95060493238eea75ecf0b7d662327022883
powersync-sqlite-core: 38ead13d8b21920cfbc79e9b3415b833574a506d
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
RCTDeprecation: efb313d8126259e9294dc4ee0002f44a6f676aba
RCTRequired: f49ea29cece52aee20db633ae7edc4b271435562
Expand All @@ -1618,6 +1652,7 @@ SPEC CHECKSUMS:
React-logger: 7e7403a2b14c97f847d90763af76b84b152b6fce
React-Mapbuffer: 11029dcd47c5c9e057a4092ab9c2a8d10a496a33
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
react-native-quick-sqlite: 3d7faa9ac557da507cb8a1684fb78682fefb1cfb
react-native-safe-area-context: dcab599c527c2d7de2d76507a523d20a0b83823d
React-nativeconfig: b0073a590774e8b35192fead188a36d1dca23dec
React-NativeModulesApple: df46ff3e3de5b842b30b4ca8a6caae6d7c8ab09f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"EX_DEV_CLIENT_NETWORK_INSPECTOR": "true",
"ios.deploymentTarget": "13.4",
"newArchEnabled": "false",
"apple.extraPods": "[{\"name\":\"powersync-sqlite-core\",\"version\":\"~> 0.1.7\"}]",
"apple.ccacheEnabled": "false",
"apple.privacyManifestAggregationEnabled": "true"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { PhotoAttachmentQueue } from './PhotoAttachmentQueue';
import { type AttachmentRecord } from '@powersync/attachments';
import { AppConfig } from '../supabase/AppConfig';
import Logger from 'js-logger';
import { OPSqliteOpenFactory } from '@powersync/react-native-op-sqlite';
import { OPSqliteOpenFactory } from '@powersync/op-sqlite';

Logger.useDefaults();

Expand Down
2 changes: 1 addition & 1 deletion demos/react-native-supabase-todolist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@powersync/common": "workspace:*",
"@powersync/react": "workspace:*",
"@powersync/react-native": "workspace:*",
"@powersync/react-native-op-sqlite": "workspace:*",
"@powersync/op-sqlite": "workspace:*",
"@react-native-community/masked-view": "^0.1.11",
"@react-navigation/drawer": "^6.6.3",
"@react-navigation/native": "^6.0.0",
Expand Down
43 changes: 43 additions & 0 deletions packages/op-sqlite/android/CMakeLists.txt
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
)
112 changes: 112 additions & 0 deletions packages/op-sqlite/android/build.gradle
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'
}
4 changes: 4 additions & 0 deletions packages/op-sqlite/android/src/main/AndroidManifest.xml
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>
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
}
11 changes: 11 additions & 0 deletions packages/op-sqlite/ios/PowersyncOpSqlite.h
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
27 changes: 27 additions & 0 deletions packages/op-sqlite/ios/PowersyncOpSqlite.mm
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
18 changes: 0 additions & 18 deletions packages/op-sqlite/jest.config.ts

This file was deleted.

Loading

0 comments on commit 8836706

Please sign in to comment.