From 99704800a13136510562f197bcb54d603a7c35a5 Mon Sep 17 00:00:00 2001 From: legobt <6wbvkn0j@anonaddy.me> Date: Mon, 20 May 2024 06:39:26 -0700 Subject: [PATCH] chore: Increase iOS script portability (#44417) 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: https://github.com/facebook/react-native/pull/44417 Reviewed By: NickGerleman Differential Revision: D57055928 Pulled By: cipolleschi fbshipit-source-id: 1c49f70c52b4667abf0a215cbee52ee6aa6dd052 --- packages/react-native/scripts/ios-configure-glog.sh | 11 +++++++++-- packages/react-native/scripts/react_native_pods.rb | 4 +++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/react-native/scripts/ios-configure-glog.sh b/packages/react-native/scripts/ios-configure-glog.sh index f13c61b40e2..02a875d31e4 100755 --- a/packages/react-native/scripts/ios-configure-glog.sh +++ b/packages/react-native/scripts/ios-configure-glog.sh @@ -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 diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index 20978c7ea85..77aca67f240 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -288,7 +288,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)