Skip to content

Commit 7e2f7c5

Browse files
committed
fix(plugin-react-native): ship Expo config plugin to exclude x86_64 simulator slice
cpp.js xcframeworks are arm64-only for the iOS simulator, so a Release build (ONLY_ACTIVE_ARCH=NO builds every arch) fails with `ld: library not found`. `expo prebuild` regenerates ios/ from scratch, so the exclusion ships as an Expo config plugin loaded when "@cpp.js/plugin-react-native" is listed in the app config's plugins[] — it injects EXCLUDED_ARCHS[sdk=iphonesimulator*]=x86_64 into the generated Podfile for every Pod target and the app target. - @cpp.js/plugin-react-native: add app.plugin.cjs (.cjs because the package is type:module) and @expo/config-plugins as an optional peer dependency. - Expo sample: reference "@cpp.js/plugin-react-native" in app.json plugins and regenerate the native project. - Version bumps for release; refresh lockfiles. Verified: a fresh scaffold installs the published package, prebuild patches the Podfile, and `expo run:ios --configuration Release` builds, launches, and renders the cpp.js C++ demo on the simulator.
1 parent 45361d4 commit 7e2f7c5

10 files changed

Lines changed: 361 additions & 95 deletions

File tree

cppjs-core/cppjs-core-create-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-cpp.js",
3-
"version": "2.0.0-beta.19",
3+
"version": "2.0.0-beta.20",
44
"description": "Create Cpp.js Applications",
55
"homepage": "https://github.com/bugra9/cpp.js/tree/main/packages/cppjs-core-create-app#readme",
66
"repository": "https://github.com/bugra9/cpp.js.git",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Expo config plugin shipped by @cpp.js/plugin-react-native.
3+
*
4+
* cpp.js ships arm64-only iOS simulator slices for its xcframeworks
5+
* (react-native-cppjs, @cpp.js/sample-lib-prebuilt-matrix, the @cpp.js/package-*
6+
* family, ...). A Release build compiles every architecture
7+
* (ONLY_ACTIVE_ARCH=NO), so the simulator build otherwise tries x86_64 and fails
8+
* with `ld: library '...' not found` because there is no matching x86_64 slice.
9+
*
10+
* `expo prebuild` regenerates ios/ from scratch, so the exclusion can't live in
11+
* a committed Podfile/pbxproj — it must be injected at prebuild time. Add
12+
* "@cpp.js/plugin-react-native" to the `plugins` array of your app config and
13+
* this drops x86_64 from every Pod target and the app target.
14+
*
15+
* NOTE: .cjs because the package is `"type": "module"`; Expo resolves
16+
* app.plugin.{js,cjs,mjs,...} and a config plugin must be CommonJS-loadable.
17+
*/
18+
19+
const fs = require('node:fs');
20+
const path = require('node:path');
21+
const { withDangerousMod, createRunOncePlugin } = require('@expo/config-plugins');
22+
const { mergeContents } = require('@expo/config-plugins/build/utils/generateCode');
23+
24+
const pkg = require('./package.json');
25+
26+
const SETTING = 'EXCLUDED_ARCHS[sdk=iphonesimulator*]';
27+
28+
const POST_INSTALL_SNIPPET = [
29+
' installer.pods_project.targets.each do |target|',
30+
' target.build_configurations.each do |config|',
31+
` config.build_settings['${SETTING}'] = 'x86_64'`,
32+
' end',
33+
' end',
34+
' installer.aggregate_targets.each do |aggregate_target|',
35+
' aggregate_target.user_project.native_targets.each do |target|',
36+
' target.build_configurations.each do |config|',
37+
` config.build_settings['${SETTING}'] = 'x86_64'`,
38+
' end',
39+
' end',
40+
' aggregate_target.user_project.save',
41+
' end',
42+
].join('\n');
43+
44+
function withExcludeSimulatorArchs(config) {
45+
return withDangerousMod(config, ['ios', (cfg) => {
46+
const podfile = path.join(cfg.modRequest.platformProjectRoot, 'Podfile');
47+
const before = fs.readFileSync(podfile, 'utf8');
48+
const merged = mergeContents({
49+
tag: 'cppjs-exclude-simulator-x86_64',
50+
src: before,
51+
newSrc: POST_INSTALL_SNIPPET,
52+
anchor: /post_install do \|installer\|/,
53+
offset: 1,
54+
comment: '#',
55+
});
56+
if (merged.didMerge) {
57+
fs.writeFileSync(podfile, merged.contents);
58+
}
59+
return cfg;
60+
}]);
61+
}
62+
63+
module.exports = createRunOncePlugin(withExcludeSimulatorArchs, pkg.name, pkg.version);

cppjs-plugins/cppjs-plugin-react-native/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cpp.js/plugin-react-native",
3-
"version": "2.0.0-beta.18",
3+
"version": "2.0.0-beta.20",
44
"description": "Cpp.js React Native plugin: A tool for seamless C++ integration with React Native and Expo.",
55
"homepage": "https://github.com/bugra9/cpp.js/tree/main/packages/cppjs-plugin-react-native#readme",
66
"repository": "https://github.com/bugra9/cpp.js.git",
@@ -9,7 +9,13 @@
99
"type": "module",
1010
"peerDependencies": {
1111
"react-native": "*",
12-
"metro": "*"
12+
"metro": "*",
13+
"@expo/config-plugins": "*"
14+
},
15+
"peerDependenciesMeta": {
16+
"@expo/config-plugins": {
17+
"optional": true
18+
}
1319
},
1420
"dependencies": {
1521
"cpp.js": "workspace:^",

cppjs-samples/cppjs-sample-mobile-reactnative-expo/app.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
"expo-font",
4141
"expo-image",
4242
"expo-status-bar",
43-
"expo-web-browser"
43+
"expo-web-browser",
44+
"@cpp.js/plugin-react-native"
4445
],
4546
"experiments": {
4647
"typedRoutes": true,

cppjs-samples/cppjs-sample-mobile-reactnative-expo/ios/Podfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ target 'cppjssamplemobilereactnativeexpo' do
5656
)
5757

