Skip to content

Commit

Permalink
fix: properly cache sdk/hermes to improve build times
Browse files Browse the repository at this point in the history
  • Loading branch information
Riccardo Cipolleschi committed Jul 18, 2022
1 parent f3db6cc commit 4cab9d3
Showing 1 changed file with 117 additions and 48 deletions.
165 changes: 117 additions & 48 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ references:
gems_cache_key: &gems_cache_key v1-gems-{{ checksum "Gemfile.lock" }}
gradle_cache_key: &gradle_cache_key v1-gradle-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "ReactAndroid/gradle.properties" }}
hermes_cache_key: &hermes_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/hermes/hermesversion" }}
hermes_sdk_cache_key: &hermes_sdk_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "sdks/.hermes-cache-key-file" }}
hermes_sdk_cache_key: &hermes_sdk_cache_key v1-hermes-{{ checksum "sdks/.hermes-cache-key-file" }}
hermes_windows_cache_key: &hermes_windows_cache_key v1-hermes-{{ .Environment.CIRCLE_JOB }}-{{ checksum "tmp/hermes/hermesversion" }}
hermes_tarball_cache_key: &hermes_tarball_cache_key v1-hermes-tarball-{{ checksum "sdks/.hermes-cache-key-file" }}
pods_cache_key: &pods_cache_key v6-pods-{{ .Environment.CIRCLE_JOB }}-{{ checksum "packages/rn-tester/Podfile.lock.bak" }}-{{ checksum "packages/rn-tester/Podfile" }}
windows_yarn_cache_key: &windows_yarn_cache_key v1-win-yarn-cache-{{ arch }}-{{ checksum "yarn.lock" }}
yarn_cache_key: &yarn_cache_key v5-yarn-cache-{{ .Environment.CIRCLE_JOB }}
Expand Down Expand Up @@ -303,6 +304,49 @@ commands:
- sdks/hermesc
- sdks/hermes

with_hermes_tarball_cache_span:
parameters:
steps:
type: steps
set_tarball_path:
type: boolean
default: False
steps:
- run:
name: Setup Hermes cache
command: |
HERMES_CACHE_KEY_FILE="sdks/.hermes-cache-key-file"
if [ ! -f "$HERMES_CACHE_KEY_FILE" ]; then
git ls-remote https://github.com/facebook/hermes main | cut -f 1 > $HERMES_CACHE_KEY_FILE
fi
- restore_cache:
keys:
- *hermes_tarball_cache_key
- when:
condition: << parameters.set_tarball_path >>
steps:
- run:
name: Set HERMES_TARBALL_PATH if present
command: |
BASE_PATH=/tmp/hermes/hermes-runtime-darwin/
if [ ! -d $BASE_PATH ]; then
echo "Hermes tarball base path not present ($BASE_PATH). Build it from source."
return
fi
TARBALL=$(ls /tmp/hermes/hermes-runtime-darwin/)
TARBALL_PATH=$BASE_PATH$TARBALL
if [ ! -f $TARBALL_PATH]; then
echo "Hermes tarball not present ($TARBALL_PATH). Build it from source."
return
fi
echo 'export HERMES_ENGINE_TARBALL_PATH=$TARBALL_PATH' >> $BASH_ENV
- steps: << parameters.steps >>
- save_cache:
key: *hermes_tarball_cache_key
paths:
- /tmp/hermes/hermes-runtime-darwin/

# -------------------------
# JOBS
# -------------------------
Expand Down Expand Up @@ -492,7 +536,7 @@ jobs:
name: Setup the CocoaPods environment
command: bundle exec pod setup

- with_hermes_sdk_cache_span:
- with_hermes_tarball_cache_span:
steps:
- with_rntester_pods_cache_span:
steps:
Expand Down Expand Up @@ -738,7 +782,8 @@ jobs:
- brew_install:
package: cmake

