Skip to content

Commit ae15c9c

Browse files
j-piaseckireact-native-bot
authored andcommitted
Explicitly enable debugger when building Hermes for Fantom (#55202)
Summary: Pull Request resolved: #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
1 parent 2d61709 commit ae15c9c

2 files changed

Lines changed: 99 additions & 23 deletions

File tree

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

Lines changed: 97 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,28 +149,55 @@ val installCMake by
149149
)
150150
}
151151

152+
fun configureBuildForHermesCommandLineArgs(
153+
hermesBuildDir: File,
154+
jsiDir: File,
155+
enableDebugger: Boolean,
156+
): List<String> {
157+
var cmakeCommandLine =
158+
windowsAwareCommandLine(
159+
cmakeBinaryPath,
160+
// Suppress all warnings as this is the Hermes build and we can't fix them.
161+
"--log-level=ERROR",
162+
"-Wno-dev",
163+
"-S",
164+
".",
165+
"-B",
166+
hermesBuildDir.toString(),
167+
"-DJSI_DIR=" + jsiDir.absolutePath,
168+
"-DCMAKE_BUILD_TYPE=Release",
169+
)
170+
if (enableDebugger) {
171+
cmakeCommandLine = cmakeCommandLine + "-DHERMES_ENABLE_DEBUGGER=True"
172+
}
173+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
174+
cmakeCommandLine = cmakeCommandLine + "-GNMake Makefiles"
175+
}
176+
if (hermesV1Enabled) {
177+
cmakeCommandLine = cmakeCommandLine + "-DHERMESVM_HEAP_HV_MODE=HEAP_HV_PREFER32"
178+
}
179+
180+
return cmakeCommandLine
181+
}
182+
183+
fun buildHermesCCommandLineArgs() =
184+
listOf(
185+
cmakeBinaryPath,
186+
"--build",
187+
hermesBuildDir.toString(),
188+
"--target",
189+
"hermesc",
190+
"-j",
191+
ndkBuildJobs,
192+
)
193+
152194
val configureBuildForHermes by
153195
tasks.registering(CustomExecTask::class) {
154196
dependsOn(installCMake)
155197
workingDir(hermesDir)
156198
inputs.dir(hermesDir)
157199
outputs.files(hermesBuildOutputFileTree)
158-
var cmakeCommandLine =
159-
windowsAwareCommandLine(
160-
cmakeBinaryPath,
161-
// Suppress all warnings as this is the Hermes build and we can't fix them.
162-
"--log-level=ERROR",
163-
"-Wno-dev",
164-
"-S",
165-
".",
166-
"-B",
167-
hermesBuildDir.toString(),
168-
"-DJSI_DIR=" + jsiDir.absolutePath,
169-
"-DCMAKE_BUILD_TYPE=Release",
170-
)
171-
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
172-
cmakeCommandLine = cmakeCommandLine + "-GNMake Makefiles"
173-
}
200+
val cmakeCommandLine = configureBuildForHermesCommandLineArgs(hermesBuildDir, jsiDir, false)
174201
commandLine(cmakeCommandLine)
175202
standardOutputFile.set(project.file("$buildDir/configure-hermesc.log"))
176203
}
@@ -181,32 +208,79 @@ val buildHermesC by
181208
workingDir(hermesDir)
182209
inputs.files(hermesBuildOutputFileTree)
183210
outputs.file(hermesCOutputBinary)
211+
val cmakeCommandLine = buildHermesCCommandLineArgs()
212+
commandLine(cmakeCommandLine)
213+
standardOutputFile.set(project.file("$buildDir/build-hermesc.log"))
214+
errorOutputFile.set(project.file("$buildDir/build-hermesc.error.log"))
215+
}
216+
217+
val prepareHeadersForPrefab by
218+
tasks.registering(Copy::class) {
219+
dependsOn(buildHermesC)
220+
from("$hermesDir/API")
221+
from("$hermesDir/public")
222+
include("**/*.h")
223+
exclude("jsi/**")
224+
into(prefabHeadersDir)
225+
}
226+
227+
val buildHermesLib by
228+
tasks.registering(CustomExecTask::class) {
229+
dependsOn(buildHermesC)
230+
workingDir(hermesDir)
231+
inputs.files(hermesBuildOutputFileTree)
184232
commandLine(
185233
cmakeBinaryPath,
186234
"--build",
187235
hermesBuildDir.toString(),
188236
"--target",
189-
"hermesc",
237+
"hermesvm",
190238
"-j",
191239
ndkBuildJobs,
192240
)
241+
standardOutputFile.set(project.file("$buildDir/build-hermes-lib.log"))
242+
errorOutputFile.set(project.file("$buildDir/build-hermes-lib.error.log"))
243+
}
244+
245+
// The repeated tasks below named "*WithDebugger" are required by Fantom.
246+
// Hermes V1 by default builds with the debugger disabled, while Fantom needs
247+
// it to be enabled as it does a debug build of React Native.
248+
val configureBuildForHermesWithDebugger by
249+
tasks.registering(CustomExecTask::class) {
250+
dependsOn(installCMake)
251+
workingDir(hermesDir)
252+
inputs.dir(hermesDir)
253+
outputs.files(hermesBuildOutputFileTree)
254+
val cmakeCommandLine = configureBuildForHermesCommandLineArgs(hermesBuildDir, jsiDir, true)
255+
commandLine(cmakeCommandLine)
256+
standardOutputFile.set(project.file("$buildDir/configure-hermesc.log"))
257+
}
258+
259+
val buildHermesCWithDebugger by
260+
tasks.registering(CustomExecTask::class) {
261+
dependsOn(configureBuildForHermesWithDebugger)
262+
workingDir(hermesDir)
263+
inputs.files(hermesBuildOutputFileTree)
264+
outputs.file(hermesCOutputBinary)
265+
val cmakeCommandLine = buildHermesCCommandLineArgs()
266+
commandLine(cmakeCommandLine)
193267
standardOutputFile.set(project.file("$buildDir/build-hermesc.log"))
194268
errorOutputFile.set(project.file("$buildDir/build-hermesc.error.log"))
195269
}
196270

