Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbo library setup #1

Merged
merged 1 commit into from
Apr 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 0 additions & 15 deletions .editorconfig

This file was deleted.

35 changes: 26 additions & 9 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
cmake_minimum_required(VERSION 3.4.1)
cmake_minimum_required(VERSION 3.9)

set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 11)
project(reactnativeturbostarter-jni LANGUAGES CXX)

add_library(cpp
SHARED
../cpp/react-native-turbo-starter.cpp
cpp-adapter.cpp
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

file(GLOB SOURCES "../cpp/*.cpp")
file(GLOB JNISOURCES "src/main/jni/*.cpp")

add_compile_options(-Wall -Werror -fexceptions -frtti)
add_library(${PROJECT_NAME}
SHARED
${SOURCES}
${JNISOURCES}
)

# Specifies a path to native header files.
include_directories(
../cpp
../cpp
)

find_library(
log-lib
log
)

target_link_libraries(
${PROJECT_NAME}
android
${log-lib}
)
51 changes: 39 additions & 12 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,48 @@ buildscript {
repositories {
google()
mavenCentral()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
}
}
}

apply plugin: 'com.android.library'
def isNewArchitectureEnabled() {
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

apply plugin: "com.facebook.react"
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android {
compileSdkVersion safeExtGet('TurboStarter_compileSdkVersion', 29)
compileSdkVersion safeExtGet('TurboStarter_compileSdkVersion', 31)
defaultConfig {
minSdkVersion safeExtGet('TurboStarter_minSdkVersion', 16)
targetSdkVersion safeExtGet('TurboStarter_targetSdkVersion', 29)
minSdkVersion safeExtGet('TurboStarter_minSdkVersion', 21)
targetSdkVersion safeExtGet('TurboStarter_targetSdkVersion', 31)
versionCode 1
versionName "1.0"

externalNativeBuild {
cmake {
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
arguments "-DCMAKE_VERBOSE_MAKEFILE=1"
cppFlags "-std=c++17"
}
}

}

externalNativeBuild {
cmake {
path "CMakeLists.txt"
# pin cmake version to support M1 machines
version '3.22.1'
}
}

Expand All @@ -46,13 +53,25 @@ android {
minifyEnabled false
}
}

lintOptions {
disable 'GradleCompatible'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

sourceSets.main {
java {
if (!isNewArchitectureEnabled()) {
srcDirs += [
"build/generated/source/codegen/java"
]
}
}
}
}

repositories {
Expand All @@ -63,10 +82,18 @@ repositories {
}
google()
mavenCentral()
jcenter()
}

dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation project(':ReactAndroid')
}

if (isNewArchitectureEnabled()) {
react {
libraryName = "reactnativeturbomodulez"
codegenJavaPackageName = "com.reactnativeturbomodulez"
jsRootDir = file("../src/")
reactRoot = rootProject.file("../node_modules/react-native/")
codegenDir = rootProject.file("../node_modules/react-native-codegen/")
}
}
Binary file added android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.reactnativeturbostarter
import com.facebook.react.bridge.*

class TurboStarterModule(reactContext: ReactApplicationContext?) :
NativeTurboStarterSpec(reactContext) {

override fun getGreeting(name: String): String {
return String.format("Hello, %s!", name)
}

override fun getName(): String {
return NAME
}

companion object {
const val NAME = "TurboStarter"
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.reactnativeturbostarter

import com.facebook.react.ReactPackage
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.NativeModule
import com.facebook.react.uimanager.ViewManager
import java.util.ArrayList
import com.reactnativeturbostarter.TurboStarterModule

class TurboStarterPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
val modules: MutableList<NativeModule> = ArrayList()
modules.add(TurboStarterModule(reactContext))
return modules
}

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
return emptyList()
}
}
6 changes: 2 additions & 4 deletions cpp/react-native-turbo-starter.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "react-native-turbo-starter.h"

namespace example {
int multiply(float a, float b) {
return a * b;
}
namespace turbostarter
{
}
11 changes: 6 additions & 5 deletions cpp/react-native-turbo-starter.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef EXAMPLE_H
#define EXAMPLE_H
#ifndef TURBOSTARTER_H
#define TURBOSTARTER_H

namespace turbostarter
{

namespace example {
int multiply(float a, float b);
}

#endif /* EXAMPLE_H */
#endif /* TURBOSTARTER_H */
8 changes: 1 addition & 7 deletions ios/TurboStarter.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
#import <React/RCTBridgeModule.h>

#ifdef __cplusplus

#import "react-native-turbo-starter.h"

#endif

@interface TurboStarter : NSObject <RCTBridgeModule>
@interface TurboModulez : NSObject <RCTBridgeModule>

@end
24 changes: 14 additions & 10 deletions ios/TurboStarter.mm
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#import "TurboStarter.h"
#import "react-native-turbo-starter.h"
#import "TurboStarter.h"
#import <TurboModulez/TurboModulez.h>

@implementation TurboStarter
@interface TurboStarter() <NativeTurboStarterSpec>
@end

RCT_EXPORT_MODULE()
@implementation TurboStarter

// Example method for C++
// See the implementation of the example module in the `cpp` folder
RCT_EXPORT_METHOD(multiply:(nonnull NSNumber*)a withB:(nonnull NSNumber*)b
withResolver:(RCTPromiseResolveBlock)resolve
withReject:(RCTPromiseRejectBlock)reject)
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const facebook::react::ObjCTurboModule::InitParams &)params
{
NSNumber *result = @(example::multiply([a floatValue], [b floatValue]));
return std::make_shared<facebook::react::NativeTurboModulezSpecJSI>(params);
}

- (NSString *)getGreeting:(NSString *)name {
return [NSString stringWithFormat: @"Hello, %@!", name];
}

resolve(result);
+ (NSString *)moduleName {
return @"TurboStarter";
}

@end