Skip to content

Commit 51f2027

Browse files
hramosfacebook-github-bot
authored andcommitted
Circle CI: Reduce build_hermes_macos Hermes SDK cache size by 75% (#34886)
Summary: Pull Request resolved: #34886 ## Reduced cache size The `build_hermes_macos` job can spend over 20 minutes restoring cached build artifacts (over 5 GB), when only `build_macosx` and `destroot` are required to be cached: `build_macosx` as it may contain a pre-built `hermesc` from previous builds, and `destroot` which contains the artifacts for previous iOS/macOS builds. This is the `build_hermes_macos` Restore Cache step, before the changes in this diff: ``` Found a cache from build 308044 at v1-hermes-build_hermes_macos-debug-PEiMHp9XQ13KtYFQMKoT27DmHkkoxOi_PJUyW7PacZE= Size: 5.2 GiB Cached paths: * /Users/distiller/react-native/sdks/hermes/build_host_hermesc * /Users/distiller/react-native/sdks/hermes/build_iphoneos * /Users/distiller/react-native/sdks/hermes/build_catalyst * /Users/distiller/react-native/sdks/hermes/build_iphonesimulator * /Users/distiller/react-native/sdks/hermes/build_macosx * /Users/distiller/react-native/sdks/hermes/destroot Downloading cache archive... Unarchiving cache... ``` Size: 5.2 GiB Time to restore cache: 183s This is the `build_hermes_macos` Restore Cache step, after the changes in this diff: ``` Found a cache from build 310128 at v2-hermes-build_hermes_macos-debug-e7WmoA0+mfveXq1zsMYpgR6BYqVuuDjmVeLLyjqPJWk= Size: 1.3 GiB Cached paths: * /Users/distiller/react-native/sdks/hermes/build_macosx * /Users/distiller/react-native/sdks/hermes/destroot Downloading cache archive... Unarchiving cache... ``` Size: 1.3 GiB Time to restore cache: 42s **This is a size reduction of 75%, and execution time reduction of 77%.** This savings will apply to every workflow that runs afterwards until the Hermes cache is invalidated due to a new commit landing in `facebook/hermes`. ## Added `export_hermesc` As part of the work mentioned above, a reusable `export_hermesc` command was added, which will export hermesc for use in downstream steps. Either of the macOS or iOS build scripts will generate this binary. As we now only cache the macOS build dir, that version is loaded from cache by default if available: - If the cache contains hermesc, both the macOS and iOS builds will use it. - If the cache does not contain hermesc, then the iOS job will use the hermesc that was built by the macOS job previously. - The `export_hermesc` command will work regardless of the order of the Hermes build scripts ## Refactoring of magic strings into reusable yaml references Some additional changes to the Circle CI config were done in order to reduce repetition of artifacts/cache paths that are re-used across workflows. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D40153737 fbshipit-source-id: b9f07302ccc9bac1ce72a09b944d3210e6db2ec1
1 parent f1f7824 commit 51f2027

File tree

1 file changed

+78
-33
lines changed

1 file changed

+78
-33
lines changed

.circleci/config.yml

Lines changed: 78 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ references:
2828
/tmp/hermes
2929
hermes_tarball_artifacts_dir: &hermes_tarball_artifacts_dir
3030
/tmp/hermes/hermes-runtime-darwin
31+
hermes_osxbin_artifacts_dir: &hermes_osxbin_artifacts_dir
32+
/tmp/hermes/osx-bin
3133
attach_hermes_workspace: &attach_hermes_workspace
3234
attach_workspace:
3335
at: *hermes_workspace_root
@@ -50,8 +52,8 @@ references:
5052
gems_cache_key: &gems_cache_key v1-gems-{{ checksum "Gemfile.lock" }}
5153
gradle_cache_key: &gradle_cache_key v1-gradle-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "ReactAndroid/gradle.properties" }}
5254
hermes_workspace_cache_key: &hermes_workspace_cache_key v4-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }}
53-
hermes_workspace_debug_cache_key: &hermes_workspace_debug_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-debug-{{ checksum "/tmp/hermes/hermesversion" }}
54-
hermes_workspace_release_cache_key: &hermes_workspace_release_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-release-{{ checksum "/tmp/hermes/hermesversion" }}
55+
hermes_workspace_debug_cache_key: &hermes_workspace_debug_cache_key v2-hermes-{{ .Environment.CIRCLE_JOB }}-debug-{{ checksum "/tmp/hermes/hermesversion" }}
56+
hermes_workspace_release_cache_key: &hermes_workspace_release_cache_key v2-hermes-{{ .Environment.CIRCLE_JOB }}-release-{{ checksum "/tmp/hermes/hermesversion" }}
5557
hermes_windows_cache_key: &hermes_windows_cache_key v3-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "tmp/hermes/hermesversion" }}
5658
hermes_tarball_debug_cache_key: &hermes_tarball_debug_cache_key v2-hermes-tarball-debug-{{ checksum "/tmp/hermes/hermesversion" }}
5759
hermes_tarball_release_cache_key: &hermes_tarball_release_cache_key v1-hermes-tarball-release-{{ checksum "/tmp/hermes/hermesversion" }}
@@ -61,10 +63,6 @@ references:
6163

