Skip to content

Commit 11a49c8

Browse files
andrewdacenkofacebook-github-bot
authored andcommitted
Add hermes and jsi
Summary: Changelog: [Internal] Add hermes and jsi so we can evaluate JS. Differential Revision: D76746362
1 parent c644dca commit 11a49c8

5 files changed

Lines changed: 61 additions & 1 deletion

File tree

packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,24 @@ val prepareHeadersForPrefab by
186186
into(prefabHeadersDir)
187187
}
188188

189+
val buildHermesLib by
190+
tasks.registering(CustomExecTask::class) {
191+
dependsOn(buildHermesC)
192+
workingDir(hermesDir)
193+
inputs.files(hermesBuildOutputFileTree)
194+
commandLine(
195+
cmakeBinaryPath,
196+
"--build",
197+
hermesBuildDir.toString(),
198+
"--target",
199+
"libhermes",
200+
"-j",
201+
ndkBuildJobs,
202+
)
203+
standardOutputFile.set(project.file("$buildDir/build-hermes-lib.log"))
204+
errorOutputFile.set(project.file("$buildDir/build-hermes-lib.error.log"))
205+
}
206+
189207
fun windowsAwareCommandLine(vararg commands: String): List<String> {
190208
val result =
191209
if (Os.isFamily(Os.FAMILY_WINDOWS)) {

private/react-native-fantom/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,7 @@ val prepareNative3pDependencies by
5959
tasks.registering {
6060
dependsOn(
6161
prepareGflags,
62+
":packages:react-native:ReactAndroid:hermes-engine:buildHermesLib",
63+
":packages:react-native:ReactAndroid:hermes-engine:prepareHeadersForPrefab",
6264
)
6365
}

private/react-native-fantom/tester/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ set(CMAKE_VERBOSE_MAKEFILE on)
88

99
project(fantom_tester)
1010

11+
find_library(LIB_HERMES libhermes
12+
HINTS ${REACT_ANDROID_DIR}/hermes-engine/build/hermes/API/hermes
13+
REQUIRED)
14+
include_directories(${REACT_ANDROID_DIR}/hermes-engine/build/prefab-headers)
15+
1116
include(${REACT_COMMON_DIR}/cmake-utils/react-native-flags.cmake)
1217

1318
# Convert input paths to CMake format (with forward slashes)
@@ -23,7 +28,7 @@ function(add_third_party_subdir relative_path)
2328
endfunction()
2429

2530
function(add_react_common_subdir relative_path)
26-
add_subdirectory(${REACT_COMMON_DIR}/${relative_path} src/${relative_path})
31+
add_subdirectory(${REACT_COMMON_DIR}/${relative_path} ReactCommon/${relative_path})
2732
endfunction()
2833

2934
function(add_fantom_third_party_subdir relative_path)
@@ -42,6 +47,7 @@ add_fantom_third_party_subdir(gflags)
4247

4348
# Common targets
4449
add_react_common_subdir(yoga)
50+
add_react_common_subdir(jsi)
4551
add_react_common_subdir(react/featureflags)
4652

4753
file(GLOB SOURCES "src/*.cpp" "src/*.h")
@@ -51,6 +57,8 @@ target_link_libraries(fantom_tester
5157
PRIVATE
5258
glog
5359
gflags
60+
jsi
61+
${LIB_HERMES}
5462
boost
5563
double-conversion
5664
fast_float

private/react-native-fantom/tester/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ BUILD_DIR="$SCRIPT_DIR/build"
1111
REACT_NATIVE_ROOT_DIR=$(readlink -f "$SCRIPT_DIR/../../../packages/react-native")
1212

1313
cmake -S "$SCRIPT_DIR" -B "$BUILD_DIR" \
14+
-DREACT_ANDROID_DIR="${REACT_NATIVE_ROOT_DIR}/ReactAndroid" \
1415
-DFANTOM_THIRD_PARTY_DIR="${SCRIPT_DIR}/../build/third-party" \
1516
-DREACT_THIRD_PARTY_NDK_DIR="${REACT_NATIVE_ROOT_DIR}/ReactAndroid/build/third-party-ndk" \
1617
-DREACT_COMMON_DIR="${REACT_NATIVE_ROOT_DIR}/ReactCommon"

private/react-native-fantom/tester/src/main.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <folly/json.h>
99
#include <gflags/gflags.h>
1010
#include <glog/logging.h>
11+
#include <hermes/hermes.h>
12+
#include <jsi/jsi.h>
1113
#include <react/featureflags/ReactNativeFeatureFlags.h>
1214
#include <react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h>
1315
#include <yoga/YGEnums.h>
@@ -23,6 +25,8 @@ DEFINE_string(
2325
"JSON representation of the common feature flags to set for the app");
2426

2527
using namespace facebook::react;
28+
using namespace facebook::hermes;
29+
using namespace facebook::jsi;
2630

2731
static void setUpLogging() {
2832
google::InitGoogleLogging("react-native-fantom");
@@ -46,6 +50,31 @@ static folly::dynamic setUpFeatureFlags() {
4650
return dynamicFeatureFlags;
4751
}
4852

53+
void createHermesInstance() {
54+
auto gcConfig = ::hermes::vm::GCConfig::Builder()
55+
// Default to 3GB
56+
.withMaxHeapSize(3072 << 20)
57+
.withName("RNBridgeless");
58+
::hermes::vm::RuntimeConfig::Builder runtimeConfigBuilder =
59+
::hermes::vm::RuntimeConfig::Builder()
60+
.withGCConfig(gcConfig.build())
61+
.withEnableSampleProfiling(true);
62+
63+
std::unique_ptr<HermesRuntime> hermesRuntime =
64+
makeHermesRuntime(runtimeConfigBuilder.build());
65+
66+
hermesRuntime->evaluateJavaScript(
67+
std::make_unique<StringBuffer>(
68+
"var fantom = 'Hello, I am fantom_tester'"),
69+
"script.js");
70+
71+
LOG(INFO) << "JS evaluated value: "
72+
<< hermesRuntime->global()
73+
.getProperty(*hermesRuntime, "fantom")
74+
.getString(*hermesRuntime)
75+
.utf8(*hermesRuntime);
76+
}
77+
4978
int main(int argc, char* argv[]) {
5079
if (argc > 0 && argv != nullptr) {
5180
// 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[]) {
6493
LOG(INFO) << fmt::format(
6594
"[FeatureFlags] overrides: {}", folly::toJson(dynamicFeatureFlags));
6695

96+
createHermesInstance();
97+
6798
return 0;
6899
}

0 commit comments

Comments
 (0)