Skip to content

Commit 2344860

Browse files
dmytrorykunfacebook-github-bot
authored andcommitted
Prepare dummy hermes.xcframework before pod install
Summary: This diff adds prepare command to hermes-engine.podspec. That command creates dummy `universal/hermes.xcframework` and `maocosx/hermes.framework`. This allow us to utilise CocoaPods auto-linking, and remove manual linking/cleanup code. Also we now do not pollute user project with "Copy Hermes Framework" script phase. Which was quite bad on its own, and also caused annoying bugs on the CI. allow-large-files Changelog: [iOS][Changed] - Prepare dummy hermes.xcframework before pod install. Reviewed By: cipolleschi Differential Revision: D41533994 fbshipit-source-id: d7d098ba5e882ac2d036335c23d7cda447d75b8d
1 parent 65e0f79 commit 2344860

File tree

8 files changed

+46
-98
lines changed

8 files changed

+46
-98
lines changed

packages/rn-tester/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ SPEC CHECKSUMS:
932932
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
933933
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
934934
FBLazyVector: d68947eddece25638eb0f642d1b957c90388afd1
935-
FBReactNativeSpec: 0ded2dec004001d5888590a9c13df3e0c357a59f
935+
FBReactNativeSpec: c530d2df977f98d0d72ce4440c074cb73bff6289
936936
Flipper: 26fc4b7382499f1281eb8cb921e5c3ad6de91fe0
937937
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
938938
Flipper-DoubleConversion: 2dc99b02f658daf147069aad9dbd29d8feb06d30
@@ -944,7 +944,7 @@ SPEC CHECKSUMS:
944944
FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86
945945
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
946946
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
947-
hermes-engine: 62aa33fe860de4c9fde92adea000ce2e56c70370
947+
hermes-engine: b5817966bad2f5e14014102dbf97e26a17fe256e
948948
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
949949
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
950950
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
@@ -958,7 +958,7 @@ SPEC CHECKSUMS:
958958
React-cxxreact: 97903bdac0fb53409663fd312e2183ae1dd730e5
959959
React-Fabric: 4d08ce0b0f15513b2724ae1000c2aaedf73ebc32
960960
React-graphics: cb8a85648695c60f33a00d732b985f734d1470d8
961-
React-hermes: e35ea664b36773a2ce84c583febf1396080e59f7
961+
React-hermes: 73a4f97e9cd712476f9b93ae4838a576279feb78
962962
React-jsi: e4c75a1cf727c8761908ac2eeb1084e47ba88a26
963963
React-jsiexecutor: dcc8c2b89b6e0b5abb9bbbfb6df86adf44e3e877
964964
React-jsinspector: 9b56a373a6797114e1d89a7dffa98ee98af67a8f

scripts/cocoapods/__tests__/jsengine-test.rb

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -125,30 +125,4 @@ def test_setupHermes_installsPods_installsFabricSubspecWhenFabricEnabled
125125
assert_equal($podInvocation["libevent"][:version], "~> 2.1.12")
126126
end
127127

128-
# ================================= #
129-
# TEST - isBuildingHermesFromSource #
130-
# ================================= #
131-
def test_isBuildingHermesFromSource_whenTarballIsNilAndVersionIsNotNightly_returnTrue
132-
assert_true(is_building_hermes_from_source("1000.0.0", '../..'))
133-
end
134-
135-
def test_isBuildingHermesFromSource_whenTarballIsNilAndInReleaseBranch_returnTrue
136-
ENV['CI'] = 'true'
137-
File.mocked_existing_files(['../../sdks/.hermesversion'])
138-
assert_true(is_building_hermes_from_source("0.999.0", '../..'))
139-
end
140-
141-
def test_isBuildingHermesFromSource_whenTarballIsNotNil_returnFalse
142-
ENV['HERMES_ENGINE_TARBALL_PATH'] = "~/Downloads/hermes-ios-debug.tar.gz"
143-
assert_false(is_building_hermes_from_source("1000.0.0", '../..'))
144-
end
145-
146-
def test_isBuildingHermesFromSource_whenIsNigthly_returnsFalse
147-
assert_false(is_building_hermes_from_source("0.0.0-", '../..'))
148-
end
149-
150-
def test_isBuildingHermesFromSource_whenIsStbleRelease_returnsFalse
151-
assert_false(is_building_hermes_from_source("0.71.0", '../..'))
152-
end
153-
154128
end

