Skip to content

Commit

Permalink
Build hermesc in Xcode run script phase
Browse files Browse the repository at this point in the history
Summary:
Build hermesc in Xcode run script phase, so it ends up inside `Pods/hermes-engine/buld_host_hermesc`. All the the housekeeping is now done by CocoaPods and Xcode, and we can get rid of all the setup/cleanup code.

Changelog:
[iOS][Changed] - Build hermesc in Xcode run script phase.

Reviewed By: cipolleschi

Differential Revision: D41521987

fbshipit-source-id: 336854fa23582255cba6d161acf2cc791cac9d00
  • Loading branch information
dmytrorykun authored and facebook-github-bot committed Nov 24, 2022
1 parent 09843a0 commit a5c7711
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ package-lock.json
/sdks/download
/sdks/hermes
/sdks/hermesc
/sdks/hermes-engine/build_host_hermesc

# Visual studio
.vscode
Expand Down
10 changes: 5 additions & 5 deletions packages/rn-tester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ SPEC CHECKSUMS:
FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
hermes-engine: d18f5a58d912c767ed56b58821bddd685d766712
hermes-engine: e49758848596771dbb97c8f1b65e9d1ac353af69
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
Expand All @@ -965,14 +965,14 @@ SPEC CHECKSUMS:
React-Codegen: 4f1e911c128928e425e11698ad7859dfd0f92e20
React-Core: 719bec4b41c93b1affb1e2c3a43956ec482ecb9f
React-CoreModules: feaa45c54c58e1420981f6dd544c8b3d01200caa
React-cxxreact: c5f93e7a35f3545489d8e1f89beb9d2d56acfde5
React-cxxreact: 97903bdac0fb53409663fd312e2183ae1dd730e5
React-Fabric: 8a854fd89c932ab073f67036bb45d1787d0d31a4
React-graphics: cb8a85648695c60f33a00d732b985f734d1470d8
React-hermes: 299c7f56d32e8953480fd8e7fba2a7968a534b3f
React-hermes: af82687697f03ebb78aadd09dbc027df55fd87f8
React-jsi: d40e13b7f545f9af2af780f153f5321018b5e2f8
React-jsidynamic: 8aa406dfc1eff081f3443e55a28b51d11616a3bf
React-jsiexecutor: 04a945f040cc085d79655359ec29e5f501fb6e01
React-jsinspector: a56861590ddfcb5cb544877ade3e007a32ff9616
React-jsiexecutor: c402e7aeef68fab08a5f82adfea1f6874bf1b89b
React-jsinspector: 9b56a373a6797114e1d89a7dffa98ee98af67a8f
React-logger: 07c9b44040a6f948b8e2033207b23cb623f0b9b4
React-perflogger: b4b9fb2ddd856b78003708ab3cf66ce03e6bc7c4
React-RCTActionSheet: 1b1501ef80928be10702cd0ce09120358094cd82
Expand Down
4 changes: 0 additions & 4 deletions scripts/cocoapods/jsengine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ def remove_copy_hermes_framework_script_phase(installer, react_native_path)
project.save()
end

def remove_hermesc_build_dir(react_native_path)
%x(rm -rf #{react_native_path}/sdks/hermes-engine/build_host_hermesc)
end

def is_building_hermes_from_source(react_native_version)
is_nightly = react_native_version.start_with?('0.0.0-')
has_tarball = ENV['HERMES_ENGINE_TARBALL_PATH'] != nil
Expand Down
1 change: 0 additions & 1 deletion scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re
add_copy_hermes_framework_script_phase(installer, react_native_path)
else
remove_copy_hermes_framework_script_phase(installer, react_native_path)
remove_hermesc_build_dir(react_native_path)
end

ReactNativePodsUtils.exclude_i386_architecture_while_using_hermes(installer)
Expand Down
22 changes: 13 additions & 9 deletions sdks/hermes-engine/hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,10 @@ Pod::Spec.new do |spec|
ss.header_dir = 'hermes/Public'
end

hermesc_path = ""
hermesc_path = "${PODS_ROOT}/hermes-engine/build_host_hermesc"

if ENV.has_key?('HERMES_OVERRIDE_HERMESC_PATH') && File.exist?(ENV['HERMES_OVERRIDE_HERMESC_PATH']) then
hermesc_path = ENV['HERMES_OVERRIDE_HERMESC_PATH']
else
# Keep hermesc_path synchronized with .gitignore entry.
ENV['REACT_NATIVE_PATH'] = react_native_path
hermesc_path = "${REACT_NATIVE_PATH}/sdks/hermes-engine/build_host_hermesc"
# NOTE: Prepare command is not run if the pod is not downloaded.
spec.prepare_command = ". #{react_native_path}/sdks/hermes-engine/utils/build-hermesc-xcode.sh #{hermesc_path}"
end

spec.user_target_xcconfig = {
Expand All @@ -125,12 +119,22 @@ Pod::Spec.new do |spec|
'HERMES_CLI_PATH' => "#{hermesc_path}/bin/hermesc"
}

CMAKE_BINARY = %x(command -v cmake | tr -d '\n')
# NOTE: Script phases are sorted alphabetically inside Xcode project
spec.script_phases = [
{
:name => 'Build Hermes',
:name => '[RN] [1] Build Hermesc',
:script => <<-EOS
. ${PODS_ROOT}/../.xcode.env
export CMAKE_BINARY=${CMAKE_BINARY:-#{%x(command -v cmake | tr -d '\n')}}
export CMAKE_BINARY=${CMAKE_BINARY:-#{CMAKE_BINARY}}
. ${REACT_NATIVE_PATH}/sdks/hermes-engine/utils/build-hermesc-xcode.sh #{hermesc_path}
EOS
},
{
:name => '[RN] [2] Build Hermes',
:script => <<-EOS
. ${PODS_ROOT}/../.xcode.env
export CMAKE_BINARY=${CMAKE_BINARY:-#{CMAKE_BINARY}}
. ${REACT_NATIVE_PATH}/sdks/hermes-engine/utils/build-hermes-xcode.sh #{version} #{hermesc_path}/ImportHermesc.cmake
EOS
}
Expand Down
11 changes: 9 additions & 2 deletions sdks/hermes-engine/utils/build-hermesc-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ set -x

hermesc_dir_path="$1"

CMAKE_BINARY=${CMAKE_BINARY:-$(command -v cmake | tr -d '\n')}
# This script is supposed to be executed from Xcode "run script" phase.
# Xcode sets up its build environment based on the build target.
# Here we override relevant envvars to make sure that we build hermesc for macosx,
# even if Xcode build target is iphone, iponesimulator, etc.
MACOSX_DEPLOYMENT_TARGET=$(sw_vers -productVersion)
export MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET
SDKROOT=$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
export SDKROOT=$SDKROOT

if ! "$CMAKE_BINARY" -S . -B "$hermesc_dir_path"
if ! "$CMAKE_BINARY" -S "${PODS_ROOT}/hermes-engine" -B "$hermesc_dir_path"
then
echo "Failed to configure Hermesc cmake project."
exit 1
Expand Down

0 comments on commit a5c7711

Please sign in to comment.