Skip to content

Commit 38bd186

Browse files
authored
feat: add react-native 0.74 support (#202)
# Why add react native 0.74 and expo sdk 51 support # How - [v8runtime] add stub `setExternalMemoryPressure()` - [android] fix build error on 0.74 - [ios] update config-plugin to support 0.74 from RCTRootViewFactory - [ci] update test for react-native 0.74 and expo sdk 51
1 parent ca4e3fc commit 38bd186

File tree

12 files changed

+289
-25
lines changed

12 files changed

+289
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Copyright (c) 650 Industries.
3+
#
4+
5+
name: 'Cleanup GitHub Linux Runner Disk Space'
6+
description: 'Cleanup unused preinstalled packages on the GitHub Ubuntu runners'
7+
8+
runs:
9+
using: 'composite'
10+
steps:
11+
- name: '🧹 Cleanup preinstalled packages'
12+
shell: bash
13+
run: |
14+
echo 'Disk space before cleanup'
15+
df -aH
16+
sudo apt-get remove -y --purge '^mysql-.*' '^mongodb-.*' '^mssql-.*' '^postgresql-.*' '^aspnetcore-*' '^dotnet-.*' '^php.*-.*' 'mono-complete' '^llvm-.*' 'powershell' 'google-chrome-*' 'microsoft-edge-*' 'firefox' 'nginx' 'apache2'
17+
sudo apt-get autoremove -y
18+
sudo rm -rf /usr/share/dotnet
19+
echo 'Showing Android SDKs'
20+
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --list
21+
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --uninstall 'ndk;24.0.8215888' 'ndk;25.2.9519653' 'ndk;26.2.11394342'
22+
echo 'Removing all Docker images'
23+
docker rmi -f $(docker images -aq)
24+
echo 'Disk space after cleanup'
25+
df -aH

.github/workflows/android.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
runs-on: ubuntu-latest
2323
strategy:
2424
matrix:
25-
rn-version: ['0.73']
25+
rn-version: ['0.74', '0.73']
2626
v8-android-variant:
2727
[v8-android-jit, v8-android-jit-nointl, v8-android, v8-android-nointl]
2828
# include:
@@ -32,17 +32,20 @@ jobs:
3232
# v8-android-variant: v8-android-jit
3333

3434
steps:
35-
- uses: actions/checkout@v2
35+
- uses: actions/checkout@v4
3636
- uses: oven-sh/setup-bun@v1
3737

38+
- name: 🧹 Cleanup GitHub Linux runner disk space
39+
uses: ./.github/actions/cleanup-linux-disk-space
40+
3841
- name: Use JDK 17
39-
uses: actions/setup-java@v2
42+
uses: actions/setup-java@v4
4043
with:
4144
distribution: 'temurin'
4245
java-version: '17'
4346

4447
- name: Restore yarn caches
45-
uses: actions/cache@v2
48+
uses: actions/cache@v4
4649
with:
4750
path: node_modules
4851
key: ${{ runner.os }}-workspace-modules-${{ hashFiles('yarn.lock') }}
@@ -60,7 +63,7 @@ jobs:
6063
- name: Run tests
6164
uses: reactivecircus/android-emulator-runner@v2
6265
with:
63-
api-level: 33
66+
api-level: 34
6467
arch: x86_64
6568
target: google_apis
6669
script: |
@@ -72,7 +75,7 @@ jobs:
7275
7376
- name: Upload failed artifacts
7477
if: failure()
75-
uses: actions/upload-artifact@v3
78+
uses: actions/upload-artifact@v4
7679
with:
7780
name: artifacts-${{ matrix.rn-version }}-${{ matrix.v8-android-variant }}
7881
path: |

.github/workflows/expo-android.yml

+9-6
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,20 @@ jobs:
2121
e2e-test:
2222
runs-on: ubuntu-latest
2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v4
2525
- uses: oven-sh/setup-bun@v1
2626

27+
- name: 🧹 Cleanup GitHub Linux runner disk space
28+
uses: ./.github/actions/cleanup-linux-disk-space
29+
2730
- name: Use JDK 17
28-
uses: actions/setup-java@v2
31+
uses: actions/setup-java@v4
2932
with:
3033
distribution: 'temurin'
3134
java-version: '17'
3235

3336
- name: Restore yarn caches
34-
uses: actions/cache@v2
37+
uses: actions/cache@v4
3538
with:
3639
path: node_modules
3740
key: ${{ runner.os }}-workspace-modules-${{ hashFiles('yarn.lock') }}
@@ -41,7 +44,7 @@ jobs:
4144

4245
- name: Generate TestApp
4346
run: |
44-
yarn create expo-app -t blank@@sdk-50 TestApp
47+
yarn create expo-app -t blank@@sdk-51 TestApp
4548
cd TestApp
4649
yarn add v8-android-jit
4750
yarn add file:../react-native-v8
@@ -66,7 +69,7 @@ jobs:
6669
- name: Run tests
6770
uses: reactivecircus/android-emulator-runner@v2
6871
with:
69-
api-level: 33
72+
api-level: 34
7073
arch: x86_64
7174
target: google_apis
7275
working-directory: ../TestApp/android
@@ -85,7 +88,7 @@ jobs:
8588
8689
- name: Upload failed artifacts
8790
if: failure()
88-
uses: actions/upload-artifact@v3
91+
uses: actions/upload-artifact@v4
8992
with:
9093
name: artifacts
9194
path: |

.github/workflows/expo-ios.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ jobs:
2222
runs-on: macos-latest
2323

2424
steps:
25-
- uses: actions/checkout@v2
25+
- uses: actions/checkout@v4
2626
- uses: oven-sh/setup-bun@v1
2727

28-
- name: 🔨 Switch to Xcode 14.3.1
29-
run: sudo xcode-select --switch /Applications/Xcode_14.3.1.app
28+
- name: 🔨 Switch to Xcode 15.4
29+
run: sudo xcode-select --switch /Applications/Xcode_15.4.app
3030

3131
- name: Restore yarn caches
32-
uses: actions/cache@v2
32+
uses: actions/cache@v4
3333
with:
3434
path: node_modules
3535
key: ${{ runner.os }}-workspace-modules-${{ hashFiles('yarn.lock') }}
@@ -39,7 +39,7 @@ jobs:
3939

4040
- name: Generate TestApp
4141
run: |
42-
yarn create expo-app -t blank@@sdk-50 TestApp
42+
yarn create expo-app -t blank@@sdk-51 TestApp
4343
cd TestApp
4444
yarn add v8-ios
4545
yarn add file:../react-native-v8
@@ -57,7 +57,7 @@ jobs:
5757
- name: Run TestApp
5858
working-directory: ../TestApp/ios
5959
run: |
60-
SIMUDID=$(xcrun simctl list devices available -j | jq -r '.devices."com.apple.CoreSimulator.SimRuntime.iOS-16-4"[] | select(.name=="iPhone 14 Pro") | .udid')
60+
SIMUDID=$(xcrun simctl list devices available -j | jq -r '.devices."com.apple.CoreSimulator.SimRuntime.iOS-17-5"[] | select(.name=="iPhone 15 Pro") | .udid')
6161
echo "Using simulator udid[${SIMUDID}]"
6262
xcrun simctl boot ${SIMUDID}
6363
xcrun simctl install booted ./build/Build/Products/Release-iphonesimulator/TestApp.app
@@ -75,7 +75,7 @@ jobs:
7575
7676
- name: Upload failed artifacts
7777
if: failure()
78-
uses: actions/upload-artifact@v3
78+
uses: actions/upload-artifact@v4
7979
with:
8080
name: artifacts
8181
path: |

android/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ add_library(
9292
target_include_directories(
9393
reactnative_internal_static
9494
PRIVATE
95+
"${REACT_NATIVE_DIR}/ReactCommon"
9596
"${REACT_NATIVE_DIR}/ReactCommon/jsiexecutor"
9697
"${REACT_NATIVE_DIR}/ReactCommon/reactperflogger"
98+
"${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor"
9799
)
98100

99101
target_link_libraries(

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"src/"
4141
],
4242
"devDependencies": {
43+
"@types/semver": "^7.5.8",
4344
"clang-format": "^1.8.0",
4445
"expo": "^48.0.0",
4546
"expo-module-scripts": "^3.0.7"
@@ -51,5 +52,8 @@
5152
"expo": {
5253
"optional": true
5354
}
55+
},
56+
"dependencies": {
57+
"semver": "^7.6.2"
5458
}
5559
}

plugin/build/withV8ExpoAdapter.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export declare function updateAndroidAppGradle(contents: string): string;
1313
* Updates **AppDelegate.mm**
1414
*/
1515
export declare function updateIosAppDelegate(contents: string): string;
16+
export declare function updateIosAppDelegate50(contents: string): string;

plugin/build/withV8ExpoAdapter.js

+105-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
25
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.updateIosAppDelegate = exports.updateAndroidAppGradle = void 0;
6+
exports.updateIosAppDelegate50 = exports.updateIosAppDelegate = exports.updateAndroidAppGradle = void 0;
7+
const semver_1 = __importDefault(require("semver"));
48
const config_plugins_1 = require("expo/config-plugins");
59
const generateCode_1 = require("./generateCode");
610
const withV8ExpoAdapter = (config, opts) => {
@@ -43,7 +47,12 @@ const withIosAppDelegate = (config) => {
4347
throw new Error('Must setup `expo.jsEngine` as `jsc` in app.json.');
4448
}
4549
if (config.modResults.language === 'objcpp') {
46-
config.modResults.contents = updateIosAppDelegate(config.modResults.contents);
50+
if (config.sdkVersion && semver_1.default.lt(config.sdkVersion, '51.0.0')) {
51+
config.modResults.contents = updateIosAppDelegate50(config.modResults.contents);
52+
}
53+
else {
54+
config.modResults.contents = updateIosAppDelegate(config.modResults.contents);
55+
}
4756
}
4857
else {
4958
throw new Error('Cannot update AppDelegate file for react-native-v8 because the file is not objcpp');
@@ -119,6 +128,99 @@ function updateIosAppDelegate(contents) {
119128
#define FOLLY_CFG_NO_COROUTINES 1
120129
#endif
121130
131+
#import <memory>
132+
#import <objc/runtime.h>
133+
#import <React/RCTCxxBridgeDelegate.h>
134+
#import <React/RCTJSIExecutorRuntimeInstaller.h>
135+
#import <React/RCTSurfacePresenterBridgeAdapter.h>
136+
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
137+
#import <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h>
138+
#import <RNV8/V8ExecutorFactory.h>
139+
`;
140+
let mergeResults;
141+
mergeResults = (0, generateCode_1.mergeContents)({
142+
tag: `${mergeTagPrefix}:imports`,
143+
src: contents,
144+
newSrc: imports,
145+
anchor: /^#import "AppDelegate\.h"/m,
146+
offset: 1,
147+
comment: '//',
148+
});
149+
didMerge || (didMerge = mergeResults.didMerge);
150+
didClear || mergeResults.didClear;
151+
const swizzleJsExecutorFactory = `\
152+
method_exchangeImplementations(
153+
class_getInstanceMethod(RCTRootViewFactory.class, @selector(jsExecutorFactoryForBridge:)),
154+
class_getInstanceMethod(self.class, @selector(jsExecutorFactoryForBridge:)));
155+
`;
156+
mergeResults = (0, generateCode_1.mergeContents)({
157+
tag: `${mergeTagPrefix}:swizzleJsExecutorFactory`,
158+
src: mergeResults.contents,
159+
newSrc: swizzleJsExecutorFactory,
160+
anchor: /^\s*return \[super application:application didFinishLaunchingWithOptions:launchOptions]/m,
161+
offset: 0,
162+
comment: '//',
163+
});
164+
didMerge || (didMerge = mergeResults.didMerge);
165+
didClear || mergeResults.didClear;
166+
const jsExecutorFactoryForBridge = `
167+
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
168+
{
169+
RCTAssert(!RCTIsNewArchEnabled(), @"react-native-v8 does not support new architecture yet.");
170+
auto runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
171+
return std::make_unique<rnv8::V8ExecutorFactory>(
172+
facebook::react::RCTJSIExecutorRuntimeInstaller([bridge, runtimeScheduler = std::move(runtimeScheduler)](facebook::jsi::Runtime &runtime) {
173+
if (!bridge) {
174+
return;
175+
}
176+
if (runtimeScheduler) {
177+
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
178+
}
179+
}));
180+
}
181+
`;
182+
mergeResults = (0, generateCode_1.mergeContents)({
183+
tag: `${mergeTagPrefix}:jsExecutorFactoryForBridge`,
184+
src: mergeResults.contents,
185+
newSrc: jsExecutorFactoryForBridge,
186+
anchor: /^@end$/gm,
187+
findLastAnchor: true,
188+
offset: 0,
189+
comment: '//',
190+
});
191+
didMerge || (didMerge = mergeResults.didMerge);
192+
didClear || mergeResults.didClear;
193+
if (didMerge || didClear) {
194+
return mergeResults.contents;
195+
}
196+
return contents;
197+
}
198+
exports.updateIosAppDelegate = updateIosAppDelegate;
199+
function updateIosAppDelegate50(contents) {
200+
const mergeTagPrefix = 'react-native-v8';
201+
let didMerge = false;
202+
let didClear = false;
203+
const imports = `\
204+
#ifndef FOLLY_NO_CONFIG
205+
#define FOLLY_NO_CONFIG 1
206+
#endif
207+
208+
#ifndef FOLLY_MOBILE
209+
#define FOLLY_MOBILE 1
210+
#endif
211+
212+
#ifndef FOLLY_USE_LIBCPP
213+
#define FOLLY_USE_LIBCPP 1
214+
#endif
215+
216+
#ifndef FOLLY_HAVE_PTHREAD
217+
#define FOLLY_HAVE_PTHREAD 1
218+
#endif
219+
220+
#ifndef FOLLY_CFG_NO_COROUTINES
221+
#define FOLLY_CFG_NO_COROUTINES 1
222+
#endif
223+
122224
#import <memory>
123225
#import <React/RCTCxxBridgeDelegate.h>
124226
#import <React/RCTJSIExecutorRuntimeInstaller.h>
@@ -209,4 +311,4 @@ function updateIosAppDelegate(contents) {
209311
}
210312
return contents;
211313
}
212-
exports.updateIosAppDelegate = updateIosAppDelegate;
314+
exports.updateIosAppDelegate50 = updateIosAppDelegate50;

0 commit comments

Comments
 (0)