Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions .github/workflows/build-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
platforms:
description: Which platforms to build
type: choice
options: [all, android, ios]
options: [all, android, ios, macos]
default: all
push:
branches: [main]
Expand Down Expand Up @@ -40,9 +40,12 @@ jobs:
v8_version: ${{ steps.cfg.outputs.v8_version }}
ndk_release: ${{ steps.cfg.outputs.ndk_release }}
inputs_hash: ${{ steps.cfg.outputs.inputs_hash }}
apple_variants: ${{ steps.cfg.outputs.apple_variants }}
steps:
- uses: actions/checkout@v7
- id: cfg
env:
PLATFORMS: ${{ github.event_name == 'workflow_dispatch' && inputs.platforms || 'all' }}
run: |
set -a; . ./config.env; set +a
echo "v8_version=$V8_VERSION" >> "$GITHUB_OUTPUT"
Expand All @@ -52,6 +55,17 @@ jobs:
# finished build in R2 can be reused instead of repeated.
echo "inputs_hash=$(git ls-files -s config.env patches scripts/matrix .github/workflows/build-matrix.yml \
| git hash-object --stdin)" >> "$GITHUB_OUTPUT"
# iOS and macOS variants run in the same job definition but are
# dispatched separately, so the matrix is chosen here.
ios='"arm64-device","arm64-simulator","x64-simulator","arm64-catalyst","x64-catalyst","arm64-tvdevice","arm64-tvsimulator"'
macos='"arm64-macos","x64-macos"'
case "$PLATFORMS" in
ios) variants="[$ios]" ;;
macos) variants="[$macos]" ;;
android) variants="[]" ;;
*) variants="[$ios,$macos]" ;;
esac
echo "apple_variants=$variants" >> "$GITHUB_OUTPUT"

android:
needs: config
Expand Down Expand Up @@ -192,15 +206,15 @@ jobs:
path: v8-*-src-headers.tar.gz
retention-days: 7

ios:
apple:
needs: config
if: ${{ github.event_name != 'workflow_dispatch' || inputs.platforms == 'all' || inputs.platforms == 'ios' }}
if: ${{ needs.config.outputs.apple_variants != '[]' }}
runs-on: macos-15
timeout-minutes: 300
strategy:
fail-fast: false
matrix:
variant: [arm64-device, arm64-simulator, x64-simulator, arm64-catalyst, x64-catalyst, arm64-tvdevice, arm64-tvsimulator]
variant: ${{ fromJSON(needs.config.outputs.apple_variants) }}
# See the android job for the R2 bucket layout and the missing-secrets
# fallback; this job mirrors it.
env:
Expand All @@ -221,11 +235,17 @@ jobs:
- name: Check Apple build arguments
run: python3 tests/apple-args.py

# The slice names dist/, the asset and the R2 key. It is resolved before
# the R2 check because a hit skips the build.
- name: Resolve the slice
id: slice
run: echo "slice=$(scripts/matrix/build-ios.sh --variant ${{ matrix.variant }} --print-slice)" >> "$GITHUB_OUTPUT"

- name: Check R2 for a prebuilt artifact
id: cache
if: env.AWS_ACCESS_KEY_ID != ''
run: |
key="artifacts/${{ needs.config.outputs.inputs_hash }}/v8-${{ needs.config.outputs.v8_version }}-ios-${{ matrix.variant }}.tar.gz"
key="artifacts/${{ needs.config.outputs.inputs_hash }}/v8-${{ needs.config.outputs.v8_version }}-${{ steps.slice.outputs.slice }}.tar.gz"
if aws s3api head-object --endpoint-url "$R2_ENDPOINT" \
--bucket "$R2_BUCKET" --key "$key" >/dev/null 2>&1; then
aws s3 cp --endpoint-url "$R2_ENDPOINT" "s3://$R2_BUCKET/$key" .
Expand Down Expand Up @@ -266,24 +286,24 @@ jobs:
- name: Package
if: steps.cache.outputs.hit != 'true'
run: |
tar -czf "v8-${{ needs.config.outputs.v8_version }}-ios-${{ matrix.variant }}.tar.gz" \
-C dist "ios-${{ matrix.variant }}"
tar -czf "v8-${{ needs.config.outputs.v8_version }}-${{ steps.slice.outputs.slice }}.tar.gz" \
-C dist "${{ steps.slice.outputs.slice }}"

