Skip to content

Commit

Permalink
[Discord] Adding release hermesc publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Flewp authored and joemun committed Dec 2, 2024
1 parent f3d7d73 commit 3249f89
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/react-native/ReactAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,17 @@ val createReactNdkLibraryZipArchiveForDiscord by
destinationDirectory.set(layout.projectDirectory)
}

// This is the task to run to create a .zip of hermesc for CI machines
val createHermescReleaseZipArchiveForDiscord by
tasks.registering(Zip::class) {
dependsOn(":packages:react-native:ReactAndroid:hermes-engine:buildHermesC")
archiveFileName = "hermescForDiscord.zip"
from(layout.projectDirectory.dir("hermes-engine/build/hermes/bin"))

// Place this .zip right into our ReactAndroid directory
destinationDirectory = layout.projectDirectory
}

repositories {
// Normally RNGP will set repositories for all modules,
// but when consumed from source, we need to re-declare
Expand Down Expand Up @@ -738,5 +749,11 @@ publishing {
artifactId = "discord-rn-libs"
artifact(tasks.named("createReactNdkLibraryZipArchiveForDiscord").get())
}
create<MavenPublication>("hermescReleaseZip") {
groupId = "com.facebook.react"
version = "test"
artifactId = "discord-hermesc-release"
artifact(tasks.named("createHermescReleaseZipArchiveForDiscord").get())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ val hermesBuildOutputFileTree =
"**/Makefile",
"**/link.txt")

// NOTE(flewp): These are separate build directories for configuring/building a release version of hermesc
val hermescReleaseBuildDir = File("$buildDir/hermesc-release")
val hermescReleaseOutputBinary = File("$buildDir/hermesc-release/bin/hermesc")
val hermescReleaseBuildOutputFileTree =
fileTree(hermescReleaseBuildDir.toString())
.include(
"**/*.make",
"**/*.cmake",
"**/*.marks",
"**/compiler_depends.ts",
"**/Makefile",
"**/link.txt")

var hermesVersion = "main"
val hermesVersionFile = File(reactNativeRootDir, "sdks/.hermesversion")

Expand Down Expand Up @@ -147,7 +160,8 @@ val configureBuildForHermes by
".",
"-B",
hermesBuildDir.toString(),
"-DJSI_DIR=" + jsiDir.absolutePath))
"-DJSI_DIR=" + jsiDir.absolutePath,
"-DICU_FOUND=1"))
}

val buildHermesC by
Expand Down Expand Up @@ -178,6 +192,63 @@ val prepareHeadersForPrefab by
into(prefabHeadersDir)
}

/**
NOTE(Flewp): Taken from https://github.com/facebook/hermes/blob/9f8603b9886c957e0ccead61fe4380616188bbb4/.circleci/config.yml#L115-L123
The idea here is to replicate building the hermesc binary historically provided by the hermes-engine-cli package.
Config Step
cmake -S hermes -B build -DHERMES_STATIC_LINK=ON -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=True -DCMAKE_CXX_FLAGS=-s -DCMAKE_C_FLAGS=-s \
-DCMAKE_EXE_LINKER_FLAGS="-Wl,--whole-archive -lpthread -Wl,--no-whole-archive" \
-DHERMES_ENABLE_DEBUGGER=False
Build Step
cmake --build build --target check-hermes hermes hvm hbcdump hermesc
*/
val configureBuildForHermescReleaseBinary by
tasks.registering(Exec::class) {
dependsOn(unzipHermes)
workingDir(hermesDir)
inputs.dir(hermesDir)
outputs.files(hermescReleaseBuildOutputFileTree)
commandLine(
windowsAwareCommandLine(
cmakeBinaryPath,
"-S",
".",
"-B",
hermescReleaseBuildDir.toString(),
"-DHERMES_STATIC_LINK=ON",
"-DCMAKE_BUILD_TYPE=Release",
"-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=True",
"-DCMAKE_CXX_FLAGS=-s",
"-DCMAKE_C_FLAGS=-s",
"-DHERMES_ENABLE_DEBUGGER=False",
"-DJSI_DIR=" + jsiDir.absolutePath,
"-DICU_FOUND=1"
)
)
}

val buildHermescReleaseBinary by
tasks.registering(Exec::class) {
dependsOn(configureBuildForHermescReleaseBinary)
workingDir(hermesDir)
inputs.files(hermescReleaseBuildOutputFileTree)
outputs.file(hermescReleaseOutputBinary)
commandLine(
windowsAwareCommandLine(
cmakeBinaryPath,
"--build",
hermescReleaseBuildDir.toString(),
"--target",
"hermesc",
"-j",
ndkBuildJobs
)
)
}

fun windowsAwareCommandLine(vararg commands: String): List<String> {
val result =
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
Expand Down

0 comments on commit 3249f89

Please sign in to comment.