Skip to content

Commit

Permalink
Upstream RN macOS Hermes integration bits (#29748)
Browse files Browse the repository at this point in the history
Summary:
Microsoft’s RN for macOS fork supports the Hermes engine nowadays microsoft#473. As a longer term work item, we’ve started moving bits that are not invasive for iOS but _are_ a maintenance burden on us—mostly when merging—upstream. Seeing as this one is a recent addition, it seemed like a good candidate to start with.

As to the actual changes, these include:

* Sharing Android’s Hermes executor with the objc side of the codebase.
* Adding a CocoaPods subspec to build the Hermes inspector source and its dependencies (`Folly/Futures`, `libevent`).
* Adding the bits to the Xcode build phase script that creates the JS bundle for release builds to compile Hermes bytecode and source-maps…
* …coincidentally it turns out that the Xcode build phase script did _not_ by default output source-maps for iOS, which is now fixed too.

All of the Hermes bits are automatically enabled, on macOS, when providing the `hermes-engine-darwin` [npm package](https://www.npmjs.com/package/hermes-engine-darwin) and enabling the Hermes pods.

## Changelog

[General] [Added] - Upstream RN macOS Hermes integration bits

Pull Request resolved: #29748

Test Plan:
Building RNTester for iOS and Android still works as before.

To test the actual changes themselves, you’ll have to use the macOS target in RNTester in the macOS fork, or create a new application from `master`:

<img width="812" alt="Screenshot 2020-08-18 at 16 55 06" src="https://user-images.githubusercontent.com/2320/90547606-160f6480-e18c-11ea-9a98-edbbaa755800.png">

Reviewed By: TheSavior

Differential Revision: D23304618

Pulled By: fkgozali

fbshipit-source-id: 4ef0e0f60d909f3c59f9cfc87c667189df656a3b
  • Loading branch information
alloy authored and facebook-github-bot committed Aug 27, 2020
1 parent e3845f4 commit 941bc0e
Show file tree
Hide file tree
Showing 40 changed files with 1,036 additions and 296 deletions.
4 changes: 2 additions & 2 deletions Libraries/Blob/React-RCTBlob.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/RCT-Folly\""
}

s.dependency "Folly", folly_version
s.dependency "RCT-Folly", folly_version
s.dependency "FBReactNativeSpec", version
s.dependency "ReactCommon/turbomodule/core", version
s.dependency "React-jsi", version
Expand Down
4 changes: 2 additions & 2 deletions Libraries/FBReactNativeSpec/FBReactNativeSpec.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/Libraries/FBReactNativeSpec\" \"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/Libraries/FBReactNativeSpec\" \"$(PODS_ROOT)/RCT-Folly\""
}

s.dependency "Folly", folly_version
s.dependency "RCT-Folly", folly_version
s.dependency "RCTRequired", version
s.dependency "RCTTypeSafety", version
s.dependency "React-Core", version
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Image/React-RCTImage.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/RCT-Folly\""
}

s.dependency "Folly", folly_version
s.dependency "RCT-Folly", folly_version
s.dependency "FBReactNativeSpec", version
s.dependency "RCTTypeSafety", version
s.dependency "ReactCommon/turbomodule/core", version
Expand Down
2 changes: 1 addition & 1 deletion Libraries/LinkingIOS/React-RCTLinking.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/RCT-Folly\""
}

s.dependency "FBReactNativeSpec", version
Expand Down
4 changes: 2 additions & 2 deletions Libraries/NativeAnimation/React-RCTAnimation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/RCT-Folly\""
}

s.dependency "Folly", folly_version
s.dependency "RCT-Folly", folly_version
s.dependency "RCTTypeSafety", version
s.dependency "ReactCommon/turbomodule/core", version
s.dependency "React-jsi", version
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Network/React-RCTNetwork.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/RCT-Folly\""
}
s.frameworks = "MobileCoreServices"

