Skip to content

Commit a2fd422

Browse files
authored
MacOS test app and fix hermes vendoring from react-native-macos (#297)
* Remove platform restriction from host package's podspec * Add fallback for watchFolders in the metro config * Update Podspec to detect React Native package name * Add script to init a MacOS test app Enable Hermes and Fabric Patch react_native_post_install to pass react native path Don't pod install when initializing Patch macos app with scripts and source files Re-arm the init script Move linked deps into install command to make --install-links effective Using regular linking for monorepo deps Include original dependencies Enable new arch in Podfile Fix comment from review * Add job in the check workflow to initialize and build the MacOS test app No need to Setup Android SDK Debugging with Copilot Pass --mode when building from CLI Install CMake 3.22 Fix bootstrap issue Trying a higher CMake version Remove debug info from workflow Build universal Darwin libraries Add missing x86_64-apple-darwin Rust target to macOS CI job (#298) * Initial plan * Add missing x86_64-apple-darwin Rust target to macOS job Co-authored-by: kraenhansen <[email protected]> * Add only missing x86_64-apple-darwin target (aarch64 is host) Co-authored-by: kraenhansen <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: kraenhansen <[email protected]> Run MacOS test app Use package script to run all tests
1 parent 1d636d6 commit a2fd422

File tree

12 files changed

+284
-17
lines changed

12 files changed

+284
-17
lines changed

.changeset/silly-mice-warn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"react-native-node-api": patch
3+
---
4+
5+
Detects "pod install" from React Native MacOS apps and vendors Hermes accordingly

.github/workflows/check.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,39 @@ jobs:
107107
# TODO: Enable release mode when it works
108108
# run: npm run test:ios -- --mode Release
109109
working-directory: apps/test-app
110+
test-macos:
111+
# Disabling this on main for now, as initializing the template takes a long time and
112+
# we don't have macOS-specific code yet
113+
if: contains(github.event.pull_request.labels.*.name, 'MacOS 💻')
114+
name: Test app (macOS)
115+
runs-on: macos-latest
116+
steps:
117+
- uses: actions/checkout@v4
118+
- uses: actions/setup-node@v4
119+
with:
120+
node-version: lts/jod
121+
- name: Set up JDK 17
122+
uses: actions/setup-java@v3
123+
with:
124+
java-version: "17"
125+
distribution: "temurin"
126+
# Install CMake 3 since 4.x may have compatibility issues with Hermes build system
127+
- name: Install compatible CMake version
128+
uses: jwlawson/actions-setup-cmake@v2
129+
with:
130+
cmake-version: "3.31.2"
131+
- run: rustup target add x86_64-apple-darwin
132+
- run: npm ci
133+
- run: npm run bootstrap
134+
env:
135+
CMAKE_RN_TRIPLETS: arm64;x86_64-apple-darwin
136+
FERRIC_TARGETS: aarch64-apple-darwin,x86_64-apple-darwin
137+
- run: npm run init-macos-test-app
138+
- run: pod install --project-directory=macos
139+
working-directory: apps/macos-test-app
140+
- name: Run MacOS test app
141+
run: npm run test:allTests -- --mode Release
142+
working-directory: apps/macos-test-app
110143
test-android:
111144
if: github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'Android 🤖')
112145
name: Test app (Android)

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ node_modules/
44
dist/
55

66
*.tsbuildinfo
7+
8+
# Treading the MacOS app as ephemeral
9+
apps/macos-test-app

apps/test-app/metro.config.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const { makeMetroConfig } = require("@rnx-kit/metro-config");
2-
module.exports = makeMetroConfig({
2+
3+
const config = makeMetroConfig({
34
transformer: {
45
getTransformOptions: async () => ({
56
transform: {
@@ -9,3 +10,13 @@ module.exports = makeMetroConfig({
910
}),
1011
},
1112
});
13+
14+
if (config.watchFolders.length === 0) {
15+
// This patch is needed to locate packages in the monorepo from the MacOS app
16+
// which is intentionally kept outside of the workspaces configuration to prevent
17+
// duplicate react-native version and pollution of the package lock.
18+
const path = require("node:path");
19+
config.watchFolders.push(path.resolve(__dirname, "../.."));
20+
}
21+
22+
module.exports = config;

eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export default tseslint.config(
4747
{
4848
files: [
4949
"apps/test-app/*.js",
50+
"apps/macos-test-app/*.js",
5051
"packages/node-addon-examples/**/*.js",
5152
"packages/host/babel-plugin.js",
5253
"packages/host/react-native.config.js",
@@ -68,6 +69,7 @@ export default tseslint.config(
6869
},
6970
{
7071
files: [
72+
"**/metro.config.js",
7173
"packages/gyp-to-cmake/bin/*.js",
7274
"packages/host/bin/*.mjs",
7375
"packages/host/scripts/*.mjs",

package-lock.json

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"test": "npm test --workspace react-native-node-api --workspace cmake-rn --workspace gyp-to-cmake --workspace node-addon-examples",
2727
"bootstrap": "node --run build && npm run bootstrap --workspaces --if-present",
2828
"prerelease": "node --run build && npm run prerelease --workspaces --if-present",
29-
"release": "changeset publish"
29+
"release": "changeset publish",
30+
"init-macos-test-app": "node scripts/init-macos-test-app.ts"
3031
},
3132
"author": {
3233
"name": "Callstack",
@@ -64,6 +65,7 @@
6465
"globals": "^16.0.0",
6566
"prettier": "^3.6.2",
6667
"react-native": "0.81.4",
68+
"read-pkg": "^9.0.1",
6769
"tsx": "^4.20.5",
6870
"typescript": "^5.8.0",
6971
"typescript-eslint": "^8.38.0"

packages/host/react-native-node-api.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Pod::Spec.new do |s|
2929
s.license = package["license"]
3030
s.authors = package["author"]
3131

32-
s.platforms = { :ios => min_ios_version_supported }
3332
s.source = { :git => "https://github.com/callstackincubator/react-native-node-api.git", :tag => "#{s.version}" }
3433

3534
s.source_files = "apple/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}", "weak-node-api/include/*.h", "weak-node-api/*.hpp"

packages/host/scripts/patch-hermes.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44
raise "React Native Node-API cannot reliably patch JSI when React Native Core is prebuilt."
55
end
66

7+
def get_react_native_package
8+
if caller.any? { |frame| frame.include?("node_modules/react-native-macos/") }
9+
return "react-native-macos"
10+
elsif caller.any? { |frame| frame.include?("node_modules/react-native/") }
11+
return "react-native"
12+
else
13+
raise "Unable to determine React Native package from call stack."
14+
end
15+
end
16+
717
if ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'].nil?
8-
VENDORED_HERMES_DIR ||= `npx react-native-node-api vendor-hermes --silent '#{Pod::Config.instance.installation_root}'`.strip
18+
VENDORED_HERMES_DIR ||= `npx react-native-node-api vendor-hermes --react-native-package '#{get_react_native_package()}' --silent '#{Pod::Config.instance.installation_root}'`.strip
919
# Signal the patched Hermes to React Native
1020
ENV['BUILD_FROM_SOURCE'] = 'true'
1121
ENV['REACT_NATIVE_OVERRIDE_HERMES_DIR'] = VENDORED_HERMES_DIR

0 commit comments

Comments
 (0)