Skip to content

Commit f312abe

Browse files
authored
Compatibility with new Hermes (#8268)
## Summary Starting with React Native 0.82, it will be possible to test the new version of Hermes v1 (previously called Static Hermes) by enabling the flag `HERMES_V1_ENABLED`—see more details here: [link](facebook/react-native#53579). Reanimated works with new Hermes out of the box; we just need to stop using the legacy debugger with the new Hermes, as it removes them. We're working on supporting the new debugger, but it will require more attention—follow the progress here: [link](#7655). ## Test plan
1 parent f0dc547 commit f312abe

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ namespace worklets {
1616

1717
using namespace facebook;
1818
using namespace react;
19-
#if HERMES_ENABLE_DEBUGGER
19+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
2020
using namespace facebook::hermes::inspector_modern;
21-
#endif // HERMES_ENABLE_DEBUGGER
21+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
2222

2323
#if HERMES_ENABLE_DEBUGGER
2424

25-
class HermesExecutorRuntimeAdapter : public RuntimeAdapter {
25+
class HermesExecutorRuntimeAdapter
26+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
27+
: public RuntimeAdapter
28+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
29+
{
2630
public:
2731
explicit HermesExecutorRuntimeAdapter(
2832
facebook::hermes::HermesRuntime &hermesRuntime,
@@ -34,7 +38,7 @@ class HermesExecutorRuntimeAdapter : public RuntimeAdapter {
3438
// that the thread was indeed `quit` before
3539
thread_->quitSynchronous();
3640
}
37-
41+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
3842
facebook::hermes::HermesRuntime &getRuntime() override {
3943
return hermesRuntime_;
4044
}
@@ -44,6 +48,7 @@ class HermesExecutorRuntimeAdapter : public RuntimeAdapter {
4448
// required us to hold a refernce to the runtime inside this adapter which
4549
// caused issues while reloading the app.
4650
void tickleJs() override {}
51+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
4752

4853
public:
4954
facebook::hermes::HermesRuntime &hermesRuntime_;
@@ -60,11 +65,11 @@ WorkletHermesRuntime::WorkletHermesRuntime(
6065
*runtime,
6166
reentrancyCheck_),
6267
runtime_(std::move(runtime)) {
63-
#if HERMES_ENABLE_DEBUGGER
68+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
6469
auto adapter =
6570
std::make_unique<HermesExecutorRuntimeAdapter>(*runtime_, jsQueue);
6671
debugToken_ = chrome::enableDebugging(std::move(adapter), name);
67-
#endif // HERMES_ENABLE_DEBUGGER
72+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
6873

6974
#ifndef NDEBUG
7075
facebook::hermes::HermesRuntime *wrappedRuntime = runtime_.get();
@@ -97,10 +102,10 @@ WorkletHermesRuntime::WorkletHermesRuntime(
97102
}
98103

99104
WorkletHermesRuntime::~WorkletHermesRuntime() {
100-
#if HERMES_ENABLE_DEBUGGER
105+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
101106
// We have to disable debugging before the runtime is destroyed.
102107
chrome::disableDebugging(debugToken_);
103-
#endif // HERMES_ENABLE_DEBUGGER
108+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
104109
}
105110

106111
} // namespace worklets

packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletHermesRuntime.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
#include <string>
1818
#include <thread>
1919

20-
#if HERMES_ENABLE_DEBUGGER
20+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
2121
#include <hermes/inspector-modern/chrome/Registration.h>
22-
#endif // HERMES_ENABLE_DEBUGGER
22+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
2323

2424
namespace worklets {
2525

2626
using namespace facebook;
2727
using namespace react;
28-
#if HERMES_ENABLE_DEBUGGER
28+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
2929
using namespace facebook::hermes::inspector_modern;
30-
#endif // HERMES_ENABLE_DEBUGGER
30+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
3131

3232
// ReentrancyCheck is copied from React Native
3333
// from ReactCommon/hermes/executor/HermesExecutorFactory.cpp
@@ -121,9 +121,9 @@ class WorkletHermesRuntime
121121
private:
122122
std::unique_ptr<facebook::hermes::HermesRuntime> runtime_;
123123
WorkletsReentrancyCheck reentrancyCheck_;
124-
#if HERMES_ENABLE_DEBUGGER
124+
#if HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
125125
chrome::DebugSessionToken debugToken_;
126-
#endif // HERMES_ENABLE_DEBUGGER
126+
#endif // HERMES_ENABLE_DEBUGGER && !defined(HERMES_V1_ENABLED)
127127
};
128128

129129
} // namespace worklets

packages/react-native-worklets/android/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ string(
1515
APPEND
1616
CMAKE_CXX_FLAGS
1717
" -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}\
18-
-DWORKLETS_VERSION=${WORKLETS_VERSION}\
19-
-DWORKLETS_FEATURE_FLAGS=\"${WORKLETS_FEATURE_FLAGS}\"")
18+
-DWORKLETS_VERSION=${WORKLETS_VERSION}\
19+
-DWORKLETS_FEATURE_FLAGS=\"${WORKLETS_FEATURE_FLAGS}\"\
20+
-DHERMES_V1_ENABLED=${HERMES_V1_ENABLED}")
2021

2122
string(APPEND CMAKE_CXX_FLAGS " -fno-omit-frame-pointer -fstack-protector-all")
2223

packages/react-native-worklets/android/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def IS_NEW_ARCHITECTURE_ENABLED = isNewArchitectureEnabled()
102102
def IS_REANIMATED_EXAMPLE_APP = safeAppExtGet("isReanimatedExampleApp", false)
103103
def BUNDLE_MODE = safeAppExtGet("workletsBundleMode", false)
104104
def WORKLETS_FEATURE_FLAGS = getStaticFeatureFlags()
105+
def HERMES_V1_ENABLED = safeAppExtGet("hermesV1Enabled", false)
105106

106107
// Set version for prefab
107108
version WORKLETS_VERSION
@@ -196,7 +197,8 @@ android {
196197
"-DWORKLETS_BUNDLE_MODE=${BUNDLE_MODE}",
197198
"-DWORKLETS_VERSION=${WORKLETS_VERSION}",
198199
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
199-
"-DWORKLETS_FEATURE_FLAGS=${WORKLETS_FEATURE_FLAGS}"
200+
"-DWORKLETS_FEATURE_FLAGS=${WORKLETS_FEATURE_FLAGS}",
201+
"-DHERMES_V1_ENABLED=${HERMES_V1_ENABLED}"
200202
abiFilters (*reactNativeArchitectures())
201203
targets("worklets")
202204
}

0 commit comments

Comments
 (0)