Skip to content

Add Hermes engine as option for macOS #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5ea4f9a
[CocoaPods] Add Hermes and get app to build & run
alloy May 7, 2020
dabc0e7
[Hermes] Create instance of VM from within Cxx codebase
alloy May 8, 2020
b82f581
[Hermes] Actually use Hermes for RN bridge.
alloy May 12, 2020
7248255
[Hermes] Use a release build to speed things up
alloy May 13, 2020
a964b7a
[Hermes] Use a binary distribution for now
alloy May 13, 2020
cb48b3c
[Hermes] Fix binary distribution
alloy May 13, 2020
4f2fbd9
[Hermes] Bind native logger, which enables console.js polyfill
alloy May 15, 2020
a710e8b
[Hermes] Add reentrancy check
alloy May 15, 2020
c127394
[Hermes] Compile and use bytecode bundle with RNTester
alloy May 15, 2020
45ef55e
[Hermes] Build with debugger support.
alloy May 23, 2020
c9b5ff7
[Hermes] Use v0.5.0 bin release
alloy Jun 2, 2020
6b82e8e
[Hermes] Enable on macOS when sources exist
alloy Jun 2, 2020
3e767ef
[Hermes] Use optimizations in release builds
alloy Jun 2, 2020
71822f3
[CxxBridge] Share logger binding between engines
alloy Jun 3, 2020
8a39db7
[Hermes] Share Android and macOS executor code.
alloy Jun 4, 2020
63c10f9
[Xcode] Remove need to sign locally
alloy Jun 22, 2020
2d2549c
[Pods] Build libevent from source and use prebuilt hermes framework
alloy Jun 22, 2020
782083a
[Pods] Make React-Core/Hermes an optional dep
alloy Jun 25, 2020
84d4c6a
[Xcode] Add ability to create source-maps for release builds, includi…
alloy Jun 25, 2020
aa1f62d
Tiny doc fix.
alloy Jun 25, 2020
d0388a1
[Pods] Move hermes deps to autolink script
alloy Jun 25, 2020
8539c5a
Minor cleanups
alloy Jun 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions RNTester/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ if ENV['USE_FRAMEWORKS'] == '1'
use_frameworks!
end

def pods()
def pods(options = {})
project 'RNTesterPods.xcodeproj'

# Enable TurboModule
use_react_native!(path: "..")
use_react_native!(options.merge(path: ".."))
pod 'ReactCommon/turbomodule/samples', :path => '../ReactCommon'

# Additional Pods which aren't included in the default Podfile
Expand Down Expand Up @@ -118,7 +117,7 @@ end

target 'RNTester-macOS' do
platform :osx, '10.14'
pods()
pods(:hermes_enabled => true)
end

target 'RNTesterUnitTests' do
Expand Down
43 changes: 39 additions & 4 deletions RNTester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ PODS:
- boost-for-react-native
- DoubleConversion
- glog
- Folly/Futures (2018.10.22.00):
- boost-for-react-native
- DoubleConversion
- glog
- libevent
- glog (0.3.5)
- hermes (0.4.1)
- libevent (2.1.11):
- libevent/core (= 2.1.11)
- libevent/core (2.1.11):
- libevent/event2-headers
- libevent/event2-headers (2.1.11)
- OpenSSL-Universal (1.0.2.19):
- OpenSSL-Universal/Static (= 1.0.2.19)
- OpenSSL-Universal/Static (1.0.2.19)
Expand Down Expand Up @@ -132,6 +143,15 @@ PODS:
- React-jsiexecutor (= 1000.0.0)
- React-jsinspector (= 1000.0.0)
- Yoga
- React-Core/Hermes (1000.0.0):
- Folly (= 2018.10.22.00)
- Folly/Futures
- glog
- hermes (~> 0.4.1)
- React-cxxreact (= 1000.0.0)
- React-jsi (= 1000.0.0)
- React-jsiexecutor (= 1000.0.0)
- Yoga
- React-Core/RCTActionSheetHeaders (1000.0.0):
- Folly (= 2018.10.22.00)
- glog
Expand Down Expand Up @@ -343,12 +363,15 @@ DEPENDENCIES:
- FlipperKit/SKIOSNetworkPlugin (~> 0.30.1)
- Folly (from `../third-party-podspecs/Folly.podspec`)
- glog (from `../third-party-podspecs/glog.podspec`)
- "hermes (from `{:http=>\"https://github.com/alloy/hermes/releases/download/v0.4.1-macOS/hermes-v0.4.1.zip\", :sha256=>\"d33c7eafded94d8113a3bb74f56aef3ec1cd3df513e99df7fa3c7c34b867d379\"}`)"
- libevent (from `../third-party-podspecs/libevent.podspec`)
- RCTRequired (from `../Libraries/RCTRequired`)
- RCTTypeSafety (from `../Libraries/TypeSafety`)
- React (from `../`)
- React-ART (from `../Libraries/ART`)
- React-Core (from `../`)
- React-Core/DevSupport (from `../`)
- React-Core/Hermes (from `../`)
- React-Core/RCTWebSocket (from `../`)
- React-CoreModules (from `../React/CoreModules`)
- React-cxxreact (from `../ReactCommon/cxxreact`)
Expand All @@ -372,7 +395,7 @@ DEPENDENCIES:
- Yoga (from `../ReactCommon/yoga`)