s.dependency "Folly", folly_version
s.dependency "RCT-Folly", folly_version
s.dependency "FBReactNativeSpec", version
s.dependency "RCTTypeSafety", version
s.dependency "ReactCommon/turbomodule/core", version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/RCT-Folly\""
}
s.framework = "UserNotifications"

Expand Down
4 changes: 2 additions & 2 deletions Libraries/Settings/React-RCTSettings.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/RCT-Folly\""
}

s.dependency "Folly", folly_version
s.dependency "RCT-Folly", folly_version
s.dependency "FBReactNativeSpec", version
s.dependency "RCTTypeSafety", version
s.dependency "ReactCommon/turbomodule/core", version
Expand Down
4 changes: 2 additions & 2 deletions Libraries/TypeSafety/RCTTypeSafety.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/Libraries/TypeSafety\" \"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/Libraries/TypeSafety\" \"$(PODS_ROOT)/RCT-Folly\""
}

s.dependency "FBLazyVector", version
s.dependency "Folly", folly_version
s.dependency "RCT-Folly", folly_version
s.dependency "RCTRequired", version
s.dependency "React-Core", version
end
4 changes: 2 additions & 2 deletions Libraries/Vibration/React-RCTVibration.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/RCT-Folly\""
}
s.frameworks = "AudioToolbox"

s.dependency "Folly", folly_version
s.dependency "RCT-Folly", folly_version
s.dependency "FBReactNativeSpec", version
s.dependency "ReactCommon/turbomodule/core", version
s.dependency "React-jsi", version
Expand Down
15 changes: 13 additions & 2 deletions React-Core.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Pod::Spec.new do |s|
s.header_dir = "React"
s.framework = "JavaScriptCore"
s.library = "stdc++"
s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Folly\"" }
s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/RCT-Folly\"" }
s.user_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/Headers/Private/React-Core\""}
s.default_subspec = "Default"

Expand All @@ -69,6 +69,17 @@ Pod::Spec.new do |s|
ss.private_header_files = "React/Cxx*/*.h"
end

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 "RCT-Folly/Futures"
ss.dependency "hermes", "~> 0.6.0"
end

s.subspec "DevSupport" do |ss|
ss.source_files = "React/DevSupport/*.{h,mm,m}",
"React/Inspector/*.{h,mm,m}"
Expand All @@ -92,7 +103,7 @@ Pod::Spec.new do |s|
end
end

s.dependency "Folly", folly_version
s.dependency "RCT-Folly", folly_version
s.dependency "React-cxxreact", version
s.dependency "React-perflogger", version
s.dependency "React-jsi", version
Expand Down
4 changes: 2 additions & 2 deletions React/CoreModules/React-CoreModules.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Pod::Spec.new do |s|
s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++14",
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/React/CoreModules\" \"$(PODS_ROOT)/Folly\""
"HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/React/CoreModules\" \"$(PODS_ROOT)/RCT-Folly\""
}

s.dependency "FBReactNativeSpec", version
s.dependency "Folly", folly_version
s.dependency "RCT-Folly", folly_version
s.dependency "RCTTypeSafety", version
s.dependency "React-Core/CoreModulesHeaders", version
s.dependency "React-RCTImage", version
Expand Down
20 changes: 1 addition & 19 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 @@ -19,25 +18,8 @@
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);

react::PerformanceNow iosPerformanceNowBinder = []() {
// CACurrentMediaTime() returns the current absolute time, in seconds
return CACurrentMediaTime() * 1000;
};
react::bindNativePerformanceNow(runtime, iosPerformanceNowBinder);

// Wrap over the original runtimeInstaller
if (runtimeInstaller) {
runtimeInstaller(runtime);
}
};
return std::make_unique<JSIExecutor>(
facebook::jsc::makeJSCRuntime(), delegate, JSIExecutor::defaultTimeoutInvoker, std::move(installBindings));
facebook::jsc::makeJSCRuntime(), delegate, JSIExecutor::defaultTimeoutInvoker, runtimeInstaller_);
}

} // namespace react
Expand Down
16 changes: 15 additions & 1 deletion React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@
#import <jsireact/JSIExecutor.h>
#import <reactperflogger/BridgeNativeModulePerfLogger.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 "RCTJSIExecutorRuntimeInstaller.h"

