Skip to content

Commit 3c958a8

Browse files
hramosfacebook-github-bot
authored andcommitted
Add flag to enable building Hermes from source on iOS
Summary: If Hermes is enabled on a project and the envvar `BUILD_HERMES_SOURCE` is truthy, a React Native project will build Hermes from source when running `pod install`: ``` cd ios/ BUILD_HERMES_SOURCE=1 pod install ``` * Requires `cmake` and `ninja` to be installed: `brew install cmake ninja`. * Requires a `react-native` release with Hermes source code bundled in (`scripts/publish-npm.js --include-hermes && npm pack`). # Changelog [Internal] Reviewed By: cortinico Differential Revision: D34313581 fbshipit-source-id: 4ba5f82aa6c7027fd37f1982127fc5f63d931ded
1 parent 8b226f9 commit 3c958a8

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

scripts/react_native_pods.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,13 @@ def use_react_native! (options={})
109109

110110
if hermes_enabled
111111
pod 'React-hermes', :path => "#{prefix}/ReactCommon/hermes"
112-
pod 'hermes-engine', '~> 0.11.0'
112+
113+
if ENV['BUILD_HERMES_SOURCE'] == '1'
114+
hermes_source_path = locatePathToHermesSource!(prefix)
115+
pod 'hermes-engine', :path => "#{hermes_source_path}/hermes-engine.podspec"
116+
else
117+
pod 'hermes-engine', '~> 0.11.0'
118+
end
113119
pod 'libevent', '~> 2.1.12'
114120
end
115121
end
@@ -622,6 +628,20 @@ def use_react_native_codegen!(spec, options={})
622628
}
623629
end
624630

631+
def locatePathToHermesSource!(react_native_path)
632+
return if ENV['BUILD_HERMES_SOURCE'] != '1'
633+
634+
hermes_source_path = "#{react_native_path}/sdks/hermes"
635+
636+
if !File.exist?(hermes_source_path)
637+
Pod::UI.warn "[Hermes] Error: Hermes source code must be present at #{hermes_source_path} when BUILD_HERMES_SOURCE is enabled."
638+
Pod::UI.warn '[Hermes] Verify that the release of React Native that you are using has the Hermes source code included.'
639+
exit 1
640+
end
641+
642+
hermes_source_path
643+
end
644+
625645
# This provides a post_install workaround for build issues related Xcode 12.5 and Apple Silicon (M1) machines.
626646
# Call this in the app's main Podfile's post_install hook.
627647
# See https://github.com/facebook/react-native/issues/31480#issuecomment-902912841 for more context.

0 commit comments

Comments
 (0)