- name: Upload the artifact to R2
if: env.AWS_ACCESS_KEY_ID != '' && steps.cache.outputs.hit != 'true'
run: |
f="v8-${{ needs.config.outputs.v8_version }}-ios-${{ matrix.variant }}.tar.gz"
f="v8-${{ needs.config.outputs.v8_version }}-${{ steps.slice.outputs.slice }}.tar.gz"
aws s3 cp --endpoint-url "$R2_ENDPOINT" "$f" \
"s3://$R2_BUCKET/artifacts/${{ needs.config.outputs.inputs_hash }}/$f"

- uses: actions/upload-artifact@v7
with:
name: v8-ios-${{ matrix.variant }}
path: v8-*-ios-${{ matrix.variant }}.tar.gz
name: v8-${{ steps.slice.outputs.slice }}
path: v8-*-${{ steps.slice.outputs.slice }}.tar.gz
retention-days: 7

release:
needs: [config, android, ios]
needs: [config, android, apple]
if: startsWith(github.ref, 'refs/tags/v8-')
runs-on: ubuntu-24.04
steps:
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ from a pinned revision, with the gn args under review, is the point of this repo
|---|---|---|
| Android | `arm64-v8a`, `x86_64`, `armeabi-v7a`, `x86` | `ubuntu-24.04` |
| Apple | `arm64-device`, `arm64-simulator`, `x64-simulator`, `arm64-catalyst`, `x64-catalyst`, `arm64-tvdevice`, `arm64-tvsimulator` | `macos-15` |
| macOS | `arm64-macos`, `x64-macos` | `macos-15` |

Each target is its own job with its own checkout. That costs one `gclient sync`
per job, but the sync is about 6 minutes against 90–145 minutes of compile, so
Expand All @@ -50,6 +51,17 @@ This replaces the previous arrangement of one branch per architecture. Nine
branches meant nine places to apply a V8 bump or a patch, and cutting a release
needs a single ref to tag.

### macOS

