jazz-rn 2.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/JazzRn.podspec +44 -0
- package/README.md +47 -0
- package/android/CMakeLists.txt +76 -0
- package/android/build.gradle +144 -0
- package/android/cpp-adapter.cpp +43 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/jazzrn/JazzRnModule.kt +43 -0
- package/android/src/main/java/com/jazzrn/JazzRnPackage.kt +34 -0
- package/cpp/jazz-rn.cpp +16 -0
- package/cpp/jazz-rn.h +15 -0
- package/ios/JazzRn.h +16 -0
- package/ios/JazzRn.mm +66 -0
- package/lib/module/NativeJazzRn.js +7 -0
- package/lib/module/NativeJazzRn.js.map +1 -0
- package/lib/module/generated/jazz_rn-ffi.js +43 -0
- package/lib/module/generated/jazz_rn-ffi.js.map +1 -0
- package/lib/module/generated/jazz_rn.js +714 -0
- package/lib/module/generated/jazz_rn.js.map +1 -0
- package/lib/module/index.js +43 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeJazzRn.d.ts +8 -0
- package/lib/typescript/src/NativeJazzRn.d.ts.map +1 -0
- package/lib/typescript/src/generated/jazz_rn-ffi.d.ts +147 -0
- package/lib/typescript/src/generated/jazz_rn-ffi.d.ts.map +1 -0
- package/lib/typescript/src/generated/jazz_rn.d.ts +644 -0
- package/lib/typescript/src/generated/jazz_rn.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +8 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +170 -0
- package/react-native.config.js +11 -0
- package/src/NativeJazzRn.ts +10 -0
- package/src/generated/jazz_rn-ffi.ts +360 -0
- package/src/generated/jazz_rn.ts +1391 -0
- package/src/index.tsx +41 -0
package/JazzRn.podspec
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Generated by uniffi-bindgen-react-native
|
|
2
|
+
require "json"
|
|
3
|
+
|
|
4
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
5
|
+
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
|
6
|
+
|
|
7
|
+
Pod::Spec.new do |s|
|
|
8
|
+
s.name = "JazzRn"
|
|
9
|
+
s.version = package["version"]
|
|
10
|
+
s.summary = package["description"]
|
|
11
|
+
s.homepage = package["homepage"]
|
|
12
|
+
s.license = package["license"]
|
|
13
|
+
s.authors = package["author"]
|
|
14
|
+
|
|
15
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
16
|
+
s.source = { :git => "https://https://github.com/garden-co/jazz.git", :tag => "#{s.version}" }
|
|
17
|
+
|
|
18
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}", "ios/generated/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}", "cpp/generated/**/*.{hpp,cpp,c,h}"
|
|
19
|
+
s.vendored_frameworks = "JazzRnFramework.xcframework"
|
|
20
|
+
s.dependency "uniffi-bindgen-react-native", "0.29.3-1"
|
|
21
|
+
|
|
22
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
23
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
24
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
25
|
+
install_modules_dependencies(s)
|
|
26
|
+
else
|
|
27
|
+
s.dependency "React-Core"
|
|
28
|
+
|
|
29
|
+
# Don't install the dependencies when we run `pod install` in the old architecture.
|
|
30
|
+
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
|
|
31
|
+
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
|
|
32
|
+
s.pod_target_xcconfig = {
|
|
33
|
+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
|
|
34
|
+
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
|
|
35
|
+
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
|
|
36
|
+
}
|
|
37
|
+
s.dependency "React-Codegen"
|
|
38
|
+
s.dependency "RCT-Folly"
|
|
39
|
+
s.dependency "RCTRequired"
|
|
40
|
+
s.dependency "RCTTypeSafety"
|
|
41
|
+
s.dependency "ReactCommon/turbomodule/core"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# jazz-rn
|
|
2
|
+
|
|
3
|
+
A React Native native module that provides high-performance cryptographic operations for the Jazz framework, built with Rust and UniFFI. This package exposes the same cryptographic primitives as `jazz-napi` and `jazz-wasm` but specifically designed for React Native applications running on iOS and Android.
|
|
4
|
+
|
|
5
|
+
## What is jazz-rn?
|
|
6
|
+
|
|
7
|
+
`jazz-rn` is a React Native Turbo Module that bridges Rust-based cryptographic code to JavaScript/TypeScript. It uses [uniffi-bindgen-react-native](https://jhugman.github.io/uniffi-bindgen-react-native/) that uses [UniFFI](https://mozilla.github.io/uniffi-rs/) (Unified Foreign Function Interface) to automatically generate type-safe bindings between Rust and React Native, enabling you to use high-performance cryptographic operations in your React Native applications.
|
|
8
|
+
|
|
9
|
+
### Architecture
|
|
10
|
+
|
|
11
|
+
The package consists of:
|
|
12
|
+
|
|
13
|
+
- **Rust Core** (`rust/`): The core cryptographic implementation, shared with `jazz` and `jazz-napi`
|
|
14
|
+
- **UniFFI Bindings**: Automatically generated bindings that bridge Rust to React Native
|
|
15
|
+
- **Native Modules**:
|
|
16
|
+
- **iOS**: XCFramework containing static libraries for arm64 (device) and arm64-simulator
|
|
17
|
+
- **Android**: CMake-based native library compiled for multiple architectures
|
|
18
|
+
- **TypeScript Wrapper**: Type-safe JavaScript/TypeScript API that wraps the native bindings
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
### In the Jazz Monorepo
|
|
23
|
+
|
|
24
|
+
If you're working within the Jazz monorepo, the package is already available as a workspace dependency:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# From the monorepo root
|
|
28
|
+
pnpm install
|
|
29
|
+
pnpm build:rn
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### As a Standalone Package
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm install jazz-rn
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The package includes pre-built native binaries for:
|
|
39
|
+
|
|
40
|
+
- **iOS**: arm64 (device) and arm64-simulator
|
|
41
|
+
- **Android**: Multiple architectures (arm64, arm, x86_64, etc.)
|
|
42
|
+
|
|
43
|
+
## Building from Source
|
|
44
|
+
|
|
45
|
+
### Prerequisites
|
|
46
|
+
|
|
47
|
+
Before building `jazz-rn`, ensure you followed this [guide](https://jhugman.github.io/uniffi-bindgen-react-native/guides/rn/pre-installation.html).
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Generated by uniffi-bindgen-react-native
|
|
2
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
3
|
+
project(JazzRn)
|
|
4
|
+
|
|
5
|
+
set (CMAKE_VERBOSE_MAKEFILE ON)
|
|
6
|
+
set (CMAKE_CXX_STANDARD 17)
|
|
7
|
+
|
|
8
|
+
# Resolve the path to the uniffi-bindgen-react-native package
|
|
9
|
+
execute_process(
|
|
10
|
+
COMMAND node -p "require.resolve('uniffi-bindgen-react-native/package.json')"
|
|
11
|
+
OUTPUT_VARIABLE UNIFFI_BINDGEN_PATH
|
|
12
|
+
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
13
|
+
)
|
|
14
|
+
# Get the directory; get_filename_component and cmake_path will normalize
|
|
15
|
+
# paths with Windows path separators.
|
|
16
|
+
get_filename_component(UNIFFI_BINDGEN_PATH "${UNIFFI_BINDGEN_PATH}" DIRECTORY)
|
|
17
|
+
|
|
18
|
+
# Specifies a path to native header files.
|
|
19
|
+
include_directories(
|
|
20
|
+
../cpp
|
|
21
|
+
../cpp/generated
|
|
22
|
+
|
|
23
|
+
${UNIFFI_BINDGEN_PATH}/cpp/includes
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
add_library(jazz-rn SHARED
|
|
27
|
+
../cpp/jazz-rn.cpp
|
|
28
|
+
../cpp/generated/jazz_rn.cpp
|
|
29
|
+
cpp-adapter.cpp
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# Set C++ compiler flags
|
|
33
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
|
34
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
|
|
35
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti")
|
|
36
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all")
|
|
37
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
|
38
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
|
39
|
+
|
|
40
|
+
cmake_path(
|
|
41
|
+
SET MY_RUST_LIB
|
|
42
|
+
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libjazz_rn.a
|
|
43
|
+
NORMALIZE
|
|
44
|
+
)
|
|
45
|
+
add_library(my_rust_lib STATIC IMPORTED)
|
|
46
|
+
set_target_properties(my_rust_lib PROPERTIES IMPORTED_LOCATION ${MY_RUST_LIB})
|
|
47
|
+
|
|
48
|
+
# Add ReactAndroid libraries, being careful to account for different versions.
|
|
49
|
+
find_package(ReactAndroid REQUIRED CONFIG)
|
|
50
|
+
find_library(LOGCAT log)
|
|
51
|
+
|
|
52
|
+
# REACTNATIVE_MERGED_SO seems to be only be set in a build.gradle.kt file,
|
|
53
|
+
# which we don't use. Thus falling back to version number sniffing.
|
|
54
|
+
if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
|
|
55
|
+
set(REACTNATIVE_MERGED_SO true)
|
|
56
|
+
endif()
|
|
57
|
+
|
|
58
|
+
# https://github.com/react-native-community/discussions-and-proposals/discussions/816
|
|
59
|
+
# This if-then-else can be removed once this library does not support version below 0.76
|
|
60
|
+
if (REACTNATIVE_MERGED_SO)
|
|
61
|
+
target_link_libraries(jazz-rn ReactAndroid::reactnative)
|
|
62
|
+
else()
|
|
63
|
+
target_link_libraries(jazz-rn
|
|
64
|
+
ReactAndroid::turbomodulejsijni
|
|
65
|
+
ReactAndroid::react_nativemodule_core
|
|
66
|
+
)
|
|
67
|
+
endif()
|
|
68
|
+
|
|
69
|
+
find_package(fbjni REQUIRED CONFIG)
|
|
70
|
+
target_link_libraries(
|
|
71
|
+
jazz-rn
|
|
72
|
+
fbjni::fbjni
|
|
73
|
+
ReactAndroid::jsi
|
|
74
|
+
${LOGCAT}
|
|
75
|
+
my_rust_lib
|
|
76
|
+
)
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// Generated by uniffi-bindgen-react-native
|
|
2
|
+
|
|
3
|
+
buildscript {
|
|
4
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
5
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["DummyLibForAndroid_kotlinVersion"]
|
|
6
|
+
|
|
7
|
+
repositories {
|
|
8
|
+
google()
|
|
9
|
+
mavenCentral()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
dependencies {
|
|
13
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
14
|
+
// noinspection DifferentKotlinGradleVersion
|
|
15
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def reactNativeArchitectures() {
|
|
20
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
21
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
def isNewArchitectureEnabled() {
|
|
25
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
apply plugin: "com.android.library"
|
|
29
|
+
apply plugin: "kotlin-android"
|
|
30
|
+
|
|
31
|
+
if (isNewArchitectureEnabled()) {
|
|
32
|
+
apply plugin: "com.facebook.react"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
def getExtOrDefault(name) {
|
|
36
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["JazzRn_" + name]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
def getExtOrIntegerDefault(name) {
|
|
40
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["JazzRn_" + name]).toInteger()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
def supportsNamespace() {
|
|
44
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
45
|
+
def major = parsed[0].toInteger()
|
|
46
|
+
def minor = parsed[1].toInteger()
|
|
47
|
+
|
|
48
|
+
// Namespace support was added in 7.3.0
|
|
49
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
android {
|
|
53
|
+
if (supportsNamespace()) {
|
|
54
|
+
namespace "com.jazzrn"
|
|
55
|
+
|
|
56
|
+
sourceSets {
|
|
57
|
+
main {
|
|
58
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
ndkVersion getExtOrDefault("ndkVersion")
|
|
64
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
65
|
+
|
|
66
|
+
defaultConfig {
|
|
67
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
68
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
69
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
70
|
+
consumerProguardFiles 'proguard-rules.pro'
|
|
71
|
+
|
|
72
|
+
buildFeatures {
|
|
73
|
+
prefab true
|
|
74
|
+
}
|
|
75
|
+
externalNativeBuild {
|
|
76
|
+
cmake {
|
|
77
|
+
arguments '-DANDROID_STL=c++_shared', '-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON'
|
|
78
|
+
abiFilters (*reactNativeArchitectures())
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
ndk {
|
|
82
|
+
abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
externalNativeBuild {
|
|
87
|
+
cmake {
|
|
88
|
+
path "CMakeLists.txt"
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
buildFeatures {
|
|
93
|
+
buildConfig true
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
buildTypes {
|
|
97
|
+
release {
|
|
98
|
+
minifyEnabled false
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
lintOptions {
|
|
103
|
+
disable "GradleCompatible"
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
compileOptions {
|
|
107
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
108
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
sourceSets {
|
|
112
|
+
main {
|
|
113
|
+
if (isNewArchitectureEnabled()) {
|
|
114
|
+
java.srcDirs += [
|
|
115
|
+
"generated/java",
|
|
116
|
+
"generated/jni"
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
repositories {
|
|
124
|
+
mavenCentral()
|
|
125
|
+
google()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
129
|
+
|
|
130
|
+
dependencies {
|
|
131
|
+
// For < 0.71, this will be from the local maven repo
|
|
132
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
133
|
+
//noinspection GradleDynamicVersion
|
|
134
|
+
implementation "com.facebook.react:react-native:+"
|
|
135
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (isNewArchitectureEnabled()) {
|
|
139
|
+
react {
|
|
140
|
+
jsRootDir = file("../src/")
|
|
141
|
+
libraryName = "JazzRn"
|
|
142
|
+
codegenJavaPackageName = "com.jazzrn"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Generated by uniffi-bindgen-react-native
|
|
2
|
+
#include <jni.h>
|
|
3
|
+
#include <jsi/jsi.h>
|
|
4
|
+
#include <ReactCommon/CallInvokerHolder.h>
|
|
5
|
+
#include "jazz-rn.h"
|
|
6
|
+
|
|
7
|
+
namespace jsi = facebook::jsi;
|
|
8
|
+
namespace react = facebook::react;
|
|
9
|
+
|
|
10
|
+
// Automated testing checks Java_com_jazzrn_JazzRnModule and jazzrn
|
|
11
|
+
// by comparing the whole line here.
|
|
12
|
+
/*
|
|
13
|
+
Java_com_jazzrn_JazzRnModule_nativeMultiply(JNIEnv *env, jclass type, jdouble a, jdouble b) {
|
|
14
|
+
return jazzrn::multiply(a, b);
|
|
15
|
+
}
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// Installer coming from JazzRnModule
|
|
19
|
+
extern "C"
|
|
20
|
+
JNIEXPORT jboolean JNICALL
|
|
21
|
+
Java_com_jazzrn_JazzRnModule_nativeInstallRustCrate(
|
|
22
|
+
JNIEnv *env,
|
|
23
|
+
jclass type,
|
|
24
|
+
jlong rtPtr,
|
|
25
|
+
jobject callInvokerHolderJavaObj
|
|
26
|
+
) {
|
|
27
|
+
using JCallInvokerHolder = facebook::react::CallInvokerHolder;
|
|
28
|
+
|
|
29
|
+
auto holderLocal = facebook::jni::make_local(callInvokerHolderJavaObj);
|
|
30
|
+
auto holderRef = facebook::jni::static_ref_cast<JCallInvokerHolder::javaobject>(holderLocal);
|
|
31
|
+
auto* holderCxx = holderRef->cthis();
|
|
32
|
+
auto jsCallInvoker = holderCxx->getCallInvoker();
|
|
33
|
+
|
|
34
|
+
auto runtime = reinterpret_cast<jsi::Runtime *>(rtPtr);
|
|
35
|
+
return jazzrn::installRustCrate(*runtime, jsCallInvoker);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
extern "C"
|
|
39
|
+
JNIEXPORT jboolean JNICALL
|
|
40
|
+
Java_com_jazzrn_JazzRnModule_nativeCleanupRustCrate(JNIEnv *env, jclass type, jlong rtPtr) {
|
|
41
|
+
auto runtime = reinterpret_cast<jsi::Runtime *>(rtPtr);
|
|
42
|
+
return jazzrn::cleanupRustCrate(*runtime);
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Generated by uniffi-bindgen-react-native
|
|
2
|
+
package com.jazzrn
|
|
3
|
+
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
6
|
+
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder
|
|
7
|
+
|
|
8
|
+
@ReactModule(name = JazzRnModule.NAME)
|
|
9
|
+
class JazzRnModule(reactContext: ReactApplicationContext) :
|
|
10
|
+
NativeJazzRnSpec(reactContext) {
|
|
11
|
+
|
|
12
|
+
override fun getName(): String {
|
|
13
|
+
return NAME
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Two native methods implemented in cpp-adapter.cpp, and ultimately
|
|
17
|
+
// jazz-rn.cpp
|
|
18
|
+
|
|
19
|
+
external fun nativeInstallRustCrate(runtimePointer: Long, callInvoker: CallInvokerHolder): Boolean
|
|
20
|
+
external fun nativeCleanupRustCrate(runtimePointer: Long): Boolean
|
|
21
|
+
|
|
22
|
+
override fun installRustCrate(): Boolean {
|
|
23
|
+
val context = this.reactApplicationContext
|
|
24
|
+
return nativeInstallRustCrate(
|
|
25
|
+
context.javaScriptContextHolder!!.get(),
|
|
26
|
+
context.jsCallInvokerHolder!!
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun cleanupRustCrate(): Boolean {
|
|
31
|
+
return nativeCleanupRustCrate(
|
|
32
|
+
this.reactApplicationContext.javaScriptContextHolder!!.get()
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
companion object {
|
|
37
|
+
const val NAME = "JazzRn"
|
|
38
|
+
|
|
39
|
+
init {
|
|
40
|
+
System.loadLibrary("jazz-rn")
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Generated by uniffi-bindgen-react-native
|
|
2
|
+
package com.jazzrn
|
|
3
|
+
|
|
4
|
+
import com.facebook.react.TurboReactPackage
|
|
5
|
+
import com.facebook.react.bridge.NativeModule
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
9
|
+
import java.util.HashMap
|
|
10
|
+
|
|
11
|
+
class JazzRnPackage : TurboReactPackage() {
|
|
12
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
13
|
+
return if (name == JazzRnModule.NAME) {
|
|
14
|
+
JazzRnModule(reactContext)
|
|
15
|
+
} else {
|
|
16
|
+
null
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
21
|
+
return ReactModuleInfoProvider {
|
|
22
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
23
|
+
moduleInfos[JazzRnModule.NAME] = ReactModuleInfo(
|
|
24
|
+
JazzRnModule.NAME,
|
|
25
|
+
JazzRnModule.NAME,
|
|
26
|
+
false, // canOverrideExistingModule
|
|
27
|
+
false, // needsEagerInit
|
|
28
|
+
false, // isCxxModule
|
|
29
|
+
true // isTurboModule
|
|
30
|
+
)
|
|
31
|
+
moduleInfos
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/cpp/jazz-rn.cpp
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Generated by uniffi-bindgen-react-native
|
|
2
|
+
#include "jazz-rn.h"
|
|
3
|
+
#include "generated/jazz_rn.hpp"
|
|
4
|
+
|
|
5
|
+
namespace jazzrn {
|
|
6
|
+
using namespace facebook;
|
|
7
|
+
|
|
8
|
+
uint8_t installRustCrate(jsi::Runtime &runtime, std::shared_ptr<react::CallInvoker> callInvoker) {
|
|
9
|
+
NativeJazzRn::registerModule(runtime, callInvoker);
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
uint8_t cleanupRustCrate(jsi::Runtime &runtime) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
package/cpp/jazz-rn.h
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#ifndef JAZZRN_H
|
|
2
|
+
#define JAZZRN_H
|
|
3
|
+
// Generated by uniffi-bindgen-react-native
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
#include <ReactCommon/CallInvoker.h>
|
|
7
|
+
|
|
8
|
+
namespace jazzrn {
|
|
9
|
+
using namespace facebook;
|
|
10
|
+
|
|
11
|
+
uint8_t installRustCrate(jsi::Runtime &runtime, std::shared_ptr<react::CallInvoker> callInvoker);
|
|
12
|
+
uint8_t cleanupRustCrate(jsi::Runtime &runtime);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
#endif /* JAZZRN_H */
|
package/ios/JazzRn.h
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Generated by uniffi-bindgen-react-native
|
|
2
|
+
#ifdef __cplusplus
|
|
3
|
+
#import "jazz-rn.h"
|
|
4
|
+
#endif
|
|
5
|
+
|
|
6
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
7
|
+
#import "JazzRnSpec.h"
|
|
8
|
+
|
|
9
|
+
@interface JazzRn : NSObject <NativeJazzRnSpec>
|
|
10
|
+
#else
|
|
11
|
+
#import <React/RCTBridgeModule.h>
|
|
12
|
+
|
|
13
|
+
@interface JazzRn : NSObject <RCTBridgeModule>
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
@end
|
package/ios/JazzRn.mm
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Generated by uniffi-bindgen-react-native
|
|
2
|
+
#import "JazzRn.h"
|
|
3
|
+
|
|
4
|
+
namespace uniffi_generated {
|
|
5
|
+
using namespace facebook::react;
|
|
6
|
+
/**
|
|
7
|
+
* ObjC++ class for module 'NativeJazzRn'
|
|
8
|
+
*/
|
|
9
|
+
class JSI_EXPORT NativeJazzRnSpecJSI : public ObjCTurboModule {
|
|
10
|
+
public:
|
|
11
|
+
NativeJazzRnSpecJSI(const ObjCTurboModule::InitParams ¶ms);
|
|
12
|
+
std::shared_ptr<CallInvoker> callInvoker;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
static facebook::jsi::Value __hostFunction_JazzRn_installRustCrate(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
16
|
+
auto& tm = static_cast<NativeJazzRnSpecJSI&>(turboModule);
|
|
17
|
+
auto jsInvoker = tm.callInvoker;
|
|
18
|
+
uint8_t result = jazzrn::installRustCrate(rt, jsInvoker);
|
|
19
|
+
return facebook::jsi::Value(rt, result);
|
|
20
|
+
}
|
|
21
|
+
static facebook::jsi::Value __hostFunction_JazzRn_cleanupRustCrate(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
22
|
+
uint8_t result = jazzrn::cleanupRustCrate(rt);
|
|
23
|
+
return facebook::jsi::Value(rt, result);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
NativeJazzRnSpecJSI::NativeJazzRnSpecJSI(const ObjCTurboModule::InitParams ¶ms)
|
|
27
|
+
: ObjCTurboModule(params), callInvoker(params.jsInvoker) {
|
|
28
|
+
this->methodMap_["installRustCrate"] = MethodMetadata {1, __hostFunction_JazzRn_installRustCrate};
|
|
29
|
+
this->methodMap_["cleanupRustCrate"] = MethodMetadata {1, __hostFunction_JazzRn_cleanupRustCrate};
|
|
30
|
+
}
|
|
31
|
+
} // namespace uniffi_generated
|
|
32
|
+
|
|
33
|
+
@implementation JazzRn
|
|
34
|
+
RCT_EXPORT_MODULE()
|
|
35
|
+
|
|
36
|
+
// Don't compile this code when we build for the old architecture.
|
|
37
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
38
|
+
|
|
39
|
+
// Automated testing checks jazzrn
|
|
40
|
+
// by comparing the whole line here.
|
|
41
|
+
/*
|
|
42
|
+
- (NSNumber *)multiply:(double)a b:(double)b {
|
|
43
|
+
NSNumber *result = @(jazzrn::multiply(a, b));
|
|
44
|
+
}
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
- (NSNumber *)installRustCrate {
|
|
48
|
+
@throw [NSException exceptionWithName:@"UnreachableException"
|
|
49
|
+
reason:@"This method should never be called."
|
|
50
|
+
userInfo:nil];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (NSNumber *)cleanupRustCrate {
|
|
54
|
+
@throw [NSException exceptionWithName:@"UnreachableException"
|
|
55
|
+
reason:@"This method should never be called."
|
|
56
|
+
userInfo:nil];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
60
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
61
|
+
{
|
|
62
|
+
return std::make_shared<uniffi_generated::NativeJazzRnSpecJSI>(params);
|
|
63
|
+
}
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
@end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeJazzRn.ts"],"mappings":";;AAAA;;AAEA,SAASA,mBAAmB,QAAQ,cAAc;AAOlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,QAAQ,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// This file was autogenerated by some hot garbage in the `uniffi-bindgen-react-native` crate.
|
|
4
|
+
// Trust me, you don't want to mess with it!
|
|
5
|
+
|
|
6
|
+
// Casting globalThis to any allows us to look for `NativeJazzRn`
|
|
7
|
+
// if it was added via JSI.
|
|
8
|
+
//
|
|
9
|
+
// We use a getter here rather than simply `globalThis.NativeJazzRn` so that
|
|
10
|
+
// if/when the startup sequence isn't just so, an empty value isn't inadvertantly cached.
|
|
11
|
+
const getter = () => globalThis.NativeJazzRn;
|
|
12
|
+
export default getter;
|
|
13
|
+
|
|
14
|
+
// Structs and function types for calling back into Typescript from Rust.
|
|
15
|
+
|
|
16
|
+
// UniffiRustFutureContinuationCallback is generated as part of the component interface's
|
|
17
|
+
// ffi_definitions. However, we need it in the runtime.
|
|
18
|
+
// We could:
|
|
19
|
+
// (a) do some complicated template logic to ensure the declaration is not generated here (possible)
|
|
20
|
+
// (b) import the generated declaration into the runtime (m a y b e) or…
|
|
21
|
+
// (c) generate the declaration anyway, and use a different declaration in the runtime.
|
|
22
|
+
//
|
|
23
|
+
// We chose (c) here as the simplest. In addition, we perform a compile time check that
|
|
24
|
+
// the two versions of `UniffiRustFutureContinuationCallback` are structurally equivalent.
|
|
25
|
+
//
|
|
26
|
+
// If you see the error:
|
|
27
|
+
// ```
|
|
28
|
+
// Type 'true' is not assignable to type 'false'.(2322)
|
|
29
|
+
// ```
|
|
30
|
+
// Then a new version of uniffi has changed the signature of the callback. Most likely, code in
|
|
31
|
+
// `typescript/src/async-rust-call.ts` will need to be changed.
|
|
32
|
+
//
|
|
33
|
+
// If you see the error:
|
|
34
|
+
// ```
|
|
35
|
+
// Cannot find name 'UniffiRustFutureContinuationCallback'. Did you mean 'RuntimeUniffiRustFutureContinuationCallback'?(2552)
|
|
36
|
+
// ```
|
|
37
|
+
// then you may not be using callbacks or promises, and uniffi is now not generating Futures and callbacks.
|
|
38
|
+
// You should not generate this if that is the case.
|
|
39
|
+
//
|
|
40
|
+
// ('You' being the bindings generator maintainer).
|
|
41
|
+
const isRustFutureContinuationCallbackTypeCompatible = true;
|
|
42
|
+
const isUniffiForeignFutureTypeCompatible = true;
|
|
43
|
+
//# sourceMappingURL=jazz_rn-ffi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getter","globalThis","NativeJazzRn","isRustFutureContinuationCallbackTypeCompatible","isUniffiForeignFutureTypeCompatible"],"sourceRoot":"../../../src","sources":["generated/jazz_rn-ffi.ts"],"mappings":";;AAAA;AACA;;AAmLA;AACA;AACA;AACA;AACA;AACA,MAAMA,MAAmC,GAAGA,CAAA,KACzCC,UAAU,CAASC,YAAY;AAClC,eAAeF,MAAM;;AAErB;;AA0IA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,8CAGL,GAAG,IAAI;AACR,MAAMC,mCAGL,GAAG,IAAI","ignoreList":[]}
|