Skip to content

Commit fbe5ed9

Browse files
kraenhansenclaude
andcommitted
Add a prebuilt-hermes command and a workflow that publishes its archive (#440)
* Add a prebuilt-hermes command and a workflow that publishes its archive Building Hermes for Apple platforms is the expensive part of an iOS build, and it only changes when the pinned commit does. Build it once into an archive in the destroot layout hermes-engine.podspec expects from HERMES_ENGINE_TARBALL_PATH, and publish it as a release asset keyed by the pinned commit. Nothing consumes the archive yet — pod install still builds Hermes from source. This lands the command and the publishing workflow first, so the workflow is dispatchable and an asset exists before anything depends on it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UkNbgdyuKgHaFwT27RahGH * Trigger CI with the labels attached The workflow's pull_request trigger doesn't fire on `labeled`, so the label-gated jobs need a synchronize event to be evaluated against. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UkNbgdyuKgHaFwT27RahGH --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent ddfcded commit fbe5ed9

6 files changed

Lines changed: 671 additions & 81 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
"react-native-node-api": minor
3+
---
4+
5+
Add a `prebuilt-hermes` command, which resolves an archive of the pinned Hermes
6+
commit prebuilt for Apple platforms and prints its path. The archive holds the
7+
`destroot` layout React Native's `hermes-engine.podspec` expects from a tarball
8+
pointed at by `HERMES_ENGINE_TARBALL_PATH`, so an app that sets that variable
9+
vendors the prebuilt frameworks rather than compiling Hermes as part of its own
10+
build.
11+
12+
It is resolved from a local cache, then from a release asset published for the
13+
pinned commit, and only built locally if neither has it. Its name covers
14+
everything that changes its contents — the pinned commit, the React Native
15+
version whose `ReactCommon/jsi` it is compiled against, the build type and the
16+
platforms — so a stale archive can never be mistaken for a matching one.
17+
18+
Nothing consumes this yet: `pod install` still builds Hermes from source.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Hermes prebuilt
2+
3+
# Builds the pinned Hermes for Apple platforms and publishes it as a release
4+
# asset, so `pod install` downloads it instead of compiling Hermes as part of
5+
# every app build. The asset is keyed by everything that changes its contents,
6+
# so a bumped pin publishes alongside the previous one rather than replacing it.
7+
8+
env:
9+
GIT_CONFIG_COUNT: 1
10+
GIT_CONFIG_KEY_0: "url.https://github.com/.insteadOf"
11+
GIT_CONFIG_VALUE_0: "git@github.com:"
12+
13+
on:
14+
workflow_dispatch:
15+
push:
16+
branches:
17+
- main
18+
- next
19+
paths:
20+
- "packages/host/src/node/cli/hermes.ts"
21+
- "packages/host/src/node/cli/hermes-prebuilt.ts"
22+
- ".github/workflows/hermes-prebuilt.yml"
23+
24+
# Two runs publishing the same tag would race on creating the release.
25+
concurrency:
26+
group: ${{ github.workflow }}
27+
28+
jobs:
29+
publish:
30+
name: Publish prebuilt Hermes
31+
runs-on: macos-latest
32+
permissions:
33+
contents: write
34+
steps:
35+
- uses: actions/checkout@v7
36+
- uses: actions/setup-node@v7
37+
with:
38+
node-version: lts/krypton
39+
- uses: pnpm/action-setup@v6
40+
with:
41+
cache: true
42+
- run: pnpm install
43+
- run: pnpm run build
44+
# Resolved from the test app so the archive is built against the React
45+
# Native version this repository actually pins.
46+
- name: Resolve prebuilt Hermes name
47+
id: hermes
48+
working-directory: apps/test-app
49+
run: |
50+
echo "archive=$(pnpm exec react-native-node-api prebuilt-hermes --print name)" >> "$GITHUB_OUTPUT"
51+
echo "tag=$(pnpm exec react-native-node-api prebuilt-hermes --print tag)" >> "$GITHUB_OUTPUT"
52+
- name: Cache prebuilt Hermes
53+
uses: actions/cache@v6
54+
with:
55+
path: ~/Library/Caches/react-native-node-api/hermes-prebuilt
56+
key: ${{ steps.hermes.outputs.archive }}
57+
# --no-download so a re-run rebuilds rather than round-tripping the asset
58+
# it is about to publish.
59+
- name: Build prebuilt Hermes
60+
id: build
61+
working-directory: apps/test-app
62+
run: echo "path=$(pnpm exec react-native-node-api prebuilt-hermes --no-download)" >> "$GITHUB_OUTPUT"
63+
# --latest=false keeps these out of the "latest release" slot, which
64+
# belongs to the package releases changesets publishes.
65+
- name: Publish as a release asset
66+
env:
67+
GH_TOKEN: ${{ github.token }}
68+
TAG: ${{ steps.hermes.outputs.tag }}
69+
ARCHIVE_PATH: ${{ steps.build.outputs.path }}
70+
run: |
71+
if ! gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
72+
gh release create "$TAG" \
73+
--repo "$GITHUB_REPOSITORY" \
74+
--title "Prebuilt Hermes ($TAG)" \
75+
--notes "Hermes, built for Apple platforms from the commit pinned in \`packages/host/src/node/cli/hermes.ts\`. Downloaded by \`react-native-node-api prebuilt-hermes\` and injected into the app's \`pod install\` through \`HERMES_ENGINE_TARBALL_PATH\`." \
76+
--latest=false
77+
fi
78+
gh release upload "$TAG" "$ARCHIVE_PATH" --repo "$GITHUB_REPOSITORY" --clobber

‎docs/CLI.md‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,29 @@ npx react-native-node-api <command> [options]
99
Run `npx react-native-node-api help` or `npx react-native-node-api help <command>` to see this same information from the CLI itself.
1010

1111
> [!NOTE]
12-
> This document is hand-written from the [Commander](https://github.com/tj/commander.js) program definition in [`packages/host/src/node/cli/program.ts`](../packages/host/src/node/cli/program.ts) (with the `vendor-hermes` command defined in [`hermes.ts`](../packages/host/src/node/cli/hermes.ts)). It needs to be kept in sync by hand whenever a command or its options change.
12+
> This document is hand-written from the [Commander](https://github.com/tj/commander.js) program definition in [`packages/host/src/node/cli/program.ts`](../packages/host/src/node/cli/program.ts) (with the `vendor-hermes` command defined in [`hermes.ts`](../packages/host/src/node/cli/hermes.ts) and `prebuilt-hermes` in [`hermes-prebuilt.ts`](../packages/host/src/node/cli/hermes-prebuilt.ts)). It needs to be kept in sync by hand whenever a command or its options change.
13+
14+
## `prebuilt-hermes [from]`
15+
16+
Resolves an archive of the pinned Hermes, prebuilt for Apple platforms, and prints its path. The archive holds the `destroot` layout React Native's `hermes-engine.podspec` expects from a tarball pointed at by `HERMES_ENGINE_TARBALL_PATH`, so an app that sets that variable vendors the prebuilt frameworks instead of compiling Hermes as part of its own build.
17+
18+
The archive is looked for in this order, and cached under `~/Library/Caches/react-native-node-api/hermes-prebuilt` (overridable with `REACT_NATIVE_NODE_API_CACHE_PATH`):
19+
20+
1. The cache, unless `--force` is passed.
21+
2. The [release asset](https://github.com/callstackincubator/react-native-node-api/releases) published for the pinned commit by the `Hermes prebuilt` workflow, unless `--no-download` is passed.
22+
3. A local build from the vendored source, unless `--no-build` is passed. This requires macOS and Xcode, and takes a while — but only once per pinned commit.
23+
24+
Its name covers everything that changes its contents: the pinned Hermes commit, the React Native version whose `ReactCommon/jsi` it is compiled against, the build type and the platforms. That makes it usable as a CI cache key.
25+
26+
- `[from]` — Path to a file inside the app package. Defaults to the current working directory.
27+
- `--react-native-package <package-name>` — The React Native package to resolve Hermes for. Defaults to `react-native`.
28+
- `--build-type <type>` — One of `debug` or `release`. `debug` enables Hermes' debugger. Defaults to `debug`.
29+
- `--platform <name>` — Apple platform to build for, repeatable. Defaults to `iphoneos` and `iphonesimulator`.
30+
- `--silent` — Don't print anything except the final path. Defaults to `false`.
31+
- `--force` — Re-resolve the archive even if it is already cached. Defaults to `false`.
32+
- `--no-download` — Don't download a published archive.
33+
- `--no-build` — Don't build the archive locally when none is published.
34+
- `--print <property>` — Print `name`, `tag` or `url` of the archive instead of resolving it.
1335

1436
## `vendor-hermes [from]`
1537

0 commit comments

Comments
 (0)