Skip to content

Commit 8a5b2d6

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Add ld_classic flag to Hermes when building for Xcode 15 (#39516)
Summary: Pull Request resolved: #39516 With Xcode15, Apple rewrote the C++ linker. This is a breaking change that does not work with weak symbols. As a workaround, apple is suggesting to add `-ld_classic` to the linker in order to readd support for weak symbols. The flag does not exists for Xcode 14.3 or lower, so we need to add it conditionally. With this change, we introduce a couple of checks in the Hermes build logic: 1. Detect the version of Xcode that is used 2. Add the new flag to `HERMES_EXTRA_LINKER_FLAGS` if Xcode version is 15. ## Changelog: [Internal] - Make hermes build properly with Xcode 15 Reviewed By: cortinico, dmytrorykun Differential Revision: D49368675 fbshipit-source-id: 62d8ed81855c426f56ed94b6a2d6da2eb882b355
1 parent 47de1f6 commit 8a5b2d6

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/react-native/sdks/hermes-engine/utils/build-apple-framework.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function build_host_hermesc {
5252

5353
# Utility function to configure an Apple framework
5454
function configure_apple_framework {
55-
local enable_debugger cmake_build_type
55+
local enable_debugger cmake_build_type xcode_15_flags xcode_major_version
5656

5757
if [[ $BUILD_TYPE == "Debug" ]]; then
5858
enable_debugger="true"
@@ -67,8 +67,15 @@ function configure_apple_framework {
6767
cmake_build_type="MinSizeRel"
6868
fi
6969

70+
xcode_15_flags=""
71+
xcode_major_version=$(xcodebuild -version | grep -oE '[0-9]*' | head -n 1)
72+
if [[ $xcode_major_version -ge 15 ]]; then
73+
xcode_15_flags="LINKER:-ld_classic"
74+
fi
75+
7076
pushd "$HERMES_PATH" > /dev/null || exit 1
7177
cmake -S . -B "build_$1" \
78+
-DHERMES_EXTRA_LINKER_FLAGS="$xcode_15_flags" \
7279
-DHERMES_APPLE_TARGET_PLATFORM:STRING="$1" \
7380
-DCMAKE_OSX_ARCHITECTURES:STRING="$2" \
7481
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="$3" \

packages/react-native/sdks/hermes-engine/utils/build-hermes-xcode.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,21 @@ if [ -z "$deployment_target" ]; then
2929
deployment_target=${MACOSX_DEPLOYMENT_TARGET}
3030
fi
3131

32+
xcode_15_flags=""
33+
xcode_major_version=$(xcodebuild -version | grep -oE '[0-9]*' | head -n 1)
34+
if [[ $xcode_major_version -ge 15 ]]; then
35+
echo "########### Using LINKER:-ld_classic ###########"
36+
xcode_15_flags="LINKER:-ld_classic"
37+
fi
38+
3239
architectures=$( echo "$ARCHS" | tr " " ";" )
3340

3441
echo "Configure Apple framework"
3542

3643
"$CMAKE_BINARY" \
3744
-S "${PODS_ROOT}/hermes-engine" \
3845
-B "${PODS_ROOT}/hermes-engine/build/${PLATFORM_NAME}" \
46+
-DHERMES_EXTRA_LINKER_FLAGS="$xcode_15_flags" \
3947
-DHERMES_APPLE_TARGET_PLATFORM:STRING="$PLATFORM_NAME" \
4048
-DCMAKE_OSX_ARCHITECTURES:STRING="$architectures" \
4149
-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING="$deployment_target" \

0 commit comments

Comments
 (0)