Skip to content

Commit f18dc29

Browse files
chrfalchclaude
andcommitted
fix(ios): resolve hermesc for SwiftPM apps in react-native-xcode.sh
Release bundling derived hermesc exclusively from $PODS_ROOT/hermes-engine, which does not exist in a SwiftPM app — every SwiftPM consumer's Release build depended on HERMES_CLI_PATH being set by hand (or on the injector's baked path never going stale). When no Pods installation exists and the current HERMES_CLI_PATH does not point at a real file, resolve the hermes-compiler npm package through react-native's own dependency graph: react-native pins hermes-compiler, so the compiler's bytecode version always matches the prebuilt hermes VM artifacts. The missing-file condition also heals injector-baked paths gone stale after a package-store move. Strictly SwiftPM-scoped: in a CocoaPods build the hermes-engine pod owns both the VM and hermesc, and its hermes train may legitimately differ from the npm package — an ungated fallback compiled bundles the podded VM rejected at launch ("Wrong bytecode version"), which is why the no-Pods gate is load-bearing. Shell-only change with no unit harness; verified end-to-end by the local iOS build matrix: spm Release cells green on monorepo and fresh-consumer apps via the fallback, all CocoaPods cells green with the fallback provably inert. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent b0a5081 commit f18dc29

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

packages/react-native/scripts/react-native-xcode.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,26 @@ source "$REACT_NATIVE_DIR/scripts/node-binary.sh"
8080
HERMES_ENGINE_PATH="$PODS_ROOT/hermes-engine"
8181
[ -z "$HERMES_CLI_PATH" ] && HERMES_CLI_PATH="$HERMES_ENGINE_PATH/destroot/bin/hermesc"
8282

83+
# SwiftPM consumers have no Pods directory to provide hermesc. When there is
84+
# no Pods installation at all and the current HERMES_CLI_PATH does not exist
85+
# (unset, or an injector-baked path gone stale after a package-store move),
86+
# resolve the hermes-compiler npm package THROUGH react-native's own dependency
87+
# graph — react-native pins the hermes-compiler version, so the compiler's
88+
# bytecode version always matches the prebuilt hermes VM artifacts (a
89+
# mismatched pair crashes at launch with "Wrong bytecode version").
90+
# STRICTLY SwiftPM-scoped: in a CocoaPods build the hermes-engine pod owns both
91+
# the VM and hermesc, and its hermes train may legitimately differ from the npm
92+
# hermes-compiler — falling back there would compile bundles the podded VM
93+
# rejects.
94+
if [[ ( -z "$PODS_ROOT" || ! -d "$PODS_ROOT" ) && ! -f "$HERMES_CLI_PATH" ]]; then
95+
NODE_HERMESC=$(RN_DIR="$REACT_NATIVE_DIR" "$NODE_BINARY" --print \
96+
"require('path').join(require('path').dirname(require.resolve('hermes-compiler/package.json', {paths: [process.env.RN_DIR]})), 'hermesc', 'osx-bin', 'hermesc')" \
97+
2>/dev/null || true)
98+
if [[ -n "$NODE_HERMESC" && -f "$NODE_HERMESC" ]]; then
99+
HERMES_CLI_PATH="$NODE_HERMESC"
100+
fi
101+
fi
102+
83103
# If hermesc is not available and USE_HERMES is not set to false, show error.
84104
if [[ $USE_HERMES != false && -f "$HERMES_ENGINE_PATH" && ! -f "$HERMES_CLI_PATH" ]]; then
85105
echo "error: Hermes is enabled but the hermesc binary could not be found at ${HERMES_CLI_PATH}." \

0 commit comments

Comments
 (0)