Skip to content

Commit 1250fe5

Browse files
authored
Rust support via ferric 🦀 (#43)
* Exclude tests correctly * Refactor CMake CLI, moving common pieces into host package * Add ferric and ferric-example * Cleanup * Build typescript declaration and javascript entrypoint * Fix ferric-example package.json * TEMP: Print when calling into weak-node-api * Patch install name of Apple dylibs * TEMP: Add ferric-examples to test-app * Fix lint error * Downgrading Node-API version in ferric example
1 parent 7bc013b commit 1250fe5

34 files changed

+1430
-184
lines changed

‎apps/test-app/App.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import React from "react";
22
import { StyleSheet, Text, View, Button } from "react-native";
33

4+
/* eslint-disable @typescript-eslint/no-require-imports -- We're using require to defer crashes */
5+
46
// import { requireNodeAddon } from "react-native-node-api-modules";
57
import nodeAddonExamples from "react-native-node-addon-examples";
8+
// import * as ferricExample from "ferric-example";
69

710
function App(): React.JSX.Element {
811
return (
@@ -20,6 +23,15 @@ function App(): React.JSX.Element {
2023
))}
2124
</View>
2225
))}
26+
<View key="ferric-example" style={styles.suite}>
27+
<Text>ferric-example</Text>
28+
<Button
29+
title={"Ferric Example: sum(1, 3)"}
30+
onPress={() =>
31+
console.log("1+3 = " + require("ferric-example").sum(1, 3))
32+
}
33+
/>
34+
</View>
2335
</View>
2436
);
2537
}

‎apps/test-app/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@react-native/typescript-config": "0.79.0",
2222
"@rnx-kit/metro-config": "^2.0.1",
2323
"@types/react": "^19.0.0",
24+
"ferric-example": "^0.1.0",
2425
"react": "19.0.0",
2526
"react-native": "0.79.1",
2627
"react-native-node-addon-examples": "*",

‎package-lock.json‎

Lines changed: 259 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/target
2+
Cargo.lock
3+
4+
/*.xcframework/
5+
/*.android.node/
6+
7+
# Generated files
8+
/libferric_example.d.ts
9+
/libferric_example.js
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "ferric-example"
3+
version = "1.0.0"
4+
edition = "2021"
5+
license = "MIT"
6+
7+
[lib]
8+
crate-type = ["cdylib"]
9+
10+
[dependencies.napi]
11+
version = "2"
12+
default-features = false
13+
# see https://nodejs.org/api/n-api.html#node-api-version-matrix
14+
features = ["napi3"]
15+
16+
[dependencies.napi-derive]
17+
version = "2"
18+
features = ["type-def"]
19+
20+
[build-dependencies]
21+
napi-build = "2"
22+
23+
[profile.release]
24+
lto = true
25+
strip = "symbols"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
napi_build::setup();
3+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "ferric-example",
3+
"version": "0.1.0",
4+
"main": "libferric_example.js",
5+
"types": "libferric_example.d.ts",
6+
"scripts": {
7+
"build": "ferric build --android --apple"
8+
},
9+
"devDependencies": {
10+
"ferric-modules": "^0.1.0"
11+
}
12+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use napi_derive::napi;
2+
3+
#[napi]
4+
pub fn sum(a: i32, b: i32) -> i32 {
5+
a + b
6+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
import "../dist/run.js";
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "ferric-modules",
3+
"version": "0.1.0",
4+
"description": "Rust Node-API Modules for React Native",
5+
"type": "module",
6+
"bin": {
7+
"ferric": "./bin/ferric.js"
8+
},
9+
"scripts": {
10+
"start": "tsx src/run.ts"
11+
},
12+
"dependencies": {
13+
"@napi-rs/cli": "^2.18.4",
14+
"@commander-js/extra-typings": "^13.1.0",
15+
"bufout": "^0.3.1",
16+
"chalk": "^5.4.1",
17+
"commander": "^13.1.0",
18+
"ora": "^8.2.0"
19+
}
20+
}

0 commit comments

Comments
 (0)