SPEC REPOS:
trunk:
https://cdn.cocoapods.org/:
- CocoaAsyncSocket
- CocoaLibEvent
- Flipper
Expand All @@ -398,6 +421,11 @@ EXTERNAL SOURCES:
:podspec: "../third-party-podspecs/Folly.podspec"
glog:
:podspec: "../third-party-podspecs/glog.podspec"
hermes:
:http: https://github.com/alloy/hermes/releases/download/v0.4.1-macOS/hermes-v0.4.1.zip
:sha256: d33c7eafded94d8113a3bb74f56aef3ec1cd3df513e99df7fa3c7c34b867d379
libevent:
:podspec: "../third-party-podspecs/libevent.podspec"
RCTRequired:
:path: "../Libraries/RCTRequired"
RCTTypeSafety:
Expand Down Expand Up @@ -445,6 +473,11 @@ EXTERNAL SOURCES:
Yoga:
:path: "../ReactCommon/yoga"

CHECKOUT OPTIONS:
hermes:
:http: https://github.com/alloy/hermes/releases/download/v0.4.1-macOS/hermes-v0.4.1.zip
:sha256: d33c7eafded94d8113a3bb74f56aef3ec1cd3df513e99df7fa3c7c34b867d379

SPEC CHECKSUMS:
boost-for-react-native: a110407d9db2642fd2e1bcd7c5a51c81f2521dc9
CocoaAsyncSocket: eafaa68a7e0ec99ead0a7b35015e0bf25d2c8987
Expand All @@ -459,14 +492,16 @@ SPEC CHECKSUMS:
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
Flipper-RSocket: 64e7431a55835eb953b0bf984ef3b90ae9fdddd7
FlipperKit: 88b7f0d0cf907ddc2137b85eeb7f3d4d8d9395c8
Folly: feff29ba9d0b7c2e4f793a94942831d6cc5bbad7
Folly: ae1e11fb7b57cac65fa994a5c9da9b6f652d934b
glog: b3f6d74f3e2d33396addc0ee724d2b2b79fc3e00
hermes: ea5308401c53c1352fcb566548f2a45605c36f15
libevent: c2d56c8554ac18101d9c5f4c66ef762798209682
OpenSSL-Universal: 8b48cc0d10c1b2923617dfe5c178aa9ed2689355
RCTRequired: 66250bf27479214eb5c530ca2d8c772ebe4d7e71
RCTTypeSafety: 2bf56caee198adc4adc63a5d18e8ffff8b92fbbb
React: bacecd5320c8bb453aa396179b93061ebd9d34bf
React-ART: 2f0eb928d7bc51e6262da595955b0e8fcf6c0a9e
React-Core: 8a9c0454b0540cfcca1261e8e084a324976bb6c2
React-Core: 0fb3a932eb28dcb299eceb7fb4e359b547557528
React-CoreModules: fbe1e42d49cb14db5c9bf02dee33a18d281331f7
React-cxxreact: 7ff40ab26e02c3f8b2fec2f5ea3d9f4774ef2523
React-jsi: b23bf7e79fb2149f3bb9bd4e25e570bff9c03d10
Expand All @@ -487,6 +522,6 @@ SPEC CHECKSUMS:
Yoga: 3ed3c35bb7c41fa8f5056b767bc048539f6526ad
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 524ab13b924fd82bc5c4393c133fcd02eb70efa4
PODFILE CHECKSUM: 9f7ce884d267d41098ed0c95a51abea8c184a0ea