6264
cache_paths:
6365
hermes_workspace_macos_cache_paths: &hermes_workspace_macos_cache_paths
64-
- ~/react-native/sdks/hermes/build_host_hermesc
65-
- ~/react-native/sdks/hermes/build_iphoneos
66-
- ~/react-native/sdks/hermes/build_catalyst
67-
- ~/react-native/sdks/hermes/build_iphonesimulator
6866
- ~/react-native/sdks/hermes/build_macosx
6967
- ~/react-native/sdks/hermes/destroot
7068
hermes_tarball_cache_paths: &hermes_tarball_cache_paths
@@ -335,6 +333,51 @@ commands:
335333
key: *hermes_tarball_release_cache_key
336334
paths: *hermes_tarball_cache_paths
337335

336+
with_hermesc_span:
337+
description: "Makes hermesc available to the provided steps, if hermesc is present."
338+
parameters:
339+
steps:
340+
type: steps
341+
steps:
342+
- export_hermesc
343+
- steps: << parameters.steps >>
344+
- export_hermesc
345+
346+
export_hermesc:
347+
description: "Configures hermesc for use in Hermes builds when possible. The binary is built by either of the macOS or iOS builds, and may be cached by previous builds."
348+
parameters:
349+
artifacts_dir:
350+
type: string
351+
default: *hermes_osxbin_artifacts_dir
352+
steps:
353+
- run:
354+
name: "Export HermesC if available"
355+
command: |
356+
hermesc_artifacts_path=<< parameters.artifacts_dir >>/hermesc
357+
hermesc_bin_path=bin/hermesc
358+
hermes_build_dir_macos=$(pwd)/sdks/hermes/build_macosx
359+
hermes_build_dir_ios=$(pwd)/sdks/hermes/build_iphoneos
360+
361+
function export_hermesc_cmake_path {
362+
build_dir=$1
363+
hermesc_bin=$build_dir/$hermesc_bin_path
364+
cmake_path=$build_dir/ImportHermesc.cmake
365+
366+
if [[ -f $cmake_path ]]; then
367+
echo "export HERMES_OVERRIDE_HERMESC_PATH=$cmake_path" >> $BASH_ENV
368+
fi
369+
370+
if [[ ! -f $hermesc_artifacts_path ]]; then
371+
cp $hermesc_bin $hermesc_artifacts_path
372+
fi
373+
}
374+
375+
if [[ -f $hermes_build_dir_macos/$hermesc_bin_path ]]; then
376+
export_hermesc_cmake_path $hermes_build_dir_macos
377+
elif [[ -f $hermes_build_dir_ios/$hermesc_bin_path ]]; then
378+
export_hermesc_cmake_path $hermes_build_dir_ios
379+
fi
380+
338381
# -------------------------
339382
# JOBS
340383
# -------------------------
@@ -994,7 +1037,7 @@ jobs:
9941037
path: ~/react-native/coverage/
9951038

