Skip to content

Commit f240c06

Browse files
authored
Merge pull request #127 from Emurgo/feat/CORE-206-jsi-poc
JSI NativeState Bridge
2 parents cd7fade + b2f04dd commit f240c06

File tree

146 files changed

+65409
-54536
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+65409
-54536
lines changed

INSTALLATION_GUIDE.md

Lines changed: 711 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
>DISCLAIMER: the code contained in this repo is experimental and still in WIP status.
22
3-
# cls-mobile-bridge
3+
# csl-mobile-bridge
44

55
https://www.npmjs.com/package/@emurgo/csl-mobile-bridge
66

android/CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(csl_mobile_bridge_jsi)
3+
4+
set(CMAKE_VERBOSE_MAKEFILE ON)
5+
set(CMAKE_CXX_STANDARD 17)
6+
7+
# Paths
8+
set(BUILD_DIR ${CMAKE_CURRENT_LIST_DIR}/build)
9+
10+
# Collect your C++ sources
11+
file(GLOB native_module_SRC CONFIGURE_DEPENDS ${CMAKE_CURRENT_LIST_DIR}/../cpp/*.cpp)
12+
13+
# Define your library
14+
add_library(
15+
csl_mobile_bridge_jsi
16+
SHARED
17+
${native_module_SRC}
18+
)
19+
20+
# Include your own headers
21+
target_include_directories(
22+
csl_mobile_bridge_jsi
23+
PUBLIC
24+
${CMAKE_CURRENT_LIST_DIR}/../cpp
25+
${BUILD_DIR}/generated/source/codegen/jni
26+
)
27+
28+
# Rust dependency (already built .so from your rust build)
29+
add_library(react_native_haskell_shelley SHARED IMPORTED)
30+
set_target_properties(
31+
react_native_haskell_shelley
32+
PROPERTIES
33+
IMPORTED_LOCATION ${BUILD_DIR}/rustJniLibs/android/${ANDROID_ABI}/libreact_native_haskell_shelley.so
34+
)
35+
target_include_directories(
36+
react_native_haskell_shelley
37+
INTERFACE ${CMAKE_CURRENT_LIST_DIR}/../rust/include
38+
)
39+
40+
# Link everything together
41+
target_link_libraries(
42+
csl_mobile_bridge_jsi
43+
react_codegen_RNCslMobileBridgeSpec # <-- generated by RN Codegen
44+
react_native_haskell_shelley # <-- your Rust/Haskell native lib
45+
jsi # <-- JSI from ReactAndroid
46+
android
47+
log
48+
)

android/build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ def isNewArchitectureEnabled() {
4242
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
4343
}
4444

45-
apply plugin: "com.android.library"
46-
4745
if (isNewArchitectureEnabled()) {
4846
apply plugin: "com.facebook.react"
4947
}
@@ -116,7 +114,7 @@ android {
116114
//"${project.buildDir}/generated/source/codegen/java"
117115
]
118116
}
119-
//jniLibs.srcDirs += ["${project.buildDir}/rustJniLibs/android"]
117+
// jniLibs.srcDirs += ["${project.buildDir}/rustJniLibs/android"]
120118
}
121119
}
122120
}
@@ -135,6 +133,13 @@ cargo {
135133
}
136134
}
137135

136+
afterEvaluate {
137+
// Ensure Rust builds before any CMake build task
138+
tasks.matching { it.name.startsWith("buildCMake") }.configureEach {
139+
it.dependsOn("cargoBuild")
140+
}
141+
}
142+
138143
tasks.whenTaskAdded { task ->
139144
if ((task.name == 'javaPreCompileDebug' || task.name == 'javaPreCompileRelease')) {
140145
task.dependsOn 'cargoBuild'
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.emurgo.cslmobilebridge;
2+
3+
import androidx.annotation.Nullable;
4+
import com.facebook.react.bridge.ReactApplicationContext;
5+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
6+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
7+
8+
public class CslMobileBridgeModule extends ReactContextBaseJavaModule implements TurboModule {
9+
public static final String NAME = "CslMobileBridge";
10+
11+
public CslMobileBridgeModule(ReactApplicationContext reactContext) {
12+
super(reactContext);
13+
}
14+
15+
@Override
16+
public String getName() {
17+
return NAME;
18+
}
19+
}
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
package com.emurgo.cslmobilebridge;
22

3-
import androidx.annotation.Nullable;
4-
3+
import androidx.annotation.NonNull;
4+
import com.facebook.react.ReactPackage;
55
import com.facebook.react.bridge.NativeModule;
66
import com.facebook.react.bridge.ReactApplicationContext;
7-
import com.facebook.react.module.model.ReactModuleInfo;
8-
import com.facebook.react.module.model.ReactModuleInfoProvider;
9-
import com.facebook.react.TurboReactPackage;
10-
11-
import java.util.HashMap;
12-
import java.util.Map;
7+
import com.facebook.react.uimanager.ViewManager;
138

14-
public class CslMobileBridgePackage extends TurboReactPackage {
9+
import java.util.Collections;
10+
import java.util.List;
1511

16-
@Nullable
12+
public class CslMobileBridgePackage implements ReactPackage {
13+
@NonNull
1714
@Override
18-
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
19-
return null;
15+
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
16+
return Collections.singletonList(new CslMobileBridgeModule(reactContext));
2017
}
2118

19+
@NonNull
2220
@Override
23-
public ReactModuleInfoProvider getReactModuleInfoProvider() {
24-
return () -> {
25-
return new HashMap<>();
26-
};
21+
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
22+
return Collections.emptyList();
2723
}
2824
}

0 commit comments

Comments
 (0)