COCOAPODS: 1.9.1
24 changes: 22 additions & 2 deletions RNTester/RNTesterPods.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -731,6 +731,7 @@
9F153459233AB2C4006DFE44 /* Resources */,
38C8132424577FB500BFFA62 /* Build JS Bundle */,
51B9D81723C4D5A4002B30E1 /* Start Metro */,
4733C3A4FBA299F6E1E956BA /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -1021,7 +1022,24 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export NODE_BINARY=node\nPROJECT_ROOT=$SRCROOT/.. $SRCROOT/../scripts/react-native-xcode.sh RNTester/js/RNTesterApp.macos.js\n";
shellScript = "export NODE_BINARY=node\nexport PROJECT_ROOT=$SRCROOT/..\nexport SOURCEMAP_FILE=sourcemap.macOS.map\n# export FORCE_BUNDLING=true\n$SRCROOT/../scripts/react-native-xcode.sh RNTester/js/RNTesterApp.macos.js\n";
};
4733C3A4FBA299F6E1E956BA /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTester-macOS/Pods-RNTester-macOS-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-RNTester-macOS/Pods-RNTester-macOS-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-RNTester-macOS/Pods-RNTester-macOS-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
51B9D81723C4D5A4002B30E1 /* Start Metro */ = {
isa = PBXShellScriptBuildPhase;
Expand Down Expand Up @@ -1814,6 +1832,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = "RNTester-macOS/RNTester_macOS.entitlements";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
Expand Down Expand Up @@ -1868,6 +1887,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = "RNTester-macOS/RNTester_macOS.entitlements";
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
Expand Down
18 changes: 16 additions & 2 deletions React-Core.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ Pod::Spec.new do |s|
ss.exclude_files = "React/CoreModules/**/*",
"React/DevSupport/**/*",
"React/Fabric/**/*",
"React/Inspector/**/*"
ss.ios.exclude_files = "React/**/RCTTV*.*",
"React/Inspector/**/*",
"React/CxxBridge/HermesExecutorFactory.*" # TODO(macOS GH#214)
ss.ios.exclude_files = "React/**/RCTTV*.*"

# [TODO(macOS ISS#2323203)
"**/MacOS/*"
Expand All @@ -80,6 +81,19 @@ Pod::Spec.new do |s|
ss.private_header_files = "React/Cxx*/*.h"
end

# [TODO(macOS GH#214)
s.subspec "Hermes" do |ss|
ss.platforms = { :osx => "10.14" }
ss.source_files = "ReactCommon/hermes/executor/*.{cpp,h}",
"ReactCommon/hermes/inspector/*.{cpp,h}",
"ReactCommon/hermes/inspector/chrome/*.{cpp,h}",
"ReactCommon/hermes/inspector/detail/*.{cpp,h}"
ss.pod_target_xcconfig = { "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=1" }
ss.dependency "Folly/Futures"
ss.dependency "hermes", "~> 0.4.1"
end
# ]TODO(macOS GH#214)

s.subspec "DevSupport" do |ss|
ss.source_files = "React/DevSupport/*.{h,mm,m}",
"React/Inspector/*.{h,mm,m}"
Expand Down
15 changes: 1 addition & 14 deletions React/CxxBridge/JSCExecutorFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "JSCExecutorFactory.h"

#import <React/RCTLog.h>
#import <jsi/JSCRuntime.h>

#import<memory>
Expand All @@ -18,23 +17,11 @@
std::unique_ptr<JSExecutor> JSCExecutorFactory::createJSExecutor(
std::shared_ptr<ExecutorDelegate> delegate,
std::shared_ptr<MessageQueueThread> __unused jsQueue) {
auto installBindings = [runtimeInstaller=runtimeInstaller_](jsi::Runtime &runtime) {
react::Logger iosLoggingBinder = [](const std::string &message, unsigned int logLevel) {
_RCTLogJavaScriptInternal(
static_cast<RCTLogLevel>(logLevel),
[NSString stringWithUTF8String:message.c_str()]);
};
react::bindNativeLogger(runtime, iosLoggingBinder);
// Wrap over the original runtimeInstaller
if (runtimeInstaller) {
runtimeInstaller(runtime);
}
};
return std::make_unique<JSIExecutor>(
facebook::jsc::makeJSCRuntime(),
delegate,
JSIExecutor::defaultTimeoutInvoker,
std::move(installBindings));
runtimeInstaller_);
}

} // namespace react
Expand Down
24 changes: 23 additions & 1 deletion React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@
#import <cxxreact/ReactMarker.h>
#import <jsireact/JSIExecutor.h>