9961039
# -------------------------
997-
# JOBS: Build hermesc
1040+
# JOBS: Build Hermes
9981041
# -------------------------
9991042
prepare_hermes_workspace:
10001043
docker:
@@ -1100,6 +1143,7 @@ jobs:
11001143
environment:
11011144
- HERMES_WS_DIR: *hermes_workspace_root
11021145
- HERMES_TARBALL_ARTIFACTS_DIR: *hermes_tarball_artifacts_dir
1146+
- HERMES_OSXBIN_ARTIFACTS_DIR: *hermes_osxbin_artifacts_dir
11031147
steps:
11041148
- checkout_code_with_cache
11051149
- run_yarn
@@ -1121,25 +1165,27 @@ jobs:
11211165
- run:
11221166
name: Set up workspace
11231167
command: |
1124-
mkdir -p /tmp/hermes/osx-bin
1125-
mkdir -p ~/react-native/sdks/hermes
1126-
cp -r $HERMES_WS_DIR/hermes/* ~/react-native/sdks/hermes/.
1168+
mkdir -p $HERMES_OSXBIN_ARTIFACTS_DIR ./sdks/hermes
1169+
cp -r $HERMES_WS_DIR/hermes/* ./sdks/hermes/.
11271170
- brew_install:
11281171
package: cmake
11291172
- with_hermes_tarball_cache_span:
11301173
flavor: << parameters.flavor >>
11311174
steps:
1132-
- run:
1133-
name: Build the Hermes iOS frameworks
1134-
command: |
1135-
cd ~/react-native/sdks/hermes
1136-
BUILD_TYPE="<< parameters.flavor >>" ./utils/build-ios-framework.sh
1137-
- run:
1138-
name: Build the Hermes Mac frameworks
1139-
command: |
1140-
cd ~/react-native/sdks/hermes
1141-
BUILD_TYPE="<< parameters.flavor >>" ./utils/build-mac-framework.sh
1142-
cp build_macosx/bin/hermesc /tmp/hermes/osx-bin/.
1175+
- with_hermesc_span:
1176+
steps:
1177+
- run:
1178+
name: Build the Hermes Mac frameworks
1179+
command: |
1180+
cd ./sdks/hermes || exit 1
1181+
BUILD_TYPE="<< parameters.flavor >>" ./utils/build-mac-framework.sh
1182+
- with_hermesc_span:
1183+
steps:
1184+
- run:
1185+
name: Build the Hermes iOS frameworks
1186+
command: |
1187+
cd ./sdks/hermes || exit 1
1188+
BUILD_TYPE="<< parameters.flavor >>" ./utils/build-ios-framework.sh
11431189
- run:
11441190
name: Package the Hermes Apple frameworks
11451191
command: |
@@ -1149,35 +1195,34 @@ jobs:
11491195
TARBALL_OUTPUT_DIR=$(mktemp -d /tmp/hermes-tarball-output-XXXXXXXX)
11501196
11511197
# get_release_version() is defined in build-apple-framework.sh
1152-
cd ~/react-native/sdks/hermes
1153-
BUILD_TYPE=$BUILD_TYPE source ./utils/build-apple-framework.sh
1154-
RELEASE_VERSION=$(get_release_version)
1155-
1156-
cd ~/react-native
1198+
pushd ./sdks/hermes || exit 1
1199+
BUILD_TYPE=$BUILD_TYPE source ./utils/build-apple-framework.sh
1200+
RELEASE_VERSION=$(get_release_version)
1201+
popd
11571202
11581203
TARBALL_FILENAME=$(node ./scripts/hermes/get-tarball-name.js --buildType "$BUILD_TYPE" --releaseVersion "$RELEASE_VERSION")
11591204
11601205
echo "Packaging Hermes Apple frameworks for $BUILD_TYPE build type"
11611206
11621207
TARBALL_OUTPUT_PATH=$(node ./scripts/hermes/create-tarball.js \
1163-
--inputDir ~/react-native/sdks/hermes \
1208+
--inputDir ./sdks/hermes \
11641209
--buildType "$BUILD_TYPE" \
11651210
--releaseVersion "$RELEASE_VERSION" \
1166-
--outputDir "$TARBALL_OUTPUT_DIR")
1211+
--outputDir $TARBALL_OUTPUT_DIR)
11671212
11681213
echo "Hermes tarball saved to $TARBALL_OUTPUT_PATH"
11691214
1170-
mkdir -p "$HERMES_TARBALL_ARTIFACTS_DIR"
1171-
cp "$TARBALL_OUTPUT_PATH" "$HERMES_TARBALL_ARTIFACTS_DIR/."
1215+
mkdir -p $HERMES_TARBALL_ARTIFACTS_DIR
1216+
cp $TARBALL_OUTPUT_PATH $HERMES_TARBALL_ARTIFACTS_DIR/.
11721217
11731218
# Make a copy of the debug tarball and use the old filename.
11741219
# This is necessary to support patch releases in versions of
11751220
# React Native that expect a single tarball.
11761221
# TODO: Remove once 0.70.x and 0.69.x are no longer being patched.
11771222
if [[ $BUILD_TYPE == "Debug" ]]; then
11781223
OLD_TARBALL_FILENAME="hermes-runtime-darwin-v$RELEASE_VERSION.tar.gz"
1179-
cp "$HERMES_TARBALL_ARTIFACTS_DIR/$TARBALL_FILENAME" "$HERMES_TARBALL_ARTIFACTS_DIR/$OLD_TARBALL_FILENAME"
1180-
echo "$OLD_TARBALL_FILENAME is a copy of $TARBALL_FILENAME, provided for backward compatibility." >> "$HERMES_TARBALL_ARTIFACTS_DIR/README.txt"
1224+
cp $HERMES_TARBALL_ARTIFACTS_DIR/$TARBALL_FILENAME $HERMES_TARBALL_ARTIFACTS_DIR/$OLD_TARBALL_FILENAME
1225+
echo "$OLD_TARBALL_FILENAME is a copy of $TARBALL_FILENAME, provided for backward compatibility." >> $HERMES_TARBALL_ARTIFACTS_DIR/README.txt
11811226
fi
11821227
- when:
11831228
condition:
@@ -1196,7 +1241,7 @@ jobs:
11961241
- store_artifacts:
11971242
path: *hermes_tarball_artifacts_dir
11981243
- store_artifacts:
1199-
path: /tmp/hermes/osx-bin/
1244+
path: *hermes_osxbin_artifacts_dir
12001245
- persist_to_workspace:
12011246
root: /tmp/hermes/
12021247
paths:

0 commit comments

Comments
 (0)