From cc13b0273fc533a38c06fddd5e6b74f77319afa6 Mon Sep 17 00:00:00 2001 From: Lorenzo Sciandra Date: Mon, 26 Sep 2022 02:02:32 -0700 Subject: [PATCH] fix(hermes): change logic in build scripts for Apple to use the right version (#34710) Summary: Within the `hermes-engine.podspec` contained in the RN repo (at `react-native/main/sdks/hermes-engine/`), there's a bit of logic that triggers `./utils/build-ios-framework.sh` and `./utils/build-mac-framework.sh` . The issue is that we all thought that that `./utils/build-ios-framework.sh` would invoke the React native version of the scripts (since the podspec file lives right next to the `utils` folder) but, in reality, it doesn't. It just so happens that the Hermes repo has a root level `utils` folder which is (you guessed it) where the Hermes variation of those build scripts live. So, when running the pod install command in a react-native project (build from source), it will go and download the hermes source code (since the `source[:git]` gets set) but then it will use the **hermes** variation of the `build-*.sh` scripts. [Read more here](https://github.com/facebook/react-native/pull/34513#issuecomment-1248286691). This PR is taking kudo's proposed [patch here](https://github.com/reactwg/react-native-new-architecture/discussions/68#discussioncomment-3654191) - props for the fix go to him. ## Changelog [iOS] [Fixed] - Change hermes logic in build scripts for Apple to use the correct files Pull Request resolved: https://github.com/facebook/react-native/pull/34710 Test Plan: Tested by kudo in his work, and in my PR locally - [see here](https://github.com/facebook/react-native/pull/34513#issuecomment-1249431302). Reviewed By: cortinico Differential Revision: D39647057 Pulled By: cipolleschi fbshipit-source-id: 6520e248801a307ca2f8886a3853dd1ff4af193d --- sdks/hermes-engine/hermes-engine.podspec | 13 ++++++++++--- .../utils/build-apple-framework.sh | 18 ++++++++++++++---- .../hermes-engine/utils/build-ios-framework.sh | 3 ++- .../hermes-engine/utils/build-mac-framework.sh | 3 ++- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/sdks/hermes-engine/hermes-engine.podspec b/sdks/hermes-engine/hermes-engine.podspec index 0eab5335d24f45..a141848e7a0d0e 100644 --- a/sdks/hermes-engine/hermes-engine.podspec +++ b/sdks/hermes-engine/hermes-engine.podspec @@ -66,18 +66,25 @@ Pod::Spec.new do |spec| } if source[:git] then + ENV['REACT_NATIVE_PATH'] = react_native_path + hermes_utils_path = "/sdks/hermes-engine/utils" + spec.prepare_command = <<-EOS - BUILD_TYPE=#{build_type.to_s.capitalize} + export BUILD_TYPE=#{build_type.to_s.capitalize} + export RELEASE_VERSION="#{version}" + export IOS_DEPLOYMENT_TARGET="#{spec.deployment_target('ios')}" + export MAC_DEPLOYMENT_TARGET="#{spec.deployment_target('osx')}" + export JSI_PATH="$REACT_NATIVE_PATH/ReactCommon/jsi" # Set HERMES_OVERRIDE_HERMESC_PATH if pre-built HermesC is available #{File.exist?(import_hermesc_file) ? "export HERMES_OVERRIDE_HERMESC_PATH=#{import_hermesc_file}" : ""} #{File.exist?(import_hermesc_file) ? "echo \"Overriding HermesC path...\"" : ""} # Build iOS framework - ./utils/build-ios-framework.sh + $REACT_NATIVE_PATH#{hermes_utils_path}/build-ios-framework.sh # Build Mac framework - ./utils/build-mac-framework.sh + $REACT_NATIVE_PATH#{hermes_utils_path}/build-mac-framework.sh EOS end end diff --git a/sdks/hermes-engine/utils/build-apple-framework.sh b/sdks/hermes-engine/utils/build-apple-framework.sh index 646c73b5986b1b..a48b565c3cb415 100755 --- a/sdks/hermes-engine/utils/build-apple-framework.sh +++ b/sdks/hermes-engine/utils/build-apple-framework.sh @@ -7,18 +7,28 @@ NUM_CORES=$(sysctl -n hw.ncpu) IMPORT_HERMESC_PATH=${HERMES_OVERRIDE_HERMESC_PATH:-$PWD/build_host_hermesc/ImportHermesc.cmake} REACT_NATIVE_PATH=${REACT_NATIVE_PATH:-$PWD/../..} -JSI_PATH="$REACT_NATIVE_PATH/ReactCommon/jsi" +if [[ -z "$JSI_PATH" ]]; then + JSI_PATH="$REACT_NATIVE_PATH/ReactCommon/jsi" +fi + +function use_env_var_or_ruby_prop { + if [[ -n "$1" ]]; then + echo "$1" + else + ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').$2" + fi +} function get_release_version { - ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').version" + use_env_var_or_ruby_prop "${RELEASE_VERSION}" "version" } function get_ios_deployment_target { - ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('ios')" + use_env_var_or_ruby_prop "${IOS_DEPLOYMENT_TARGET}" "deployment_target('ios')" } function get_mac_deployment_target { - ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('osx')" + use_env_var_or_ruby_prop "${MAC_DEPLOYMENT_TARGET}" "deployment_target('osx')" } # Build host hermes compiler for internal bytecode diff --git a/sdks/hermes-engine/utils/build-ios-framework.sh b/sdks/hermes-engine/utils/build-ios-framework.sh index 771f39f79779d2..6b3b8fe2f8cd53 100755 --- a/sdks/hermes-engine/utils/build-ios-framework.sh +++ b/sdks/hermes-engine/utils/build-ios-framework.sh @@ -5,7 +5,8 @@ # LICENSE file in the root directory of this source tree. # shellcheck source=xplat/js/react-native-github/sdks/hermes-engine/utils/build-apple-framework.sh -. ./utils/build-apple-framework.sh +CURR_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" +. "${CURR_SCRIPT_DIR}/build-apple-framework.sh" if [ ! -d destroot/Library/Frameworks/universal/hermes.xcframework ]; then ios_deployment_target=$(get_ios_deployment_target) diff --git a/sdks/hermes-engine/utils/build-mac-framework.sh b/sdks/hermes-engine/utils/build-mac-framework.sh index e1f9abf81a4a41..0492ad28f22eea 100755 --- a/sdks/hermes-engine/utils/build-mac-framework.sh +++ b/sdks/hermes-engine/utils/build-mac-framework.sh @@ -5,7 +5,8 @@ # LICENSE file in the root directory of this source tree. # shellcheck source=xplat/js/react-native-github/sdks/hermes-engine/utils/build-apple-framework.sh -. ./utils/build-apple-framework.sh +CURR_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" +. "${CURR_SCRIPT_DIR}/build-apple-framework.sh" if [ ! -d destroot/Library/Frameworks/macosx/hermes.framework ]; then mac_deployment_target=$(get_mac_deployment_target)