- with_hermes_sdk_cache_span:
- with_hermes_tarball_cache_span:
set_tarball_path: True
steps:
- run:
name: Install CocoaPods dependencies
Expand Down Expand Up @@ -976,50 +1021,70 @@ jobs:
name: Install dependencies
command: |
brew install cmake
- run:
name: Build the Hermes iOS frameworks
command: |
cd ~/react-native/sdks/hermes
./utils/build-ios-framework.sh
- run:
name: Build the Hermes Mac frameworks
command: |
cd ~/react-native/sdks/hermes
./utils/build-mac-framework.sh
cp build_macosx/bin/hermesc /tmp/hermes/osx-bin/.
- run:
name: Package the Hermes Apple frameworks
command: |
cd ~/react-native/sdks/hermes
. ./utils/build-apple-framework.sh
mkdir -p /tmp/cocoapods-package-root/destroot
mkdir -p /tmp/hermes/output
cp -R ./destroot /tmp/cocoapods-package-root
cp LICENSE /tmp/cocoapods-package-root
tar -C /tmp/cocoapods-package-root/ -czvf /tmp/hermes/output/hermes-runtime-darwin-v$(get_release_version).tar.gz .
mkdir -p /tmp/hermes/hermes-runtime-darwin
cp /tmp/hermes/output/hermes-runtime-darwin-v$(get_release_version).tar.gz /tmp/hermes/hermes-runtime-darwin/.
- save_cache:
key: *hermes_cache_key
paths:
- ~/react-native/hermes/build_host_hermesc
- ~/react-native/hermes/build_iphoneos
- ~/react-native/hermes/build_catalyst
- ~/react-native/hermes/build_iphonesimulator
- ~/react-native/hermes/build_macosx
- ~/react-native/hermes/destroot
- store_artifacts:
path: /tmp/hermes/hermes-runtime-darwin/
- store_artifacts:
path: /tmp/hermes/osx-bin/
- persist_to_workspace:
root: /tmp/hermes/
paths:
- hermes-runtime-darwin
- osx-bin
- with_hermes_tarball_cache_span:
steps:
- run:
name: Build the Hermes iOS frameworks
command: |
if [[ -d "~/react-native/hermes/destroot" && -d "/tmp/hermes/hermes-runtime-darwin/" ]] then
echo "destroot and tarball exists. Skip building"
return
fi
echo "either destroot or the tarball does not exists. Build from source"
cd ~/react-native/sdks/hermes
./utils/build-ios-framework.sh
- run:
name: Build the Hermes Mac frameworks
command: |
if [[ -d "~/react-native/hermes/destroot" && -d "/tmp/hermes/hermes-runtime-darwin/" ]] then
echo "destroot and tarball exists. Skip building"
return
fi
echo "either destroot or the tarball does not exists. Build from source"
cd ~/react-native/sdks/hermes
./utils/build-mac-framework.sh
cp build_macosx/bin/hermesc /tmp/hermes/osx-bin/.
- run:
name: Package the Hermes Apple frameworks
command: |
if [[ -d "~/react-native/hermes/destroot" && -d "/tmp/hermes/hermes-runtime-darwin/" ]] then
echo "destroot and tarball exists. Skip building"
return
fi
echo "either destroot or the tarball does not exists. Build from source"
cd ~/react-native/sdks/hermes
. ./utils/build-apple-framework.sh
mkdir -p /tmp/cocoapods-package-root/destroot
mkdir -p /tmp/hermes/output
cp -R ./destroot /tmp/cocoapods-package-root
cp LICENSE /tmp/cocoapods-package-root
tar -C /tmp/cocoapods-package-root/ -czvf /tmp/hermes/output/hermes-runtime-darwin-v$(get_release_version).tar.gz .
mkdir -p /tmp/hermes/hermes-runtime-darwin
cp /tmp/hermes/output/hermes-runtime-darwin-v$(get_release_version).tar.gz /tmp/hermes/hermes-runtime-darwin/.
- save_cache:
key: *hermes_cache_key
paths:
- ~/react-native/hermes/build_host_hermesc
- ~/react-native/hermes/build_iphoneos
- ~/react-native/hermes/build_catalyst
- ~/react-native/hermes/build_iphonesimulator
- ~/react-native/hermes/build_macosx
- ~/react-native/hermes/destroot
- store_artifacts:
path: /tmp/hermes/hermes-runtime-darwin/
- store_artifacts:
path: /tmp/hermes/osx-bin/
- persist_to_workspace:
root: /tmp/hermes/
paths:
- hermes-runtime-darwin
- osx-bin

build_hermesc_windows:
executor:
Expand Down Expand Up @@ -1296,9 +1361,13 @@ workflows:
- test_ios_template:
requires:
- build_npm_package
- test_ios_rntester
- test_ios_rntester:
requires:
- build_hermes_macos
- test_ios:
run_unit_tests: true
requires:
- build_hermes_macos
# DISABLED: USE_FRAMEWORKS=1 not supported by Flipper
# - test_ios:
# name: test_ios_frameworks
Expand Down

0 comments on commit 4cab9d3

Please sign in to comment.