#if TARGET_OS_OSX && __has_include(<hermes/hermes.h>)
#define RCT_USE_HERMES 1
#endif
#if RCT_USE_HERMES
#import "HermesExecutorFactory.h"
#else
#import "JSCExecutorFactory.h"
#endif

#import "NSDataBigString.h"
#import "RCTMessageThread.h"
#import "RCTObjcExecutor.h"
Expand Down Expand Up @@ -347,7 +355,21 @@ - (void)start
executorFactory = [cxxDelegate jsExecutorFactoryForBridge:self];
}
if (!executorFactory) {
executorFactory = std::make_shared<JSCExecutorFactory>(nullptr);
auto installBindings =
[](facebook::jsi::Runtime &runtime) {
facebook::react::Logger iosLoggingBinder =
[](const std::string &message, unsigned int logLevel) {
_RCTLogJavaScriptInternal(
static_cast<RCTLogLevel>(logLevel),
[NSString stringWithUTF8String:message.c_str()]);
};
facebook::react::bindNativeLogger(runtime, iosLoggingBinder);
};
#if RCT_USE_HERMES
executorFactory = std::make_shared<HermesExecutorFactory>(installBindings);
#else
executorFactory = std::make_shared<JSCExecutorFactory>(installBindings);
#endif
}
} else {
id<RCTJavaScriptExecutor> objcExecutor = [self moduleForClass:self.executorClass];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace facebook {
namespace jsi {
void addNativeTracingHooks(Runtime &rt) {
assert(false && "unimplemented");
// unimplemented
}
} // namespace jsi
} // namespace facebook
4 changes: 2 additions & 2 deletions ReactCommon/hermes/inspector/chrome/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ bool Connection::Impl::disconnect() {

inspector_->disable().via(executor_.get()).thenValue([this](auto &&) {
// HACK: We purposely call RemoteConnection::onDisconnect on a *different*
// rather than on this thread (the executor thread). This is to prevent this
// scenario:
// thread, rather than on this thread (the executor thread). This is to
// prevent this scenario:
//
// 1. RemoteConnection::onDisconnect runs on the executor thread
// 2. onDisconnect through a long chain of calls causes the Connection
Expand Down
11 changes: 10 additions & 1 deletion scripts/autolink-ios.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def use_react_native! (options={})
# Include DevSupport dependency
production = options[:production] ||= false

hermes_enabled = options[:hermes_enabled] ||= false

# The Pods which should be included in all projects
pod 'FBLazyVector', :path => "#{prefix}/Libraries/FBLazyVector"
pod 'FBReactNativeSpec', :path => "#{prefix}/Libraries/FBReactNativeSpec"
Expand Down Expand Up @@ -58,6 +60,13 @@ def use_react_native! (options={})
pod 'React-RCTFabric', :path => "#{prefix}/React"
pod 'Folly/Fabric', :podspec => "#{prefix}/third-party-podspecs/Folly.podspec"
end

if hermes_enabled
pod 'React-Core/Hermes', :path => "#{prefix}/"
pod 'hermes', :http => 'https://github.com/alloy/hermes/releases/download/v0.4.1-macOS/hermes-v0.4.1.zip',
:sha256 => 'd33c7eafded94d8113a3bb74f56aef3ec1cd3df513e99df7fa3c7c34b867d379'
pod 'libevent', :podspec => "#{prefix}/third-party-podspecs/libevent.podspec"
end
end

def add_flipper_pods!(versions = {})
Expand Down Expand Up @@ -101,4 +110,4 @@ def flipper_post_install(installer)
end
end
end
end
end
Loading