Skip to content

Commit cc13b02

Browse files
kelsetfacebook-github-bot
authored andcommitted
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](#34513 (comment)). This PR is taking kudo's proposed [patch here](reactwg/react-native-new-architecture#68 (reply in thread)) - props for the fix go to him. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [iOS] [Fixed] - Change hermes logic in build scripts for Apple to use the correct files Pull Request resolved: #34710 Test Plan: Tested by kudo in his work, and in my PR locally - [see here](#34513 (comment)). Reviewed By: cortinico Differential Revision: D39647057 Pulled By: cipolleschi fbshipit-source-id: 6520e248801a307ca2f8886a3853dd1ff4af193d
1 parent 5d2a400 commit cc13b02

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

sdks/hermes-engine/hermes-engine.podspec

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,25 @@ Pod::Spec.new do |spec|
6666
}
6767

6868
if source[:git] then
69+
ENV['REACT_NATIVE_PATH'] = react_native_path
70+
hermes_utils_path = "/sdks/hermes-engine/utils"
71+
6972
spec.prepare_command = <<-EOS
70-
BUILD_TYPE=#{build_type.to_s.capitalize}
73+
export BUILD_TYPE=#{build_type.to_s.capitalize}
74+
export RELEASE_VERSION="#{version}"
75+
export IOS_DEPLOYMENT_TARGET="#{spec.deployment_target('ios')}"
76+
export MAC_DEPLOYMENT_TARGET="#{spec.deployment_target('osx')}"
77+
export JSI_PATH="$REACT_NATIVE_PATH/ReactCommon/jsi"
7178
7279
# Set HERMES_OVERRIDE_HERMESC_PATH if pre-built HermesC is available
7380
#{File.exist?(import_hermesc_file) ? "export HERMES_OVERRIDE_HERMESC_PATH=#{import_hermesc_file}" : ""}
7481
#{File.exist?(import_hermesc_file) ? "echo \"Overriding HermesC path...\"" : ""}
7582
7683
# Build iOS framework
77-
./utils/build-ios-framework.sh
84+
$REACT_NATIVE_PATH#{hermes_utils_path}/build-ios-framework.sh
7885
7986
# Build Mac framework
80-
./utils/build-mac-framework.sh
87+
$REACT_NATIVE_PATH#{hermes_utils_path}/build-mac-framework.sh
8188
EOS
8289
end
8390
end

sdks/hermes-engine/utils/build-apple-framework.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@
77
NUM_CORES=$(sysctl -n hw.ncpu)
88
IMPORT_HERMESC_PATH=${HERMES_OVERRIDE_HERMESC_PATH:-$PWD/build_host_hermesc/ImportHermesc.cmake}
99
REACT_NATIVE_PATH=${REACT_NATIVE_PATH:-$PWD/../..}
10-
JSI_PATH="$REACT_NATIVE_PATH/ReactCommon/jsi"
10+
if [[ -z "$JSI_PATH" ]]; then
11+
JSI_PATH="$REACT_NATIVE_PATH/ReactCommon/jsi"
12+
fi
13+
14+
function use_env_var_or_ruby_prop {
15+
if [[ -n "$1" ]]; then
16+
echo "$1"
17+
else
18+
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').$2"
19+
fi
20+
}
1121

1222
function get_release_version {
13-
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').version"
23+
use_env_var_or_ruby_prop "${RELEASE_VERSION}" "version"
1424
}
1525

1626
function get_ios_deployment_target {
17-
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('ios')"
27+
use_env_var_or_ruby_prop "${IOS_DEPLOYMENT_TARGET}" "deployment_target('ios')"
1828
}
1929

2030
function get_mac_deployment_target {
21-
ruby -rcocoapods-core -rjson -e "puts Pod::Specification.from_file('hermes-engine.podspec').deployment_target('osx')"
31+
use_env_var_or_ruby_prop "${MAC_DEPLOYMENT_TARGET}" "deployment_target('osx')"
2232
}
2333

2434
# Build host hermes compiler for internal bytecode

sdks/hermes-engine/utils/build-ios-framework.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# LICENSE file in the root directory of this source tree.
66

77
# shellcheck source=xplat/js/react-native-github/sdks/hermes-engine/utils/build-apple-framework.sh
8-
. ./utils/build-apple-framework.sh
8+
CURR_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
9+
. "${CURR_SCRIPT_DIR}/build-apple-framework.sh"
910

1011
if [ ! -d destroot/Library/Frameworks/universal/hermes.xcframework ]; then
1112
ios_deployment_target=$(get_ios_deployment_target)

sdks/hermes-engine/utils/build-mac-framework.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# LICENSE file in the root directory of this source tree.
66

77
# shellcheck source=xplat/js/react-native-github/sdks/hermes-engine/utils/build-apple-framework.sh
8-
. ./utils/build-apple-framework.sh
8+
CURR_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
9+
. "${CURR_SCRIPT_DIR}/build-apple-framework.sh"
910

1011
if [ ! -d destroot/Library/Frameworks/macosx/hermes.framework ]; then
1112
mac_deployment_target=$(get_mac_deployment_target)

0 commit comments

Comments
 (0)