Skip to content

Commit

Permalink
Update the hermesc output to be inside the $buildDir
Browse files Browse the repository at this point in the history
Summary:
Currently, we build Hermes by specifying the Cmake flag `-B ./hermes`. That means
that the output out the build is going to be placed along side the source code.

This is fine, as long as the user doesn't use the `REACT_NATIVE_OVERRIDE_HERMES_DIR`,
which is used inside the Hermes CI. In that case, the source location of Hermes can be
changed, leading to scenarios where `hermesc` can't be found.

Here I'm changing the flag to be `-B $buildDir/hermes`. Therefore the build output
will always be located within the `./ReactAndroid/hermes-engine/build` folder.
This is a more robust solution as the build output will be encapsulated within the
`build/` folder.

Changelog:i
[Internal] [Changed] - Update the hermesc output to be inside the $buildDir

Reviewed By: cipolleschi

Differential Revision: D35964402

fbshipit-source-id: aa7e0775b282897d5a99c1c46265884d19c5f289
  • Loading branch information
cortinico authored and facebook-github-bot committed Apr 27, 2022
1 parent 24bb7f7 commit c11785b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
8 changes: 4 additions & 4 deletions ReactAndroid/hermes-engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def findCmakePath(cmakeVersion) {
}
return "cmake"
}
logger.error("CMAKE PATH ${findCmakePath(cmakeVersion)}")

def reactNativeRootDir = project(':ReactAndroid').projectDir.parent;
def customDownloadDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
Expand All @@ -40,6 +39,7 @@ def downloadsDir = customDownloadDir ? new File(customDownloadDir) : new File(re
// but you can provide an override for where the hermes source code is located.
def overrideHermesDir = System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR") != null
def hermesDir = System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR") ?: new File(reactNativeRootDir, "sdks/hermes")
def hermesBuildDir = new File("$buildDir/hermes")

def hermesVersion = "main"
def hermesVersionFile = new File(reactNativeRootDir, "sdks/.hermesversion")
Expand Down Expand Up @@ -86,12 +86,12 @@ task unzipHermes(dependsOn: downloadHermes, type: Copy) {

task configureBuildForHermes(type: Exec) {
workingDir(hermesDir)
commandLine(windowsAwareCommandLine(findCmakePath(cmakeVersion), "-S", ".", "-B", "./build", "-DJSI_DIR=" + jsiDir.absolutePath))
commandLine(windowsAwareCommandLine(findCmakePath(cmakeVersion), "-S", ".", "-B", hermesBuildDir.toString(), "-DJSI_DIR=" + jsiDir.absolutePath))
}

task buildHermes(dependsOn: configureBuildForHermes, type: Exec) {
workingDir(hermesDir)
commandLine(windowsAwareCommandLine(findCmakePath(cmakeVersion), "--build", "./build", "--target", "hermesc", "-j", ndkBuildJobs))
commandLine(windowsAwareCommandLine(findCmakePath(cmakeVersion), "--build", hermesBuildDir.toString(), "--target", "hermesc", "-j", ndkBuildJobs))
}

task prepareHeadersForPrefab(type: Copy) {
Expand Down Expand Up @@ -138,7 +138,7 @@ android {
arguments "-DANDROID_STL=c++_shared"
arguments "-DANDROID_PIE=True"
arguments "-DANDROID_LD=lld"
arguments "-DIMPORT_HERMESC=${new File(hermesDir, "build/ImportHermesc.cmake").toString()}"
arguments "-DIMPORT_HERMESC=${new File(hermesBuildDir, "ImportHermesc.cmake").toString()}"
arguments "-DJSI_DIR=${jsiDir}"
arguments "-DHERMES_SLOW_DEBUG=False"
arguments "-DHERMES_BUILD_SHARED_JSI=True"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ internal fun projectPathToLibraryName(projectPath: String): String =
private const val HERMESC_IN_REACT_NATIVE_PATH =
"node_modules/react-native/sdks/hermesc/%OS-BIN%/hermesc"
private const val HERMESC_BUILT_FROM_SOURCE_PATH =
"node_modules/react-native/sdks/hermes/build/bin/hermesc"
"node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc"
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ class PathUtilsTest {

@Test
fun detectOSAwareHermesCommand_withHermescBuiltLocally() {
tempFolder.newFolder("node_modules/react-native/sdks/hermes/build/bin/")
val expected = tempFolder.newFile("node_modules/react-native/sdks/hermes/build/bin/hermesc")
tempFolder.newFolder("node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/")
val expected =
tempFolder.newFile(
"node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc")

assertEquals(expected.toString(), detectOSAwareHermesCommand(tempFolder.root, ""))
}
Expand Down Expand Up @@ -206,8 +208,10 @@ class PathUtilsTest {
@Test
@WithOs(OS.MAC)
fun detectOSAwareHermesCommand_withoutProvidedCommand_builtHermescTakesPrecedence() {
tempFolder.newFolder("node_modules/react-native/sdks/hermes/build/bin/")
val expected = tempFolder.newFile("node_modules/react-native/sdks/hermes/build/bin/hermesc")
tempFolder.newFolder("node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/")
val expected =
tempFolder.newFile(
"node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc")
tempFolder.newFolder("node_modules/react-native/sdks/hermesc/osx-bin/")
tempFolder.newFile("node_modules/react-native/sdks/hermesc/osx-bin/hermesc")

Expand All @@ -217,7 +221,9 @@ class PathUtilsTest {
@Test
fun getBuiltHermescFile_withoutOverride() {
assertEquals(
File(tempFolder.root, "node_modules/react-native/sdks/hermes/build/bin/hermesc"),
File(
tempFolder.root,
"node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc"),
getBuiltHermescFile(tempFolder.root, ""))
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rn-tester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ react {
root = rootDir
inputExcludes = ["android/**", "./**", ".gradle/**"]
composeSourceMapsPath = "$rootDir/scripts/compose-source-maps.js"
hermesCommand = "$rootDir/sdks/hermes/build/bin/hermesc"
hermesCommand = "$rootDir/ReactAndroid/hermes-engine/build/hermes/bin/hermesc"
enableHermesForVariant { def v -> v.name.contains("hermes") }

// Codegen Configs
Expand Down
5 changes: 4 additions & 1 deletion react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def getHermesCommand = {
// Also note that user can override the hermes source location with
// the `REACT_NATIVE_OVERRIDE_HERMES_DIR` env variable.
def hermesOverrideDir = System.getenv("REACT_NATIVE_OVERRIDE_HERMES_DIR")
def builtHermesc = hermesOverrideDir ? new File(hermesOverrideDir, "build/bin/hermesc") : new File(reactRoot, "node_modules/react-native/sdks/hermes/build/bin/hermesc")
def builtHermesc = hermesOverrideDir ?
new File(hermesOverrideDir, "build/bin/hermesc") :
new File(reactRoot, "node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/bin/hermesc")

if (builtHermesc.exists()) {
return builtHermesc.getAbsolutePath()
}
Expand Down

0 comments on commit c11785b

Please sign in to comment.