Skip to content

Commit 51e41d9

Browse files
committed
Update and add documentation
1 parent a9b002c commit 51e41d9

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

docs/ANDROID.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Building Hermes from source
1+
# Android support
2+
3+
## Building Hermes from source
24

35
Because we're using a version of Hermes patched with Node-API support, we need to build React Native from source.
46

@@ -8,6 +10,8 @@ export REACT_NATIVE_OVERRIDE_HERMES_DIR=`npx react-native-node-api-modules vendo
810

911
## Cleaning your React Native build folders
1012

13+
If you've accidentally built your app without Hermes patched, you can clean things up by deleting the `ReactAndroid` build folder.
14+
1115
```
1216
rm -rf node_modules/react-native/ReactAndroid/build
1317
```

docs/AUTO-LINKING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Auto-linking
2+
3+
The `react-native-node-api-modules` package (sometimes referred to as "the host package") has mechanisms to automatically find and link prebuilt binaries with Node-API modules.
4+
5+
When auto-linking, prebuilt binaries are copied (sometimes referred to as vendored) from dependencies of the app into the host package. As they're copied, they get renamed to avoid conflicts in naming as the library files across multiple dependency packages will be sharing a namespace when building the app.
6+
7+
## Naming scheme of libraries when linked into the host
8+
9+
The name of the library when linked / copied into the host is based on two things:
10+
11+
- The package name of the encapsulating package: The directory tree is walked from the original library path to the nearest `package.json` (this is the Node-API module's package root).
12+
- The relative path of the library to the package root:
13+
- Normalized (any "lib" prefix or file extension is stripped from the filename).
14+
- Escaped (any non-alphanumeric character is replaced with "-").
15+
16+
## How do I link Node-API module libraries into my app?
17+
18+
Linking will run when you `pod install` and as part of building your app with Gradle as long as your app has a dependency on the `react-native-node-api-modules` package.
19+
20+
You can also manually link by running the following in your app directory:
21+
22+
```bash
23+
npx react-native-node-api-modules link --android --apple
24+
```
25+
26+
> [!NOTE]
27+
> Because vendored frameworks must be present when running `pod install`, you have to run `pod install` if you add or remove a dependency with a Node-API module (or after creation if you're doing active development on it).

docs/PREBUILDS.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
11
# Prebuilds
22

3-
This document will codify the naming and directory structure of prebuilt binaries, expected by the `react-native-node-api-modules` package and tools.
3+
This document codifies the naming and directory structure of prebuilt binaries, expected by the auto-linking mechanism.
44

5-
To align with prior art and established patterns around the distribution of Node-API modules for Node.js (and other engines supporting this),
5+
At the time of writing, our auto-linking host package (`react-native-node-api-modules`) support two kinds of prebuilds:
66

7-
## Apple: XCFrameworks of dynamic libraries in frameworks
7+
## `*.android.node` (for Android)
8+
9+
A jniLibs-like directory structure of CPU-architecture specific directories containing a single `.so` library file.
10+
11+
The name of all the `.so` library files:
12+
13+
- must be the same across all CPU-architectures
14+
- can have a "lib" prefix, but doesn't have to
15+
- must have an `.so` or `.node` file extension
16+
17+
> [!NOTE]
18+
> The `SONAME` doesn't have to match and is not updated as the .so is copied into the host package.
19+
> This might cause trouble if you're trying to link with the library from other native code.
20+
> We're tracking [#14](https://github.com/callstackincubator/react-native-node-api-modules/issues/14) to fix this 🤞
21+
22+
The directory must have a `react-native-node-api-module` file (the content doesn't matter), to signal that the directory is intended for auto-linking by the `react-native-node-api-module` package.
23+
24+
## `*.apple.node` (for Apple)
25+
26+
An XCFramework of dynamic libraries wrapped in `.framework` bundles, renamed from `.xcframework` to `.apple.node` to ease discoverability.
827

928
The Apple Developer documentation on ["Creating a multiplatform binary framework bundle"](https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle#Avoid-issues-when-using-alternate-build-systems) mentions:
1029

1130
> An XCFramework can include dynamic library files, but only macOS supports these libraries for dynamic linking. Dynamic linking on iOS, watchOS, and tvOS requires the XCFramework to contain .framework bundles.
1231
13-
<!-- TODO: Write this -->
32+
The directory must have a `react-native-node-api-module` file (the content doesn't matter), to signal that the directory is intended for auto-linking by the `react-native-node-api-module` package.
33+
34+
## Why did we choose this naming scheme?
1435

15-
## Android: Directory of architecture specific directories of shared object library files.
36+
To align with prior art and established patterns around the distribution of Node-API modules for Node.js, we've chosen to use the ".node" filename extension for prebuilds of Node-API modules, targeting React Native.
1637

17-
<!-- TODO: Write this -->
38+
To enable distribution of packages with multiple co-existing platform-specific prebuilts, we've chosen to lean into the pattern of platform-specific filename extensions, used by the Metro bundler.

0 commit comments

Comments
 (0)