mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
2c26c8fdedd8cfc53cc7e5c2c716b19bce2caf23
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
6b8e13f53c |
Integrate Hermes with the Xcode build process
Summary: ## Context If React Native is built from *main* of any non-stable commit, then Hermes is built from source. The build is performed by `build-ios-framework.sh` and `build-mac-framework.sh` scripts in `hermes-engine.podspec` `prepare_command` stage. Since those scripts have no access build target information, they build all possible architectures and platforms just in case. That takes ages. ## Solution The idea is to integrate build script into Xcode *run script* phase, and use build target information to build Hermes for active architecture only. ## Implementation - Existing behaviour remains unchanged for local tarball and remote prebuild cases. - `build-hermesc-xcode.sh` builds Hermesc as `hermes-engine.podspec` `prepare_command`. Default build location is `react-native/sdks/hermes-engine/build_host_hermesc`. - `build-hermes-xcode.sh` builds Hermes in 'Build Hermes' Xcode script phase. It uses `$PLATFORM_NAME`, `$CONFIGURATION`, `$ARCHS`, `$IPHONEOS_DEPLOYMENT_TARGET` and `$MACOSX_DEPLOYMENT_TARGET` environment variables to configure cmake project so it builds only active architecture. The script also gets RN version, *cmake* path and *hermesc* path from the podspec. - `copy-hermes-xcode.sh` copies Hermes.framework inside the app bundle. This script phase is added to the user app target in a `post_install` hook, after pods are integrated in a user project. - `OTHER_LDFLAGS -framework "hermes"` added to the user project to enable linking against Hermes.framework. - If `HERMES_OVERRIDE_HERMESC_PATH` is set, then Hermesc building is skipped, and `HERMES_OVERRIDE_HERMESC_PATH` is used for `build-hermes-xcode.sh`. - `HERMES_CLI_PATH` is injected into user project config to enable Hermes source maps in `react-native-xcode.sh`. ## Things that didn't work - *Running build-hermesc-xcode.sh in Xcode run script phase*. This doesn't work because Hermesc is supposed to be built for macos, and if build target is ios, then Xcode configures environment in such a way that Hermesc build fails. - *Installing Hermesc into CocoaPods download folder*. So it then ends up in `Pods/hermes-engine/build_host_hermesc`, and all the housekeeping is handled by CocoaPods. This doesn't work because cmake uses absolute paths in a configured project. If configured project is moved to a different location, nothing builds. - *Installing Hermesc directly into Pods/hermes-engine*. This doesn't work because CocoaPods runs prepare_command before Pods folder clean up, and everything gets wiped. ## Known issue - If `Pods/hermes-engine` is manually removed, then `sdks/hermes-engine/build_host_hermesc` must also be removed before running `pod install`. Otherwise cmake will complain about stale cache: ``` CMake Error: The source "<CocoaPodsCache>/hermes-engine/<hash2>/CMakeLists.txt" does not match the source "<CocoaPodsCache>/hermes-engine/<has1>/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory. ``` ## Benchmark MacBook M1 2021 32 GB. ``` export REACT_NATIVE_PATH=~/fbsource/xplat/js/react-native-github cd $REACT_NATIVE_PATH/packages/rn-tester pod install rm -rf $REACT_NATIVE_PATH/sdks/hermes-engine/build_host_hermesc cd $REACT_NATIVE_PATH/packages/rn-tester/Pods/hermes-engine echo 't1=$(date +%s); $@; t2=$(date +%s); diff=$(echo "$t2 - $t1" | bc); echo Operation took $diff seconds.' > /tmp/benchmark.sh ``` ``` # Before export BUILD_TYPE=Debug export JSI_PATH=$REACT_NATIVE_PATH/ReactCommon/jsi export RELEASE_VERSION=1000.0 export IOS_DEPLOYMENT_TARGET=iphonesimulator export MAC_DEPLOYMENT_TARGET=12.6 cd $REACT_NATIVE_PATH/packages/rn-tester/Pods/hermes-engine . /tmp/benchmark.sh $REACT_NATIVE_PATH/sdks/hermes-engine/utils/build-ios-framework.sh # Operation took 252 seconds . /tmp/benchmark.sh $REACT_NATIVE_PATH/sdks/hermes-engine/utils/build-mac-framework.sh # Operation took 179 seconds ``` ``` # After . /tmp/benchmark.sh source $REACT_NATIVE_PATH/sdks/hermes-engine/utils/build-hermesc-xcode.sh $REACT_NATIVE_PATH/sdks/hermes-engine/build_host_hermesc # Operation took 59 seconds. . /tmp/benchmark.sh xcodebuild -workspace $REACT_NATIVE_PATH/packages/rn-tester/RNTesterPods.xcworkspace -scheme hermes-engine # Operation took 106 seconds. ``` |Before|||After||| |--| |iOS framework (s)|Mac framework (s)|Total (s)|Hermesc (s)|Target-specific framework (s)|Total (s)| |252|179|431|59|106|**165 (-266) (-61%)**| The performance win is fixed, and does not depend on the project size and structure. As an example, this is how these changes affect build time of RNTester. |Before||||After||| |--| ||Pod install (s)|Xcode build (s)|Total (s)|Pod install (s)|Xcode build (s)|Total (s)| |Clean build|1219|132|1352|734 (-485)|249(+117)|**983 (-369)**| |Incremental build|82|30|112|105 (+23)|**34 (+4)**|139 (+27)| The most important values here are the total clean build time and the incremental Xcode build time. The first one went down by 369 seconds, the second one went up by 4 seconds. I consider it a reasonable tradeoff. The extra 4 seconds in the incremental Xcode build time can potentially be mitigated by setting up output file lists for the new script phases. allow-large-files Changelog: [iOS][Changed] - Hermes is integrated into Xcode build. Reviewed By: hramos Differential Revision: D40063686 fbshipit-source-id: e6993d62225789377db769244bc07786cc978a27 |
||
|
|
a68c418082 |
Do not build JSI in React-jsi when Hermes is enabled, resolve JSI ODR violation (#35038)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35038 React-jsi provides JSI to allow React Native to interface with JavaScriptCore. The hermes-engine Pod provides a second copy of JSI, as Hermes is built and linked statically with JSI. This second copy of JSI would lead to an [ODR Violation](https://en.cppreference.com/w/cpp/language/definition). To resolve this, when Hermes is enabled: - React-hermes and hermes-engine are installed. - React-jsc is not installed. - React-jsi continues to be installed. - React-jsi will not build JSI. - React-jsi will declare a dependency on hermes-engine. The result is that the JSI dependency for React Native is satisfied by hermes-engine, and there is no duplicate JSI library in the project. When Hermes is disabled: - React-jsi and React-jsc are installed. - React-hermes and hermes-engine are not installed. - React-jsi will build JSI. Changelog: [iOS][Changed] Resolve JSI ODR violation, make hermes-engine the JSI provider when Hermes is enabled Reviewed By: cipolleschi Differential Revision: D40334913 fbshipit-source-id: 409407a193a35cbd21b0e8778537b3627e4c54a2 |
||
|
|
22e4bdf10a |
CocoaPods: Consolidate Hermes and JSC Engine configuration in jsengine.rb
Summary: Move JSC and Hermes CocoaPods configuration to scripts/cocoapods/jsengine.rb. This file provides a setup_jsc! function and a setup_hermes! function that will configure the necessary pod dependencies for each of the supported JavaScript engines. Currently, the JSI and JSC pods are installed in both cases. This will likely change in upcoming changes to how Hermes and JSC are configured. Changelog: [internal] Reviewed By: dmytrorykun Differential Revision: D40459234 fbshipit-source-id: d6c89c7f650b1efcce5622594db7fd726eafc2bc |