scripts/cocoapods/jsengine.rb

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,3 @@ def setup_hermes!(react_native_path: "../node_modules/react-native", fabric_enab
3434
pod 'React-hermes', :path => "#{react_native_path}/ReactCommon/hermes"
3535
pod 'libevent', '~> 2.1.12'
3636
end
37-
38-
def add_copy_hermes_framework_script_phase(installer, react_native_path)
39-
utils_dir = File.join(react_native_path, "sdks", "hermes-engine", "utils")
40-
phase_name = "[RN] Copy Hermes Framework"
41-
project = installer.generated_aggregate_targets.first.user_project
42-
target = project.targets.first
43-
if target.shell_script_build_phases.none? { |phase| phase.name == phase_name }
44-
phase = target.new_shell_script_build_phase(phase_name)
45-
phase.shell_script = ". #{utils_dir}/copy-hermes-xcode.sh"
46-
project.save()
47-
end
48-
end
49-
50-
def remove_copy_hermes_framework_script_phase(installer, react_native_path)
51-
utils_dir = File.join(react_native_path, "sdks", "hermes-engine", "utils")
52-
phase_name = "[RN] Copy Hermes Framework"
53-
project = installer.generated_aggregate_targets.first.user_project
54-
target = project.native_targets.first
55-
target.shell_script_build_phases.each do |phase|
56-
if phase.name == phase_name
57-
target.build_phases.delete(phase)
58-
end
59-
end
60-
project.save()
61-
end
62-
63-
# TODO: Use this same function in the `hermes-engine.podspec` somehow
64-
def is_building_hermes_from_source(react_native_version, react_native_path)
65-
if ENV['HERMES_ENGINE_TARBALL_PATH'] != nil
66-
return false
67-
end
68-
69-
isInMain = react_native_version.include?('1000.0.0')
70-
71-
hermestag_file = File.join(react_native_path, "sdks", ".hermesversion")
72-
isInCI = ENV['CI'] === 'true'
73-
74-
isReleaseBranch = File.exist?(hermestag_file) && isInCI
75-
76-
77-
return isInMain || isReleaseBranch
78-
end

scripts/react_native_pods.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,6 @@ def react_native_post_install(installer, react_native_path = "../node_modules/re
205205
package = JSON.parse(File.read(File.join(react_native_path, "package.json")))
206206
version = package['version']
207207

208-
if ReactNativePodsUtils.has_pod(installer, 'hermes-engine') && is_building_hermes_from_source(version, react_native_path)
209-
add_copy_hermes_framework_script_phase(installer, react_native_path)
210-
else
211-
remove_copy_hermes_framework_script_phase(installer, react_native_path)
212-
end
213-
214208
ReactNativePodsUtils.exclude_i386_architecture_while_using_hermes(installer)
215209
ReactNativePodsUtils.fix_library_search_paths(installer)
216210
ReactNativePodsUtils.set_node_modules_user_settings(installer, react_native_path)

sdks/hermes-engine/hermes-engine.podspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Pod::Spec.new do |spec|
7373
"CLANG_CXX_LIBRARY" => "compiler-default"
7474
}.merge!(build_type == :debug ? { "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=1" } : {})
7575

76+
spec.ios.vendored_frameworks = "destroot/Library/Frameworks/ios/hermes.framework"
77+
spec.osx.vendored_frameworks = "destroot/Library/Frameworks/macosx/hermes.framework"
78+
7679
if source[:http] then
7780

7881
spec.subspec 'Pre-built' do |ss|
@@ -111,14 +114,11 @@ Pod::Spec.new do |spec|
111114
end
112115

113116
spec.user_target_xcconfig = {
114-
'FRAMEWORK_SEARCH_PATHS' => '"$(PODS_ROOT)/hermes-engine/destroot/Library/Frameworks/iphoneos" ' +
115-
'"$(PODS_ROOT)/hermes-engine/destroot/Library/Frameworks/iphonesimulator" ' +
116-
'"$(PODS_ROOT)/hermes-engine/destroot/Library/Frameworks/macosx" ' +
117-
'"$(PODS_ROOT)/hermes-engine/destroot/Library/Frameworks/catalyst"',
118-
'OTHER_LDFLAGS' => '-framework "hermes"',
119117
'HERMES_CLI_PATH' => "#{hermesc_path}/bin/hermesc"
120118
}
121119

120+
spec.prepare_command = ". #{react_native_path}/sdks/hermes-engine/utils/create-dummy-hermes-xcframework.sh"
121+
122122
CMAKE_BINARY = %x(command -v cmake | tr -d '\n')
123123
# NOTE: Script phases are sorted alphabetically inside Xcode project
124124
spec.script_phases = [

sdks/hermes-engine/utils/build-hermes-xcode.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,10 @@ echo "Build Apple framework"
6363
--build "${PODS_ROOT}/hermes-engine/build/${PLATFORM_NAME}" \
6464
--target "install/strip" \
6565
-j "$(sysctl -n hw.ncpu)"
66+
67+
echo "Copy Apple framework to destroot/Library/Frameworks"
68+
69+
cp -pfR \
70+
"${PODS_ROOT}/hermes-engine/destroot/Library/Frameworks/${PLATFORM_NAME}/hermes.framework" \
71+
"${PODS_ROOT}/hermes-engine/destroot/Library/Frameworks/ios"
72+
rm -rf "${PODS_ROOT}/hermes-engine/destroot/Library/Frameworks/${PLATFORM_NAME}"

sdks/hermes-engine/utils/copy-hermes-xcode.sh

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,4 @@
44
# This source code is licensed under the MIT license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
set -x
8-
9-
src="${PODS_ROOT}/hermes-engine/destroot/Library/Frameworks/${PLATFORM_NAME}/hermes.framework"
10-
11-
if [[ ! -e "$src" ]]; then
12-
echo "$src does not exist."
13-
exit 1
14-
fi
15-
16-
dst1="${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes"
17-
[ ! -f "$dst1" ] && mkdir -p "$dst1"
18-
cp -R "$src" "$dst1"
19-
20-
dst2="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
21-
[ ! -f "$dst2" ] && mkdir -p "$dst2"
22-
cp -R "$src" "$dst2"
7+
echo "This file is no-op now. Remove \"[RN] Copy Hermes Framework\" script phase from your main target if you don't want to see this message."
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
set -x
8+
9+
# CocoaPods requires vendored frameworks to exist before `pod install` is run,
10+
# and to be proper Moch-O binaries in order to auto-link them to the user's Xcode project.
11+
# This script creates dummy hermes.framework for macosx and ios.
12+
# They are then get rewritten by `build-hermes-xcode.sh` during Xcode build.
13+
14+
rm -rf destroot
15+
16+
mkdir -p destroot/Library/Frameworks
17+
18+
pushd destroot/Library/Frameworks > /dev/null || exit 1
19+
20+
echo '' > dummy.c
21+
22+
mkdir -p macosx/hermes.framework
23+
clang dummy.c -dynamiclib -o macosx/hermes.framework/hermes
24+
25+
mkdir -p ios/hermes.framework
26+
clang dummy.c -dynamiclib -o ios/hermes.framework/hermes
27+
28+
rm dummy.c
29+
30+
popd > /dev/null || exit 1

0 commit comments

Comments
 (0)