From 1c63877fec08e6c83efcd4cbd8e6adc420289ea9 Mon Sep 17 00:00:00 2001 From: Jakub Piasecki Date: Fri, 16 Jan 2026 06:42:34 -0800 Subject: [PATCH] Explicitly enable debugger when building Hermes for Fantom (#55202) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55202 Changelog: [Internal] After changing Hermes V1 to be the default engine, Fantom tests started failing. This was due to a combination of changes, one of them being the change of default value for `HERMES_ENABLE_DEBUGGER`. In case of legacy Hermes it was enabled by default, while for Hermes V1 it's disabled by default. Fantom didn't explicitly set this flag, but the debug build of RN (which Fantom performs) requires it to be enabled. This diff explicitly sets this flag to true for Fantom builds. Reviewed By: cipolleschi, cortinico Differential Revision: D90849881 fbshipit-source-id: 17f8393872eacef26f927f50aaf364644d9b94d7 --- .../hermes-engine/build.gradle.kts | 126 ++++++++++++++---- private/react-native-fantom/build.gradle.kts | 4 +- 2 files changed, 103 insertions(+), 27 deletions(-) diff --git a/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts b/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts index f33331ddaa5..05ce6441af5 100644 --- a/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts +++ b/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts @@ -149,28 +149,55 @@ val installCMake by ) } +fun configureBuildForHermesCommandLineArgs( + hermesBuildDir: File, + jsiDir: File, + enableDebugger: Boolean, +): List { + var cmakeCommandLine = + windowsAwareCommandLine( + cmakeBinaryPath, + // Suppress all warnings as this is the Hermes build and we can't fix them. + "--log-level=ERROR", + "-Wno-dev", + "-S", + ".", + "-B", + hermesBuildDir.toString(), + "-DJSI_DIR=" + jsiDir.absolutePath, + "-DCMAKE_BUILD_TYPE=Release", + ) + if (enableDebugger) { + cmakeCommandLine = cmakeCommandLine + "-DHERMES_ENABLE_DEBUGGER=True" + } + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + cmakeCommandLine = cmakeCommandLine + "-GNMake Makefiles" + } + if (hermesV1Enabled) { + cmakeCommandLine = cmakeCommandLine + "-DHERMESVM_HEAP_HV_MODE=HEAP_HV_PREFER32" + } + + return cmakeCommandLine +} + +fun buildHermesCCommandLineArgs() = + listOf( + cmakeBinaryPath, + "--build", + hermesBuildDir.toString(), + "--target", + "hermesc", + "-j", + ndkBuildJobs, + ) + val configureBuildForHermes by tasks.registering(CustomExecTask::class) { dependsOn(installCMake) workingDir(hermesDir) inputs.dir(hermesDir) outputs.files(hermesBuildOutputFileTree) - var cmakeCommandLine = - windowsAwareCommandLine( - cmakeBinaryPath, - // Suppress all warnings as this is the Hermes build and we can't fix them. - "--log-level=ERROR", - "-Wno-dev", - "-S", - ".", - "-B", - hermesBuildDir.toString(), - "-DJSI_DIR=" + jsiDir.absolutePath, - "-DCMAKE_BUILD_TYPE=Release", - ) - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - cmakeCommandLine = cmakeCommandLine + "-GNMake Makefiles" - } + val cmakeCommandLine = configureBuildForHermesCommandLineArgs(hermesBuildDir, jsiDir, false) commandLine(cmakeCommandLine) standardOutputFile.set(project.file("$buildDir/configure-hermesc.log")) } @@ -181,15 +208,8 @@ val buildHermesC by workingDir(hermesDir) inputs.files(hermesBuildOutputFileTree) outputs.file(hermesCOutputBinary) - commandLine( - cmakeBinaryPath, - "--build", - hermesBuildDir.toString(), - "--target", - "hermesc", - "-j", - ndkBuildJobs, - ) + val cmakeCommandLine = buildHermesCCommandLineArgs() + commandLine(cmakeCommandLine) standardOutputFile.set(project.file("$buildDir/build-hermesc.log")) errorOutputFile.set(project.file("$buildDir/build-hermesc.error.log")) } @@ -222,6 +242,60 @@ val buildHermesLib by errorOutputFile.set(project.file("$buildDir/build-hermes-lib.error.log")) } +// The repeated tasks below named "*WithDebugger" are required by Fantom. +// Hermes V1 by default builds with the debugger disabled, while Fantom needs +// it to be enabled as it does a debug build of React Native. +val configureBuildForHermesWithDebugger by + tasks.registering(CustomExecTask::class) { + dependsOn(installCMake) + workingDir(hermesDir) + inputs.dir(hermesDir) + outputs.files(hermesBuildOutputFileTree) + val cmakeCommandLine = configureBuildForHermesCommandLineArgs(hermesBuildDir, jsiDir, true) + commandLine(cmakeCommandLine) + standardOutputFile.set(project.file("$buildDir/configure-hermesc.log")) + } + +val buildHermesCWithDebugger by + tasks.registering(CustomExecTask::class) { + dependsOn(configureBuildForHermesWithDebugger) + workingDir(hermesDir) + inputs.files(hermesBuildOutputFileTree) + outputs.file(hermesCOutputBinary) + val cmakeCommandLine = buildHermesCCommandLineArgs() + commandLine(cmakeCommandLine) + standardOutputFile.set(project.file("$buildDir/build-hermesc.log")) + errorOutputFile.set(project.file("$buildDir/build-hermesc.error.log")) + } + +val prepareHeadersForPrefabWithDebugger by + tasks.registering(Copy::class) { + dependsOn(buildHermesCWithDebugger) + from("$hermesDir/API") + from("$hermesDir/public") + include("**/*.h") + exclude("jsi/**") + into(prefabHeadersDir) + } + +val buildHermesLibWithDebugger by + tasks.registering(CustomExecTask::class) { + dependsOn(buildHermesCWithDebugger) + workingDir(hermesDir) + inputs.files(hermesBuildOutputFileTree) + commandLine( + cmakeBinaryPath, + "--build", + hermesBuildDir.toString(), + "--target", + "hermesvm", + "-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 { val result = if (Os.isFamily(Os.FAMILY_WINDOWS)) { @@ -370,6 +444,8 @@ afterEvaluate { // download/unzip Hermes from Github then. tasks.getByName("configureBuildForHermes").dependsOn(unzipHermes) tasks.getByName("prepareHeadersForPrefab").dependsOn(unzipHermes) + tasks.getByName("configureBuildForHermesWithDebugger").dependsOn(unzipHermes) + tasks.getByName("prepareHeadersForPrefabWithDebugger").dependsOn(unzipHermes) } tasks.getByName("preBuild").dependsOn(buildHermesC) tasks.getByName("preBuild").dependsOn(prepareHeadersForPrefab) diff --git a/private/react-native-fantom/build.gradle.kts b/private/react-native-fantom/build.gradle.kts index 48a8a52b2c4..f9c12fee63d 100644 --- a/private/react-native-fantom/build.gradle.kts +++ b/private/react-native-fantom/build.gradle.kts @@ -159,8 +159,8 @@ val prepareHermesDependencies by tasks.registering { dependsOn( enableHermesBuild, - ":packages:react-native:ReactAndroid:hermes-engine:buildHermesLib", - ":packages:react-native:ReactAndroid:hermes-engine:prepareHeadersForPrefab", + ":packages:react-native:ReactAndroid:hermes-engine:buildHermesLibWithDebugger", + ":packages:react-native:ReactAndroid:hermes-engine:prepareHeadersForPrefabWithDebugger", ) }