From 82b7e0f7f55a36f3b7f369478168982a9739a4bb Mon Sep 17 00:00:00 2001 From: Alex Hendrix Date: Mon, 22 Jul 2024 10:17:58 -0500 Subject: [PATCH] [Discord] Adding release hermesc publishing --- .../ReactAndroid/build.gradle.kts | 17 ++++++ .../hermes-engine/build.gradle.kts | 52 +++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/packages/react-native/ReactAndroid/build.gradle.kts b/packages/react-native/ReactAndroid/build.gradle.kts index 49b3d845f36afe..0b4dae69a614a3 100644 --- a/packages/react-native/ReactAndroid/build.gradle.kts +++ b/packages/react-native/ReactAndroid/build.gradle.kts @@ -526,6 +526,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:buildHermescReleaseBinary") + archiveFileName = "hermescForDiscord.zip" + from(layout.projectDirectory.dir("hermes-engine/build/hermesc-release/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 @@ -868,5 +879,11 @@ publishing { artifactId = "discord-rn-libs" artifact(tasks.named("createReactNdkLibraryZipArchiveForDiscord").get()) } + create("hermescReleaseZip") { + groupId = "com.facebook.react" + version = "test" + artifactId = "discord-hermesc-release" + artifact(tasks.named("createHermescReleaseZipArchiveForDiscord").get()) + } } } diff --git a/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts b/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts index 2f3d02be88d3b9..35767fb5326de0 100644 --- a/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts +++ b/packages/react-native/ReactAndroid/hermes-engine/build.gradle.kts @@ -59,6 +59,7 @@ val hermesDir = } val hermesBuildDir = File("$buildDir/hermes") val hermesCOutputBinary = File("$buildDir/hermes/bin/hermesc") +val hermescReleaseBuildDir = File("$buildDir/hermesc-release/") // This filetree represents the file of the Hermes build that we want as input/output // of the buildHermesC task. Gradle will compute the hash of files in the file tree @@ -156,6 +157,57 @@ 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) + commandLine( + windowsAwareCommandLine( + findCmakePath(cmakeVersion), + "-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) + commandLine( + windowsAwareCommandLine( + findCmakePath(cmakeVersion), + "--build", + hermescReleaseBuildDir.toString(), + "--target", + "hermesc", + "-j", + ndkBuildJobs + ) + ) + } + fun windowsAwareCommandLine(vararg commands: String): List { val result = if (Os.isFamily(Os.FAMILY_WINDOWS)) {