#import "NSDataBigString.h"
#import "RCTMessageThread.h"
#import "RCTObjcExecutor.h"
Expand Down Expand Up @@ -370,7 +379,12 @@ - (void)start
executorFactory = [cxxDelegate jsExecutorFactoryForBridge:self];
}
if (!executorFactory) {
executorFactory = std::make_shared<JSCExecutorFactory>(nullptr);
auto installBindings = RCTJSIExecutorRuntimeInstaller(nullptr);
#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
23 changes: 23 additions & 0 deletions React/CxxBridge/RCTJSIExecutorRuntimeInstaller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include <jsireact/JSIExecutor.h>

namespace facebook {
namespace react {

/**
* Creates a lambda used to bind a JSIRuntime in the context of
* Apple platforms, such as console logging, performance metrics, etc.
*/
JSIExecutor::RuntimeInstaller RCTJSIExecutorRuntimeInstaller(
JSIExecutor::RuntimeInstaller runtimeInstallerToWrap);

} // namespace react
} // namespace facebook
37 changes: 37 additions & 0 deletions React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "RCTJSIExecutorRuntimeInstaller.h"

#import <React/RCTLog.h>

namespace facebook {
namespace react {

JSIExecutor::RuntimeInstaller RCTJSIExecutorRuntimeInstaller(JSIExecutor::RuntimeInstaller runtimeInstallerToWrap)
{
return [runtimeInstaller = runtimeInstallerToWrap](jsi::Runtime &runtime) {
Logger iosLoggingBinder = [](const std::string &message, unsigned int logLevel) {
_RCTLogJavaScriptInternal(static_cast<RCTLogLevel>(logLevel), [NSString stringWithUTF8String:message.c_str()]);
};
bindNativeLogger(runtime, iosLoggingBinder);

PerformanceNow iosPerformanceNowBinder = []() {
// CACurrentMediaTime() returns the current absolute time, in seconds
return CACurrentMediaTime() * 1000;
};
bindNativePerformanceNow(runtime, iosPerformanceNowBinder);

// Wrap over the original runtimeInstaller
if (runtimeInstaller) {
runtimeInstaller(runtime);
}
};
}

} // namespace react
} // namespace facebook
4 changes: 2 additions & 2 deletions React/React-RCTFabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Pod::Spec.new do |s|
s.header_dir = "React"
s.framework = "JavaScriptCore"
s.library = "stdc++"
s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/Folly\" \"$(PODS_ROOT)/Headers/Private/React-Core\"" }
s.xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/glog\" \"$(PODS_ROOT)/Folly\"",
s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/Headers/Private/React-Core\"" }
s.xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/glog\" \"$(PODS_ROOT)/RCT-Folly\"",
"OTHER_CFLAGS" => "$(inherited) -DRN_FABRIC_ENABLED" + " " + folly_flags }

s.dependency "React-Core", version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(call find-no

LOCAL_CPP_FEATURES := exceptions

LOCAL_STATIC_LIBRARIES := libjsireact libjsi
LOCAL_STATIC_LIBRARIES := libjsireact libjsi libhermes-executor-common-release
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes

include $(BUILD_SHARED_LIBRARY)
Expand All @@ -34,7 +34,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(call find-no

LOCAL_CPP_FEATURES := exceptions

LOCAL_STATIC_LIBRARIES := libjsireact libjsi libhermes-inspector
LOCAL_STATIC_LIBRARIES := libjsireact libjsi libhermes-executor-common-debug libhermes-inspector
LOCAL_SHARED_LIBRARIES := libfolly_json libfb libfbjni libreactnativejni libhermes

include $(BUILD_SHARED_LIBRARY)
Loading

0 comments on commit 941bc0e

Please sign in to comment.