Skip to content

Commit 269e690

Browse files
fix(worklets): avoid HERMES_V1_ENABLED macro redefinition on RN 0.84+ (#8908)
## Summary React Native 0.84 centralized the `HERMES_V1_ENABLED` define into `target_compile_reactnative_options()` in `react-native-flags.cmake` ([commit](facebook/react-native@9f7f6b7)). When worklets defines `-DHERMES_V1_ENABLED=${HERMES_V1_ENABLED}` and then calls `target_compile_reactnative_options()`, the macro gets defined twice with different values (`true` vs `1`), causing: ``` error: 'HERMES_V1_ENABLED' macro redefined [-Werror,-Wmacro-redefined] #define HERMES_V1_ENABLED true <command line>:1:9: note: previous definition is here #define HERMES_V1_ENABLED 1 ``` Requires - #8909 ## Solution Only define `HERMES_V1_ENABLED` manually for RN < 84, since RN 84+ handles it via `target_compile_reactnative_options()`. ## Test plan - Tested with Expo SDK 55 canary + React Native 0.84.0-rc.4 - Android build succeeds after this fix --------- Co-authored-by: Tomasz Żelawski <tzelawski@gmail.com> Co-authored-by: Tomasz Żelawski <40713406+tjzel@users.noreply.github.com>
1 parent 9316e8a commit 269e690

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ string(
1616
CMAKE_CXX_FLAGS
1717
" -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}\
1818
-DWORKLETS_VERSION=${WORKLETS_VERSION}\
19-
-DWORKLETS_FEATURE_FLAGS=\"${WORKLETS_FEATURE_FLAGS}\"\
20-
-DHERMES_V1_ENABLED=${HERMES_V1_ENABLED}")
19+
-DWORKLETS_FEATURE_FLAGS=\"${WORKLETS_FEATURE_FLAGS}\"")
20+
21+
# HERMES_V1_ENABLED is centralized in react-native-flags.cmake for RN >= 84.
22+
# Only define manually for older versions to avoid macro redefinition error.
23+
if(REACT_NATIVE_MINOR_VERSION LESS 84)
24+
string(APPEND CMAKE_CXX_FLAGS " -DHERMES_V1_ENABLED=${HERMES_V1_ENABLED}")
25+
endif()
2126

2227
string(APPEND CMAKE_CXX_FLAGS " -fno-omit-frame-pointer -fstack-protector-all")
2328

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def safeAppExtGet(prop, fallback) {
1414

1515
def isNewArchitectureEnabled() {
1616
// In React Native 0.82+, users can no longer opt-out of the New Architecture.
17-
if(getReactNativeMinorVersion() >= 82){
17+
if (getReactNativeMinorVersion() >= 82) {
1818
return true
1919
}
2020

@@ -55,6 +55,19 @@ def getReactNativeMinorVersion() {
5555
return reactNativeVersion.startsWith("0.0.0-") ? 1000 : reactNativeVersion.split("\\.")[1].toInteger()
5656
}
5757

58+
def getHermesV1Enabled() {
59+
// Even though `HERMES_V1_ENABLED` is now centralized
60+
// in `react-native-flags.cmake` for React Native >= 0.84
61+
// that CMake file depends on definitions provided
62+
// in local `externalNativeBuild` configuration of the LIBRARY.
63+
// I hope this is only a temporary workaround.
64+
if (getReactNativeMinorVersion() >= 84) {
65+
return safeAppExtGet("hermesV1Enabled", true)
66+
} else {
67+
return safeAppExtGet("hermesV1Enabled", false)
68+
}
69+
}
70+
5871
def getWorkletsVersion() {
5972
def inputFile = file(projectDir.path + '/../package.json')
6073
def json = new JsonSlurper().parseText(inputFile.text)
@@ -112,7 +125,7 @@ def IS_REANIMATED_EXAMPLE_APP = safeAppExtGet("isReanimatedExampleApp", false)
112125
def BUNDLE_MODE_ENABLED = isFlagEnabled(featureFlags, "BUNDLE_MODE_ENABLED");
113126
def FETCH_PREVIEW_ENABLED = isFlagEnabled(featureFlags, "FETCH_PREVIEW_ENABLED");
114127
def WORKLETS_FEATURE_FLAGS = getStaticFeatureFlagsString(featureFlags)
115-
def HERMES_V1_ENABLED = safeAppExtGet("hermesV1Enabled", false)
128+
def HERMES_V1_ENABLED = getHermesV1Enabled()
116129
def WORKLETS_PROFILING = safeAppExtGet("enableWorkletsProfiling", false)
117130

118131
// Set version for prefab
@@ -284,7 +297,7 @@ android {
284297
}
285298
}
286299
}
287-
if(project != rootProject) {
300+
if (project != rootProject) {
288301
kotlinOptions {
289302
jvmTarget = '17'
290303
}

0 commit comments

Comments
 (0)