Skip to content

Commit

Permalink
chore: Increase iOS script portability (#44417)
Browse files Browse the repository at this point in the history
Summary:
`pod install` and CocoaPods are actually not macOS specific.
Still, the pod lifecycle scripts of `react-native` depend on macOS-only utilities and will fail on Linux.

This is an attempt to make the scripts portable and make the pod install cleanly on Linux as well as macOS.

## Changelog:

    [INTERNAL] [FIXED] - Skip XCode patching when not run on macOS
    [INTERNAL] [FIXED] - Fall back to `which gcc`/`which g++` to identify C/C++ compiler when `xcrun` not available
    [INTERNAL] [FEAT] - Recognize CC and CXX env vars supplied to the script and prefer them over autodetection

Pull Request resolved: #44417

Reviewed By: NickGerleman

Differential Revision: D57055928

Pulled By: cipolleschi

fbshipit-source-id: 1c49f70c52b4667abf0a215cbee52ee6aa6dd052
  • Loading branch information
legobeat authored and cipolleschi committed Jun 4, 2024
1 parent 1f50fb7 commit 0f44ca6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/react-native/scripts/ios-configure-glog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ EOF
patch -p1 config.sub fix_glog_0.3.5_apple_silicon.patch
fi

export CC="$(xcrun -find -sdk $PLATFORM_NAME cc) -arch $CURRENT_ARCH -isysroot $(xcrun -sdk $PLATFORM_NAME --show-sdk-path)"
export CXX="$CC"
XCRUN="$(which xcrun)"
if [ -n "$XCRUN" ]; then
export CC="$(xcrun -find -sdk $PLATFORM_NAME cc) -arch $CURRENT_ARCH -isysroot $(xcrun -sdk $PLATFORM_NAME --show-sdk-path)"
export CXX="$CC"
else
export CC="$CC:-$(which gcc)"
export CXX="$CXX:-$(which g++ || true)"
fi
export CXX="$CXX:-$CC"

# Remove automake symlink if it exists
if [ -h "test-driver" ]; then
Expand Down
4 changes: 3 additions & 1 deletion packages/react-native/scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ def react_native_post_install(
ReactNativePodsUtils.set_use_hermes_build_setting(installer, hermes_enabled)
ReactNativePodsUtils.set_node_modules_user_settings(installer, react_native_path)
ReactNativePodsUtils.set_ccache_compiler_and_linker_build_settings(installer, react_native_path, ccache_enabled)
ReactNativePodsUtils.apply_xcode_15_patch(installer)
if Environment.new().ruby_platform().include?('darwin')
ReactNativePodsUtils.apply_xcode_15_patch(installer)
end
ReactNativePodsUtils.updateOSDeploymentTarget(installer)
ReactNativePodsUtils.set_dynamic_frameworks_flags(installer)
ReactNativePodsUtils.add_ndebug_flag_to_pods_in_release(installer)
Expand Down

0 comments on commit 0f44ca6

Please sign in to comment.