197-
val prepareHeadersForPrefab by
271+
val prepareHeadersForPrefabWithDebugger by
198272
tasks.registering(Copy::class) {
199-
dependsOn(buildHermesC)
273+
dependsOn(buildHermesCWithDebugger)
200274
from("$hermesDir/API")
201275
from("$hermesDir/public")
202276
include("**/*.h")
203277
exclude("jsi/**")
204278
into(prefabHeadersDir)
205279
}
206280

207-
val buildHermesLib by
281+
val buildHermesLibWithDebugger by
208282
tasks.registering(CustomExecTask::class) {
209-
dependsOn(buildHermesC)
283+
dependsOn(buildHermesCWithDebugger)
210284
workingDir(hermesDir)
211285
inputs.files(hermesBuildOutputFileTree)
212286
commandLine(
@@ -370,6 +444,8 @@ afterEvaluate {
370444
// download/unzip Hermes from Github then.
371445
tasks.getByName("configureBuildForHermes").dependsOn(unzipHermes)
372446
tasks.getByName("prepareHeadersForPrefab").dependsOn(unzipHermes)
447+
tasks.getByName("configureBuildForHermesWithDebugger").dependsOn(unzipHermes)
448+
tasks.getByName("prepareHeadersForPrefabWithDebugger").dependsOn(unzipHermes)
373449
}
374450
tasks.getByName("preBuild").dependsOn(buildHermesC)
375451
tasks.getByName("preBuild").dependsOn(prepareHeadersForPrefab)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ val prepareHermesDependencies by
154154
tasks.registering {
155155
dependsOn(
156156
enableHermesBuild,
157-
":packages:react-native:ReactAndroid:hermes-engine:buildHermesLib",
158-
":packages:react-native:ReactAndroid:hermes-engine:prepareHeadersForPrefab",
157+
":packages:react-native:ReactAndroid:hermes-engine:buildHermesLibWithDebugger",
158+
":packages:react-native:ReactAndroid:hermes-engine:prepareHeadersForPrefabWithDebugger",
159159
)
160160
}
161161

0 commit comments

Comments
 (0)