Skip to content

Commit e9d5900

Browse files
coadofacebook-github-bot
authored andcommitted
Set hermes release version in static_h (#1791)
Summary: Pull Request resolved: #1791 This diff sets version in `CMakeLists.txt` to `1.0.0` and configures build to pass `-DHERMES_RELEASE_VERSION=for RN ${hermesReleaseVersion}` where `hermesReleaseVersion` is a version read from the `hermes-compiler/package.json`. Reviewed By: cortinico Differential Revision: D82313203 fbshipit-source-id: 4c66368a077e19083d75bd3ae36380c2c5a1ded1
1 parent ff558b7 commit e9d5900

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ endif()
6565
# - npm/package.json
6666
# - hermes-engine.podspec
6767
project(Hermes
68-
VERSION 0.12.0
68+
VERSION 1.0.0
6969
LANGUAGES C CXX)
7070

7171
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.hermes.helpers.internal
9+
10+
import groovy.json.JsonSlurper
11+
import java.io.File
12+
import org.gradle.api.Project
13+
14+
data class PackageJson(val version: String)
15+
16+
class SerializeHermesCompilerPackageJson(project: Project) {
17+
private val serializedPackageJson = run {
18+
val packageJsonFile = File(project.rootDir.parentFile, "npm/hermes-compiler/package.json")
19+
if (!packageJsonFile.exists()) {
20+
throw IllegalStateException("package.json file not found at $packageJsonFile")
21+
}
22+
23+
val jsonSlurper = JsonSlurper().parseText(packageJsonFile.readText()) as Map<String, Any>
24+
val version =
25+
jsonSlurper["version"] as? String
26+
?: throw IllegalStateException(
27+
"Expected version to be a string in package.json, but got ${jsonSlurper["version"]}"
28+
)
29+
PackageJson(version)
30+
}
31+
32+
val hermesReleaseVersion = serializedPackageJson.version
33+
}

android/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import com.facebook.hermes.helpers.internal.SerializeHermesCompilerPackageJson
89
import com.facebook.hermes.tasks.internal.CustomExecTask
910
import org.apache.tools.ant.taskdefs.condition.Os
1011

@@ -21,6 +22,8 @@ group = "com.facebook.hermes"
2122

2223
version = project.findProperty("VERSION_NAME")?.toString()!!
2324

25+
val hermesReleaseVersion = SerializeHermesCompilerPackageJson(project).hermesReleaseVersion
26+
2427
val cmakeVersion = System.getenv("CMAKE_VERSION") ?: libs.versions.cmake.get()
2528
val cmakePath = "${getSDKPath()}/cmake/$cmakeVersion"
2629
val cmakeBinaryPath = "${cmakePath}/bin/cmake"
@@ -222,7 +225,7 @@ android {
222225
"-DIMPORT_HOST_COMPILERS=${File(hermesBuildDir, "ImportHostCompilers.cmake").toString()}",
223226
"-DJSI_DIR=${jsiDir}",
224227
"-DHERMES_BUILD_SHARED_JSI=True",
225-
// "-DHERMES_RELEASE_VERSION=for RN ${version}",
228+
"-DHERMES_RELEASE_VERSION=${hermesReleaseVersion}",
226229
"-DCMAKE_INTERPROCEDURAL_OPTIMIZATION=True",
227230
// We intentionally build Hermes with Intl support only. This is to simplify
228231
// the build setup and to avoid overcomplicating the build-type matrix.

utils/build-apple-framework-rn.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ IMPORT_HERMESC_PATH=${HERMES_OVERRIDE_HERMESC_PATH:-$PWD/build_host_hermesc/Impo
1313
BUILD_TYPE=${BUILD_TYPE:-Debug}
1414

1515
HERMES_PATH="$CURR_SCRIPT_DIR/.."
16+
HERMES_COMPILER_PACKAGE_PATH="$HERMES_PATH/npm/hermes-compiler"
1617

1718
NUM_CORES=$(sysctl -n hw.ncpu)
1819

@@ -43,6 +44,24 @@ function get_mac_deployment_target {
4344
use_env_var "${MAC_DEPLOYMENT_TARGET}" "MAC_DEPLOYMENT_TARGET"
4445
}
4546

47+
function get_release_version {
48+
local package_json_path="$HERMES_COMPILER_PACKAGE_PATH/package.json"
49+
if [[ -f "$package_json_path" ]]; then
50+
local version
51+
version=$(node -e "console.log(JSON.parse(require('fs').readFileSync('$package_json_path', 'utf8')).version)" 2>/dev/null)
52+
if [[ -n "$version" ]]; then
53+
echo "$version"
54+
return
55+
else
56+
echo >&2 "Error: Failed to read version from $package_json_path"
57+
exit 1
58+
fi
59+
else
60+
echo >&2 "Error: Package file not found at $package_json_path"
61+
exit 1
62+
fi
63+
}
64+
4665
# Build host hermes compiler for internal bytecode
4766
function build_host_hermesc {
4867
echo "Building hermesc"
@@ -98,6 +117,7 @@ function configure_apple_framework {
98117
-DCMAKE_C_FLAGS:STRING="-gdwarf" \
99118
-DIMPORT_HOST_COMPILERS:PATH="$IMPORT_HERMESC_PATH" \
100119
-DJSI_DIR="$JSI_PATH" \
120+
-DHERMES_RELEASE_VERSION="$(get_release_version)" \
101121
-DCMAKE_BUILD_TYPE="$cmake_build_type" \
102122
$boost_context_flag
103123
popd > /dev/null || exit 1

0 commit comments

Comments
 (0)