From 464af4bddd302f908c3476f7ab9a208ac20f89d5 Mon Sep 17 00:00:00 2001 From: Kudo Chien Date: Mon, 22 Jan 2024 23:12:59 +0800 Subject: [PATCH] Enable hermes debugger on all build variants (#33) --- .../ReactAndroid/hermes-engine/build.gradle.kts | 4 ++-- .../main/jni/react/hermes/reactexecutor/CMakeLists.txt | 2 +- .../src/main/jni/react/runtime/hermes/jni/CMakeLists.txt | 2 +- .../src/main/jni/react/runtime/jni/CMakeLists.txt | 2 +- .../ReactCommon/hermes/executor/CMakeLists.txt | 1 + .../ReactCommon/hermes/inspector-modern/CMakeLists.txt | 8 ++++++++ .../react-native/ReactCommon/react/runtime/CMakeLists.txt | 2 +- .../react-native/sdks/hermes-engine/hermes-engine.podspec | 3 +++ .../sdks/hermes-engine/utils/build-apple-framework.sh | 3 ++- .../sdks/hermes-engine/utils/build-hermes-xcode.sh | 3 ++- 10 files changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts b/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts index 7376fcd248d103..7f4bd2bb533233 100644 --- a/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts +++ b/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts @@ -271,8 +271,8 @@ android { cmake { arguments( "-DCMAKE_BUILD_TYPE=MinSizeRel", - // For release builds, we don't want to enable the Hermes Debugger. - "-DHERMES_ENABLE_DEBUGGER=False") + // For Expo Go, we have to enable debugging even on release builds. + "-DHERMES_ENABLE_DEBUGGER=True") } } } diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt b/packages/react-native/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt index ab70319d7f3416..5f654198020f94 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt +++ b/packages/react-native/ReactAndroid/src/main/jni/react/hermes/reactexecutor/CMakeLists.txt @@ -17,7 +17,7 @@ add_library(hermes_executor target_compile_options( hermes_executor PRIVATE - $<$:-DHERMES_ENABLE_DEBUGGER=1> + -DHERMES_ENABLE_DEBUGGER=1 -std=c++20 -fexceptions ) diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/CMakeLists.txt b/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/CMakeLists.txt index 1d8e0cf0a3ead2..fc66132f8643ab 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/CMakeLists.txt +++ b/packages/react-native/ReactAndroid/src/main/jni/react/runtime/hermes/jni/CMakeLists.txt @@ -17,7 +17,7 @@ add_library(hermesinstancejni target_compile_options( hermesinstancejni PRIVATE - $<$:-DHERMES_ENABLE_DEBUGGER=1> + -DHERMES_ENABLE_DEBUGGER=1 -std=c++20 -fexceptions ) diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/runtime/jni/CMakeLists.txt b/packages/react-native/ReactAndroid/src/main/jni/react/runtime/jni/CMakeLists.txt index add0445af38760..547634e5c5f3b1 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/runtime/jni/CMakeLists.txt +++ b/packages/react-native/ReactAndroid/src/main/jni/react/runtime/jni/CMakeLists.txt @@ -17,7 +17,7 @@ add_library(rninstance target_compile_options( rninstance PRIVATE - $<$:-DHERMES_ENABLE_DEBUGGER=1> + -DHERMES_ENABLE_DEBUGGER=1 -std=c++20 -fexceptions ) diff --git a/packages/react-native/ReactCommon/hermes/executor/CMakeLists.txt b/packages/react-native/ReactCommon/hermes/executor/CMakeLists.txt index a52b9c3542ad78..4bda12116e1941 100644 --- a/packages/react-native/ReactCommon/hermes/executor/CMakeLists.txt +++ b/packages/react-native/ReactCommon/hermes/executor/CMakeLists.txt @@ -33,5 +33,6 @@ else() hermes_executor_common PRIVATE -DNDEBUG + -DHERMES_ENABLE_DEBUGGER=1 ) endif() diff --git a/packages/react-native/ReactCommon/hermes/inspector-modern/CMakeLists.txt b/packages/react-native/ReactCommon/hermes/inspector-modern/CMakeLists.txt index 0e511126624a0f..577b6ed342593d 100644 --- a/packages/react-native/ReactCommon/hermes/inspector-modern/CMakeLists.txt +++ b/packages/react-native/ReactCommon/hermes/inspector-modern/CMakeLists.txt @@ -25,6 +25,14 @@ if(${CMAKE_BUILD_TYPE} MATCHES Debug) PRIVATE -DHERMES_ENABLE_DEBUGGER=1 ) +else() + # Expo Go requires debugging on release builds + target_compile_options( + hermes_inspector_modern + PRIVATE + # Expo Go requires debugging on release builds + -DHERMES_ENABLE_DEBUGGER=1 + ) endif() target_include_directories(hermes_inspector_modern PUBLIC ${REACT_COMMON_DIR}) diff --git a/packages/react-native/ReactCommon/react/runtime/CMakeLists.txt b/packages/react-native/ReactCommon/react/runtime/CMakeLists.txt index 2418ed82dff8b4..19426d09e258e5 100644 --- a/packages/react-native/ReactCommon/react/runtime/CMakeLists.txt +++ b/packages/react-native/ReactCommon/react/runtime/CMakeLists.txt @@ -15,7 +15,7 @@ add_library(bridgeless target_compile_options( bridgeless PRIVATE - $<$:-DHERMES_ENABLE_DEBUGGER=1> + -DHERMES_ENABLE_DEBUGGER=1 -std=c++20 -fexceptions ) diff --git a/packages/react-native/sdks/hermes-engine/hermes-engine.podspec b/packages/react-native/sdks/hermes-engine/hermes-engine.podspec index 6680c60dc493f4..813890c0e89f52 100644 --- a/packages/react-native/sdks/hermes-engine/hermes-engine.podspec +++ b/packages/react-native/sdks/hermes-engine/hermes-engine.podspec @@ -17,6 +17,9 @@ react_native_path = File.dirname(Pod::Executable.execute_command('node', ['-p', package = JSON.parse(File.read(File.join(react_native_path, "package.json"))) version = package['version'] +# Force building Hermes from source because Expo Go requires customized Hermes build +ENV['RCT_BUILD_HERMES_FROM_SOURCE'] = 'true' + source_type = hermes_source_type(version, react_native_path) source = podspec_source(source_type, version, react_native_path) diff --git a/packages/react-native/sdks/hermes-engine/utils/build-apple-framework.sh b/packages/react-native/sdks/hermes-engine/utils/build-apple-framework.sh index 08701e2e25fda3..9f08cbe5e742fe 100755 --- a/packages/react-native/sdks/hermes-engine/utils/build-apple-framework.sh +++ b/packages/react-native/sdks/hermes-engine/utils/build-apple-framework.sh @@ -72,7 +72,8 @@ function configure_apple_framework { if [[ $BUILD_TYPE == "Debug" ]]; then enable_debugger="true" else - enable_debugger="false" + # Expo Go requires debugging on release build + enable_debugger="true" fi if [[ $BUILD_TYPE == "Debug" ]]; then # JS developers aren't VM developers. diff --git a/packages/react-native/sdks/hermes-engine/utils/build-hermes-xcode.sh b/packages/react-native/sdks/hermes-engine/utils/build-hermes-xcode.sh index 0fa473e9c11fca..f7b15dd23fb505 100755 --- a/packages/react-native/sdks/hermes-engine/utils/build-hermes-xcode.sh +++ b/packages/react-native/sdks/hermes-engine/utils/build-hermes-xcode.sh @@ -36,7 +36,8 @@ function get_deployment_target { echo "${IPHONEOS_DEPLOYMENT_TARGET}" } -enable_debugger="false" +# Expo Go requires debugging on release build +enable_debugger="true" if [[ "$CONFIGURATION" == "Debug" ]]; then enable_debugger="true" fi