5858
post_install do |installer|
59+
# @generated begin cppjs-exclude-simulator-x86_64 - expo prebuild (DO NOT MODIFY) sync-d735b5d61eaecfd9b2744c042e68517e877b108e
60+
installer.pods_project.targets.each do |target|
61+
target.build_configurations.each do |config|
62+
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
63+
end
64+
end
65+
installer.aggregate_targets.each do |aggregate_target|
66+
aggregate_target.user_project.native_targets.each do |target|
67+
target.build_configurations.each do |config|
68+
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
69+
end
70+
end
71+
aggregate_target.user_project.save
72+
end
73+
# @generated end cppjs-exclude-simulator-x86_64
5974
react_native_post_install(
6075
installer,
6176
config[:reactNativePath],

cppjs-samples/cppjs-sample-mobile-reactnative-expo/ios/Podfile.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ PODS:
15181518
- ReactCommon/turbomodule/core
15191519
- ReactNativeDependencies
15201520
- Yoga
1521-
- react-native-cppjs (2.0.0-beta.18)
1521+
- react-native-cppjs (2.0.0-beta.20)
15221522
- react-native-cppjs-ios-helper (2.0.0-beta.15):
15231523
- hermes-engine
15241524
- RCTRequired
@@ -1541,7 +1541,7 @@ PODS:
15411541
- ReactCommon/turbomodule/core
15421542
- ReactNativeDependencies
15431543
- Yoga
1544-
- react-native-safe-area-context (5.7.0):
1544+
- react-native-safe-area-context (5.8.0):
15451545
- hermes-engine
15461546
- RCTRequired
15471547
- RCTTypeSafety
@@ -1553,8 +1553,8 @@ PODS:
15531553
- React-graphics
15541554
- React-ImageManager
15551555
- React-jsi
1556-
- react-native-safe-area-context/common (= 5.7.0)
1557-
- react-native-safe-area-context/fabric (= 5.7.0)
1556+
- react-native-safe-area-context/common (= 5.8.0)
1557+
- react-native-safe-area-context/fabric (= 5.8.0)
15581558
- React-NativeModulesApple
15591559
- React-RCTFabric
15601560
- React-renderercss
@@ -1565,7 +1565,7 @@ PODS:
15651565
- ReactCommon/turbomodule/core
15661566
- ReactNativeDependencies
15671567
- Yoga
1568-
- react-native-safe-area-context/common (5.7.0):
1568+
- react-native-safe-area-context/common (5.8.0):
15691569
- hermes-engine
15701570
- RCTRequired
15711571
- RCTTypeSafety
@@ -1587,7 +1587,7 @@ PODS:
15871587
- ReactCommon/turbomodule/core
15881588
- ReactNativeDependencies
15891589
- Yoga
1590-
- react-native-safe-area-context/fabric (5.7.0):
1590+
- react-native-safe-area-context/fabric (5.8.0):
15911591
- hermes-engine
15921592
- RCTRequired
15931593
- RCTTypeSafety
@@ -2637,9 +2637,9 @@ SPEC CHECKSUMS:
26372637
React-Mapbuffer: 1aa9126122d4247ffc24bf9d28d50ce923499a71
26382638
React-microtasksnativemodule: d86581169e9bb5bb6f5fc3c5052f890016c1bf21
26392639
React-mutationobservernativemodule: 9a0c4e866f1ef2a57acebc902ebacbdf469ae741
2640-
react-native-cppjs: ea92338c513ae54a2160fb6f6e05e31ae657c12e
2640+
react-native-cppjs: ca239e2ab537ca169d64da23e08e01373623c7d5
26412641
react-native-cppjs-ios-helper: 86581df2af205f62fb5d6f0637ddb9ad3409003b
2642-
react-native-safe-area-context: a2325922b8594ddd27f98fb13437aec126be2502
2642+
react-native-safe-area-context: c1eb308f4b36372a4de4b3bdaa8ed695ec3dd461
26432643
React-NativeModulesApple: cc6ec4767844d610e92cc358bd3ea34937438d56
26442644
React-networking: a8ce15641ed7775d5b54a9d0d32defc367c2216e
26452645
React-oscompat: 64a0c7ef5441855dc6e2a6afe8ba8f92aa05075e
@@ -2685,6 +2685,6 @@ SPEC CHECKSUMS:
26852685
SDWebImageWebPCoder: e38c0a70396191361d60c092933e22c20d5b1380
26862686
Yoga: 36fee8f1fca3f54a28c3d7f80e69f66d73d3af96
26872687

2688-
PODFILE CHECKSUM: 5d9f323d20765a6cb5168ee04b23c5a0b3f900b6
2688+
PODFILE CHECKSUM: a27ee40b07e4c82d816e8cc0da716c92fd4143d1
26892689

26902690
COCOAPODS: 1.16.2

0 commit comments

Comments
 (0)