The macOS variants are built by the Apple job from the same iOS checkout, but
they are `target_os="mac"` rather than an iOS `target_environment`, so they ship
as `macos-<cpu>` (`v8-<version>-macos-arm64.tar.gz`) instead of
`ios-<variant>`. Like Catalyst they keep the full tier set, and they share the
rest of the Apple gn args, pointer compression and the cppgc cage off included:
every Apple slice is compiled against the same `include/` and embedder defines.
`MACOS_DEPLOYMENT_TARGET` follows the macOS runtime in
[NativeScript/runtimes](https://github.com/NativeScript/runtimes).

### visionOS needs no build of its own

V8's build system has no visionOS support — `target_platform` accepts only
Expand Down Expand Up @@ -114,14 +126,16 @@ scripts/matrix/build-android.sh --abi arm64-v8a --ndk-root "$ANDROID_HOME/ndk/<v

scripts/matrix/fetch.sh --platform ios
scripts/matrix/build-ios.sh --variant arm64-device
scripts/matrix/build-ios.sh --variant arm64-macos
```

Sources land in `.v8/`, output in `dist/<platform>-<target>/`. The two platforms
Sources land in `.v8/`, output in `dist/<slice>/` (`build-ios.sh --variant <v>
--print-slice` prints it). The two platforms
need different DEPS, so use separate `--v8-dir` checkouts to keep both without
re-syncing.

To iterate on one platform in CI without rebuilding the other (~2.5 hours per
platform), dispatch the workflow with `platforms: android` or `platforms: ios`.
To iterate on one platform in CI without rebuilding the others (~2.5 hours per
platform), dispatch the workflow with `platforms: android`, `ios` or `macos`.

## Patches

Expand Down Expand Up @@ -197,4 +211,4 @@ disabled so that this does not enable an incomplete Wasm configuration.
The existing iOS and Catalyst arguments are unchanged.

Run `python3 tests/apple-args.py` on macOS to check the emitted GN arguments
for all seven Apple variants without compiling V8.
for all nine Apple variants without compiling V8.
3 changes: 3 additions & 0 deletions config.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ ANDROID_NDK_RELEASE=r29
IOS_DEPLOYMENT_TARGET=13.0
# arm64 macabi does not exist below 14.0.
CATALYST_DEPLOYMENT_TARGET=14.0
# Keep in step with the macOS CMAKE_OSX_DEPLOYMENT_TARGET in NativeScript/runtimes
# (NativeScript/CMakeLists.txt).
MACOS_DEPLOYMENT_TARGET=13.3
59 changes: 51 additions & 8 deletions scripts/matrix/build-ios.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/bin/bash
set -e
#
# Builds the V8 static libraries for one Apple variant into dist/ios-<variant>/.
# Builds the V8 static libraries for one Apple variant into dist/<slice>/, where
# the slice is ios-<variant>, or macos-<cpu> for the macOS variants. The slice
# also names the release asset; --print-slice prints it without building.
#
# Usage: build-ios.sh --variant <variant> [--v8-dir <path>] [-- <ninja args>]
#
# Variants: arm64-device, arm64-simulator, x64-simulator,
# arm64-catalyst, x64-catalyst
# arm64-catalyst, x64-catalyst, arm64-tvdevice, arm64-tvsimulator,
# arm64-macos, x64-macos
#
# Unlike Android, V8 has no monolith target here -- the iOS runtime links a set
# of per-module archives, so each is rebuilt from its objects. ninja emits thin
Expand All @@ -20,18 +23,22 @@ source "$ROOT_DIR/config.env"
V8_DIR="$ROOT_DIR/.v8/v8"
VARIANT=""
CC_WRAPPER=""
PRINT_SLICE=false
NINJA_ARGS=()

usage() {
cat <<EOF
Usage: $(basename "$0") --variant <variant> [--v8-dir <path>]
[--cc-wrapper <bin>] [-- <ninja args>]
[--cc-wrapper <bin>] [--print-slice] [-- <ninja args>]

--variant arm64-device | arm64-simulator | x64-simulator
| arm64-catalyst | x64-catalyst
| arm64-tvdevice | arm64-tvsimulator
| arm64-macos | x64-macos
--cc-wrapper <bin> Compiler launcher (e.g. sccache), passed to gn as
cc_wrapper. Must be on PATH.
--print-slice Print the variant's dist/ directory and release asset
stem (e.g. ios-arm64-device, macos-arm64) and exit.
EOF
}

Expand All @@ -43,12 +50,15 @@ while [ $# -gt 0 ]; do
--v8-dir=*) V8_DIR="${1#*=}"; shift ;;
--cc-wrapper) CC_WRAPPER="$2"; shift 2 ;;
--cc-wrapper=*) CC_WRAPPER="${1#*=}"; shift ;;
--print-slice) PRINT_SLICE=true; shift ;;
--) shift; NINJA_ARGS=("$@"); break ;;
-h|--help) usage; exit 0 ;;
*) echo "Unknown argument: $1" >&2; usage >&2; exit 1 ;;
esac
done

# macOS is target_os="mac", which has no target_environment.
TARGET_OS=ios
case "$VARIANT" in
arm64-device) CPU=arm64; TARGET_ENV=device ;;
arm64-simulator) CPU=arm64; TARGET_ENV=simulator ;;
Expand All @@ -57,9 +67,22 @@ case "$VARIANT" in
x64-catalyst) CPU=x64; TARGET_ENV=catalyst ;;
arm64-tvdevice) CPU=arm64; TARGET_ENV=device ;;
arm64-tvsimulator) CPU=arm64; TARGET_ENV=simulator ;;
arm64-macos) CPU=arm64; TARGET_ENV=""; TARGET_OS=mac ;;
x64-macos) CPU=x64; TARGET_ENV=""; TARGET_OS=mac ;;
*) echo "Invalid --variant '$VARIANT'" >&2; usage >&2; exit 1 ;;
esac

if [ "$TARGET_OS" = "mac" ]; then
SLICE="macos-$CPU"
else
SLICE="ios-$VARIANT"
fi

if [ "$PRINT_SLICE" = true ]; then
echo "$SLICE"
exit 0
fi

[ "$(uname)" = "Darwin" ] || { echo "Apple variants require a macOS host." >&2; exit 1; }

MODULES=(
Expand Down Expand Up @@ -103,14 +126,17 @@ MODULES=(
# process by device RAM, so that reservation fails outright on smaller devices
# -- four tries, then Oilpan's fatal OOM handler, before any JS runs. It crashed
# on an iPad Air while an iPad Pro was fine.
#
# macOS takes the same shared set: every Apple slice is compiled against one
# include/ with one set of embedder defines (no V8_COMPRESS_POINTERS, no caged
# heap), so a slice that differs here is an ABI mismatch, not a tuning choice.
GN_ARGS="
target_os=\"ios\"
target_os=\"$TARGET_OS\"
treat_warnings_as_errors=false
icu_use_data_file=false
use_custom_libcxx=false
is_component_build=false
is_debug=false
ios_enable_code_signing=false
v8_control_flow_integrity=false
v8_monolithic=false
v8_static_library=true
Expand All @@ -127,20 +153,37 @@ GN_ARGS="
symbol_level=0
"

if [ "$TARGET_ENV" = "catalyst" ]; then
if [ "$TARGET_OS" = "mac" ]; then
# Full tier set, as for Catalyst. On desktop targets is_official_build also
# defaults chrome_pgo_phase to 2, which makes gn exec
# //tools/update_pgo_profiles.py -- a Chromium script absent from a
# standalone V8 checkout, so gn gen fails without the override.
GN_ARGS="$GN_ARGS
is_official_build=true
use_thin_lto=false
chrome_pgo_phase=0
v8_enable_lite_mode=false
mac_deployment_target=\"$MACOS_DEPLOYMENT_TARGET\""
elif [ "$TARGET_ENV" = "catalyst" ]; then
# is_official_build here implies ThinLTO, which emits bitcode rather than
# object code and cannot be vendored, hence the explicit override.
GN_ARGS="$GN_ARGS
is_official_build=true
use_thin_lto=false
v8_enable_lite_mode=false
ios_enable_code_signing=false
ios_deployment_target=\"$CATALYST_DEPLOYMENT_TARGET\""
else
GN_ARGS="$GN_ARGS
v8_enable_lite_mode=true
ios_enable_code_signing=false
ios_deployment_target=\"$IOS_DEPLOYMENT_TARGET\""
fi

if [ -n "$TARGET_ENV" ]; then
GN_ARGS="$GN_ARGS target_environment=\"$TARGET_ENV\""
fi

# Chromium requires Blink configuration for tvOS even for standalone V8.
# Disable DrumBrake explicitly: tvOS otherwise enables it independently of
# v8_enable_webassembly, producing references to omitted Wasm types.
Expand All @@ -153,7 +196,7 @@ if [ -n "$CC_WRAPPER" ]; then
fi

OUTFOLDER="out.gn/$VARIANT-release"
DIST="$ROOT_DIR/dist/ios-$VARIANT"
DIST="$ROOT_DIR/dist/$SLICE"

cd "$V8_DIR"

Expand Down Expand Up @@ -181,7 +224,7 @@ archive_lib() {
}

rm -rf "$OUTFOLDER"
gn gen "$OUTFOLDER" --args="$GN_ARGS target_environment=\"$TARGET_ENV\" target_cpu=\"$CPU\" v8_target_cpu=\"$CPU\""
gn gen "$OUTFOLDER" --args="$GN_ARGS target_cpu=\"$CPU\" v8_target_cpu=\"$CPU\""

echo "Building $VARIANT: $(date)"
ninja "${NINJA_ARGS[@]}" -C "$OUTFOLDER" "${MODULES[@]}" inspector
Expand Down
32 changes: 32 additions & 0 deletions tests/apple-args.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,37 @@ def test_catalyst_is_built_with_the_jit(self):
for variant in ['arm64-catalyst', 'x64-catalyst']:
self.assertIn('v8_enable_lite_mode=false', self.args_for(variant))

def test_ios_variants_target_ios_with_an_environment(self):
for variant in ['arm64-device', 'arm64-simulator', 'x64-simulator', 'arm64-catalyst', 'x64-catalyst', 'arm64-tvdevice', 'arm64-tvsimulator']:
args = self.args_for(variant)
for flag in ['target_os="ios"', 'target_environment=', 'ios_deployment_target=', 'ios_enable_code_signing=false']:
self.assertIn(flag, args)
self.assertNotIn('mac_deployment_target=', args)

def test_macos_is_target_os_mac_with_the_jit(self):
for variant, cpu in [('arm64-macos', 'arm64'), ('x64-macos', 'x64')]:
args = self.args_for(variant)
for flag in ['target_os="mac"', f'target_cpu="{cpu}"', 'is_official_build=true', 'use_thin_lto=false', 'chrome_pgo_phase=0', 'v8_enable_lite_mode=false', 'mac_deployment_target=', 'v8_enable_pointer_compression=false', 'cppgc_enable_caged_heap=false']:
self.assertIn(flag, args)
for flag in ['target_environment=', 'target_platform=', 'ios_deployment_target=', 'ios_enable_code_signing=']:
self.assertNotIn(flag, args)

def test_slice_names(self):
expected = {
'arm64-device': 'ios-arm64-device',
'arm64-simulator': 'ios-arm64-simulator',
'x64-simulator': 'ios-x64-simulator',
'arm64-catalyst': 'ios-arm64-catalyst',
'x64-catalyst': 'ios-x64-catalyst',
'arm64-tvdevice': 'ios-arm64-tvdevice',
'arm64-tvsimulator': 'ios-arm64-tvsimulator',
'arm64-macos': 'macos-arm64',
'x64-macos': 'macos-x64',
}
for variant, slice_name in expected.items():
result = subprocess.run([str(ROOT / 'scripts/matrix/build-ios.sh'), '--variant', variant, '--print-slice'], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertEqual(result.stdout.strip(), slice_name)

if __name__ == '__main__':
unittest.main()
Loading