mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add hermes and jsi (#52060)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/52060 Changelog: [Internal] Add hermes and jsi so we can evaluate JS. Reviewed By: christophpurrer Differential Revision: D76746362 fbshipit-source-id: a5fbb90d06a8608154b6ae80242b969e7cb03cea
This commit is contained in:
committed by
Facebook GitHub Bot
parent
74b6acb1f0
commit
aeaae4294f
@@ -186,6 +186,24 @@ val prepareHeadersForPrefab by
|
||||
into(prefabHeadersDir)
|
||||
}
|
||||
|
||||
val buildHermesLib by
|
||||
tasks.registering(CustomExecTask::class) {
|
||||
dependsOn(buildHermesC)
|
||||
workingDir(hermesDir)
|
||||
inputs.files(hermesBuildOutputFileTree)
|
||||
commandLine(
|
||||
cmakeBinaryPath,
|
||||
"--build",
|
||||
hermesBuildDir.toString(),
|
||||
"--target",
|
||||
"libhermes",
|
||||
"-j",
|
||||
ndkBuildJobs,
|
||||
)
|
||||
standardOutputFile.set(project.file("$buildDir/build-hermes-lib.log"))
|
||||
errorOutputFile.set(project.file("$buildDir/build-hermes-lib.error.log"))
|
||||
}
|
||||
|
||||
fun windowsAwareCommandLine(vararg commands: String): List<String> {
|
||||
val result =
|
||||
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
||||
|
||||
@@ -59,5 +59,7 @@ val prepareNative3pDependencies by
|
||||
tasks.registering {
|
||||
dependsOn(
|
||||
prepareGflags,
|
||||
":packages:react-native:ReactAndroid:hermes-engine:buildHermesLib",
|
||||
":packages:react-native:ReactAndroid:hermes-engine:prepareHeadersForPrefab",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@ set(CMAKE_VERBOSE_MAKEFILE on)
|
||||
|
||||
project(fantom_tester)
|
||||
|
||||
find_library(LIB_HERMES libhermes
|
||||
HINTS ${REACT_ANDROID_DIR}/hermes-engine/build/hermes/API/hermes
|
||||
REQUIRED)
|
||||
include_directories(${REACT_ANDROID_DIR}/hermes-engine/build/prefab-headers)
|
||||
|
||||
include(${REACT_COMMON_DIR}/cmake-utils/react-native-flags.cmake)
|
||||
|
||||
# Convert input paths to CMake format (with forward slashes)
|
||||
@@ -23,7 +28,7 @@ function(add_third_party_subdir relative_path)
|
||||
endfunction()
|
||||
|
||||
function(add_react_common_subdir relative_path)
|
||||
add_subdirectory(${REACT_COMMON_DIR}/${relative_path} src/${relative_path})
|
||||
add_subdirectory(${REACT_COMMON_DIR}/${relative_path} ReactCommon/${relative_path})
|
||||
endfunction()
|
||||
|
||||
function(add_fantom_third_party_subdir relative_path)
|
||||
@@ -42,6 +47,7 @@ add_fantom_third_party_subdir(gflags)
|
||||
|
||||
# Common targets
|
||||
add_react_common_subdir(yoga)
|
||||
add_react_common_subdir(jsi)
|
||||
add_react_common_subdir(react/featureflags)
|
||||
|
||||
file(GLOB SOURCES "src/*.cpp" "src/*.h")
|
||||
@@ -51,6 +57,8 @@ target_link_libraries(fantom_tester
|
||||
PRIVATE
|
||||
glog
|
||||
gflags
|
||||
jsi
|
||||
${LIB_HERMES}
|
||||
boost
|
||||
double-conversion
|
||||
fast_float
|
||||
|
||||
@@ -11,6 +11,7 @@ BUILD_DIR="$SCRIPT_DIR/build"
|
||||
REACT_NATIVE_ROOT_DIR=$(readlink -f "$SCRIPT_DIR/../../../packages/react-native")
|
||||
|
||||
cmake -S "$SCRIPT_DIR" -B "$BUILD_DIR" \
|
||||
-DREACT_ANDROID_DIR="${REACT_NATIVE_ROOT_DIR}/ReactAndroid" \
|
||||
-DFANTOM_THIRD_PARTY_DIR="${SCRIPT_DIR}/../build/third-party" \
|
||||
-DREACT_THIRD_PARTY_NDK_DIR="${REACT_NATIVE_ROOT_DIR}/ReactAndroid/build/third-party-ndk" \
|
||||
-DREACT_COMMON_DIR="${REACT_NATIVE_ROOT_DIR}/ReactCommon"
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <folly/json.h>
|
||||
#include <gflags/gflags.h>
|
||||
#include <glog/logging.h>
|
||||
#include <hermes/hermes.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#include <react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h>
|
||||
#include <yoga/YGEnums.h>
|
||||
@@ -23,6 +25,8 @@ DEFINE_string(
|
||||
"JSON representation of the common feature flags to set for the app");
|
||||
|
||||
using namespace facebook::react;
|
||||
using namespace facebook::hermes;
|
||||
using namespace facebook::jsi;
|
||||
|
||||
static void setUpLogging() {
|
||||
google::InitGoogleLogging("react-native-fantom");
|
||||
@@ -46,6 +50,31 @@ static folly::dynamic setUpFeatureFlags() {
|
||||
return dynamicFeatureFlags;
|
||||
}
|
||||
|
||||
void createHermesInstance() {
|
||||
auto gcConfig = ::hermes::vm::GCConfig::Builder()
|
||||
// Default to 3GB
|
||||
.withMaxHeapSize(3072 << 20)
|
||||
.withName("RNBridgeless");
|
||||
::hermes::vm::RuntimeConfig::Builder runtimeConfigBuilder =
|
||||
::hermes::vm::RuntimeConfig::Builder()
|
||||
.withGCConfig(gcConfig.build())
|
||||
.withEnableSampleProfiling(true);
|
||||
|
||||
std::unique_ptr<HermesRuntime> hermesRuntime =
|
||||
makeHermesRuntime(runtimeConfigBuilder.build());
|
||||
|
||||
hermesRuntime->evaluateJavaScript(
|
||||
std::make_unique<StringBuffer>(
|
||||
"var fantom = 'Hello, I am fantom_tester'"),
|
||||
"script.js");
|
||||
|
||||
LOG(INFO) << "JS evaluated value: "
|
||||
<< hermesRuntime->global()
|
||||
.getProperty(*hermesRuntime, "fantom")
|
||||
.getString(*hermesRuntime)
|
||||
.utf8(*hermesRuntime);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc > 0 && argv != nullptr) {
|
||||
// Don't exit app on unknown flags, as some of those may be provided when
|
||||
@@ -64,5 +93,7 @@ int main(int argc, char* argv[]) {
|
||||
LOG(INFO) << fmt::format(
|
||||
"[FeatureFlags] overrides: {}", folly::toJson(dynamicFeatureFlags));
|
||||
|
||||
createHermesInstance();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user