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
48 changes: 32 additions & 16 deletions .github/workflows/build-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ on:
platforms:
description: Which platforms to build
type: choice
options: [all, android, ios]
options: [all, android, ios, android-intl]
default: all
push:
branches: [main]
branches: [main, build/android-intl]
tags: ['v8-*']
pull_request:
paths:
- 'config.env'
- 'patches/**'
- 'scripts/matrix/**'
- 'tests/apple-args.py'
- 'tests/android-intl-smoke.cc'
- '.github/workflows/build-matrix.yml'

permissions:
Expand Down Expand Up @@ -50,24 +51,25 @@ jobs:
# Everything the artifacts are a function of, hashed by blob id.
# Commits with an unchanged hash produce identical artifacts, so a
# 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 \
echo "inputs_hash=$(git ls-files -s config.env patches scripts/matrix tests/android-intl-smoke.cc .github/workflows/build-matrix.yml \
| git hash-object --stdin)" >> "$GITHUB_OUTPUT"

android:
needs: config
if: ${{ github.event_name != 'workflow_dispatch' || inputs.platforms == 'all' || inputs.platforms == 'android' }}
if: ${{ github.event_name != 'workflow_dispatch' || startsWith(inputs.platforms, 'android') || inputs.platforms == 'all' }}
runs-on: ubuntu-24.04
timeout-minutes: 300
strategy:
fail-fast: false
matrix:
abi: [arm64-v8a, x86_64, armeabi-v7a, x86]
matrix: ${{ fromJSON((inputs.platforms == 'android-intl' || github.ref == 'refs/heads/build/android-intl') && '{"include":[{"abi":"arm64-v8a","profile":"intl","artifact":"arm64-v8a-intl"},{"abi":"arm64-v8a","profile":"intl-a73","artifact":"arm64-v8a-intl-a73"}]}' || '{"abi":["arm64-v8a","x86_64","armeabi-v7a","x86"]}') }}
# The R2 bucket has two prefixes with separate lifecycle rules:
# artifacts/<inputs-hash>/ holds finished tarballs (expired quickly; a miss
# just means building, as before) and sccache/ holds the compiler cache
# (kept long). Every R2 step is skipped when the secrets are absent, e.g.
# on a fork PR, and the build then runs exactly as it would without R2.
env:
ARTIFACT: ${{ matrix.artifact || matrix.abi }}
PROFILE: ${{ matrix.profile || 'default' }}
R2_BUCKET: ${{ vars.R2_BUCKET }}
R2_ENDPOINT: https://${{ secrets.R2_ACCOUNT_ID }}.r2.cloudflarestorage.com
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
Expand All @@ -87,8 +89,8 @@ jobs:
id: cache
if: env.AWS_ACCESS_KEY_ID != ''
run: |
keys="v8-${{ needs.config.outputs.v8_version }}-android-${{ matrix.abi }}.tar.gz"
if [ "${{ matrix.abi }}" = "arm64-v8a" ]; then
keys="v8-${{ needs.config.outputs.v8_version }}-android-$ARTIFACT.tar.gz"
if [ "$ARTIFACT" = "arm64-v8a" ]; then
keys="$keys v8-${{ needs.config.outputs.v8_version }}-src-headers.tar.gz"
fi
prefix="artifacts/${{ needs.config.outputs.inputs_hash }}"
Expand Down Expand Up @@ -146,25 +148,39 @@ jobs:
- name: Build ${{ matrix.abi }}
if: steps.cache.outputs.hit != 'true'
run: >
scripts/matrix/build-android.sh --abi ${{ matrix.abi }}
scripts/matrix/build-android.sh --abi ${{ matrix.abi }} --profile "$PROFILE"
${{ env.AWS_ACCESS_KEY_ID != '' && '--cc-wrapper sccache' || '' }}

- name: sccache stats
if: env.AWS_ACCESS_KEY_ID != '' && steps.cache.outputs.hit != 'true'
run: sccache --show-stats

- name: Link Android Intl and WebAssembly smoke test with the consumer NDK
if: matrix.profile && steps.cache.outputs.hit != 'true'
run: |
dist="dist/android-$ARTIFACT"
bin="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin"
cxx="$bin/aarch64-linux-android29-clang++"
"$cxx" -std=c++20 -DV8_GN_HEADER -fPIC -Os -I"$dist/include" -c tests/android-intl-smoke.cc -o "$RUNNER_TEMP/intl-smoke.o"
libs=("$RUNNER_TEMP/intl-smoke.o" "$dist/lib/libv8_monolith.a" -static-libstdc++ -llog -landroid -latomic -ldl -lm)
"$cxx" -shared -Wl,-z,defs,--gc-sections "${libs[@]}" -o "$RUNNER_TEMP/libintl-smoke.so"
"$cxx" -Wl,--gc-sections "${libs[@]}" -o "$dist/intl-smoke"
# Bionic requires at least 64-byte executable TLS alignment on arm64.
tls=$("$bin/llvm-readelf" -lW "$dist/intl-smoke" | awk '$1 == "TLS" {print $NF}')
[[ -z "$tls" ]] || (( tls >= 64 ))

- name: Package
if: steps.cache.outputs.hit != 'true'
run: |
tar -czf "v8-${{ needs.config.outputs.v8_version }}-android-${{ matrix.abi }}.tar.gz" \
-C dist "android-${{ matrix.abi }}"
tar -czf "v8-${{ needs.config.outputs.v8_version }}-android-$ARTIFACT.tar.gz" \
-C dist "android-$ARTIFACT"

# The internal headers are architecture-independent, so one job produces
# them. It piggybacks on a build rather than getting its own job because
# src/inspector/protocol/*.h are generated into gen/ and only exist once
# something has been built.
- name: Package the internal headers
if: matrix.abi == 'arm64-v8a' && steps.cache.outputs.hit != 'true'
if: matrix.abi == 'arm64-v8a' && !matrix.profile && steps.cache.outputs.hit != 'true'
run: |
scripts/matrix/package-src-headers.sh \
--gen-dir .v8/v8/out.gn/android-arm64-release/gen
Expand All @@ -181,20 +197,20 @@ jobs:

- uses: actions/upload-artifact@v7
with:
name: v8-android-${{ matrix.abi }}
path: v8-*-android-${{ matrix.abi }}.tar.gz
name: v8-android-${{ env.ARTIFACT }}
path: v8-*-android-${{ env.ARTIFACT }}.tar.gz
retention-days: 7

- uses: actions/upload-artifact@v7
if: matrix.abi == 'arm64-v8a'
if: matrix.abi == 'arm64-v8a' && !matrix.profile
with:
name: v8-src-headers
path: v8-*-src-headers.tar.gz
retention-days: 7

ios:
needs: config
if: ${{ github.event_name != 'workflow_dispatch' || inputs.platforms == 'all' || inputs.platforms == 'ios' }}
if: ${{ github.ref != 'refs/heads/build/android-intl' && (github.event_name != 'workflow_dispatch' || inputs.platforms == 'all' || inputs.platforms == 'ios') }}
runs-on: macos-15
timeout-minutes: 300
strategy:
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,19 @@ 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.
# Optional Android Intl artifacts

Select `android-intl` in **Build V8 matrix** to produce two Android arm64
artifacts with built-in ICU data, WebAssembly, and JIT. The `intl` artifact
targets baseline arm64-v8a; `intl-a73` requires ARM CRC and crypto extensions
and is tuned for Cortex-A73. Do not ship the tuned archive as a generic arm64
library. Both opt-in profiles target Android 10 (API 29) or newer. Compile
consumers with `-DV8_GN_HEADER` and the artifact's own `include/` directory:
the generated header describes its public ABI, including pointer compression.
Existing releases and compact default builds are unchanged.

Both variants optimize for size, use ThinLTO without PGO, and ship a native
relocatable object in the monolithic archive so consumers do not need the
producer's LLVM bitcode reader. CI links `intl-smoke` against the archive with
the pinned Android NDK. Run that executable on a compatible Android device;
exit status zero checks localized number formatting and WebAssembly instantiation.
21 changes: 21 additions & 0 deletions patches/android_build.patch
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,24 @@ index 1e07ac0e7..6927ba1ef 100644

public_android_sdk_root = "//third_party/android_sdk/public"
public_android_sdk_platform_version = "37.0"
diff --git a/config/compiler/BUILD.gn b/config/compiler/BUILD.gn
--- a/config/compiler/BUILD.gn
+++ b/config/compiler/BUILD.gn
@@ -50,4 +50,7 @@
declare_args() {
# This allows overriding the location of lld.
lld_path = default_lld_path
+
+ # Optional target profile; never change host snapshot tool instructions.
+ android_tune_cortex_a73 = false
}
@@ -1374,6 +1377,9 @@
} else if (current_cpu == "arm64") {
+ if (is_android && android_tune_cortex_a73) {
+ cflags += [ "-march=armv8-a+crc+crypto", "-mtune=cortex-a73" ]
+ }
if (is_clang && !is_android && !is_fuchsia && !is_chromeos_device) {
cflags += [ "--target=aarch64-linux-gnu" ]
ldflags += [ "--target=aarch64-linux-gnu" ]
}
if (target_os == "chromeos" && cros_target_cpu_arch != "" &&
34 changes: 33 additions & 1 deletion scripts/matrix/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ source "$ROOT_DIR/config.env"
V8_DIR="$ROOT_DIR/.v8/v8"
NDK_ROOT=""
ABI=""
PROFILE=default
CC_WRAPPER=""
NINJA_ARGS=()

Expand All @@ -22,6 +23,7 @@ Usage: $(basename "$0") --abi <abi> [--v8-dir <path>] [--ndk-root <path>]
[--cc-wrapper <bin>] [-- <ninja args>]

--abi <abi> armeabi-v7a | arm64-v8a | x86 | x86_64
--profile <name> default | intl | intl-a73 (arm64 with CRC and crypto)
--v8-dir <path> V8 sources (default: $V8_DIR)
--ndk-root <path> NDK to build against; must be the same one the runtime is
built with. Defaults to \$ANDROID_NDK_ROOT.
Expand All @@ -34,6 +36,7 @@ while [ $# -gt 0 ]; do
case "$1" in
--abi) ABI="$2"; shift 2 ;;
--abi=*) ABI="${1#*=}"; shift ;;
--profile) PROFILE="$2"; shift 2 ;;
--v8-dir) V8_DIR="$2"; shift 2 ;;
--v8-dir=*) V8_DIR="${1#*=}"; shift ;;
--ndk-root) NDK_ROOT="$2"; shift 2 ;;
Expand Down Expand Up @@ -128,6 +131,23 @@ fi

OUTFOLDER="out.gn/android-$CPU-release"
DIST="$ROOT_DIR/dist/android-$ABI"
case "$PROFILE" in
default) ;;
intl|intl-a73)
if [[ "$PROFILE" == intl-a73 && "$CPU" != arm64 ]]; then
echo "intl-a73 requires arm64-v8a" >&2
exit 1
fi
GN_ARGS="${GN_ARGS/use_thin_lto=false/use_thin_lto=true}"
GN_ARGS="${GN_ARGS/v8_enable_i18n_support=false/v8_enable_i18n_support=true}"
GN_ARGS="${GN_ARGS/default_min_sdk_version=21/default_min_sdk_version=29}"
GN_ARGS="$GN_ARGS optimize_for_size=true v8_jitless=false v8_generate_external_defines_header=true v8_monolithic_for_shared_library=true"
if [[ "$PROFILE" == intl-a73 ]]; then GN_ARGS="$GN_ARGS android_tune_cortex_a73=true"; fi
OUTFOLDER="$OUTFOLDER-$PROFILE"
DIST="$DIST-$PROFILE"
;;
*) echo "Invalid Android profile: $PROFILE" >&2; exit 1 ;;
esac

cd "$V8_DIR"

Expand All @@ -141,11 +161,23 @@ ninja "${NINJA_ARGS[@]}" -C "$OUTFOLDER" v8_monolith
echo "Finished $ABI: $(date)"

mkdir -p "$DIST/lib" "$DIST/include"
cp "$OUTFOLDER/obj/libv8_monolith.a" "$DIST/lib/"
if [[ "$PROFILE" == default ]]; then
cp "$OUTFOLDER/obj/libv8_monolith.a" "$DIST/lib/"
else
# Resolve bitcode with the compiler that produced it, not the embedder's NDK.
tools=third_party/llvm-build/Release+Asserts/bin
"$tools/ld.lld" -r --whole-archive "$OUTFOLDER/obj/libv8_monolith.a" \
--no-whole-archive -o "$OUTFOLDER/v8_monolith.o"
"$tools/llvm-ar" rcs "$OUTFOLDER/libv8_monolith.a" "$OUTFOLDER/v8_monolith.o"
cp "$OUTFOLDER/libv8_monolith.a" "$DIST/lib/"
fi

# The public headers are architecture-independent but are shipped per artifact
# so that a consumer only has to fetch one thing.
rsync -a --delete "$V8_DIR/include/" "$DIST/include/"
if [[ "$PROFILE" != default ]]; then
cp "$OUTFOLDER/gen/include/v8-gn.h" "$DIST/include/"
fi
mkdir -p "$DIST/include/inspector"
cp "$OUTFOLDER/gen/include/inspector/"*.h "$DIST/include/inspector/"

Expand Down
36 changes: 36 additions & 0 deletions tests/android-intl-smoke.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <libplatform/libplatform.h>
#include <v8.h>

int main() {
auto platform = v8::platform::NewDefaultPlatform();
v8::V8::InitializePlatform(platform.get());
v8::V8::Initialize();
auto allocator = std::unique_ptr<v8::ArrayBuffer::Allocator>(
v8::ArrayBuffer::Allocator::NewDefaultAllocator());
v8::Isolate::CreateParams params;
params.array_buffer_allocator = allocator.get();
auto isolate = v8::Isolate::New(params);
bool ok = false;
{
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handles(isolate);
auto context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
auto source = v8::String::NewFromUtf8Literal(isolate, R"(
new Intl.NumberFormat('de-DE').format(1234.5) === '1.234,5' &&
new Intl.DateTimeFormat('en-US', {year:'numeric', timeZone:'UTC'}).format(0) === '1970' &&
new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([
0,97,115,109,1,0,0,0, 1,5,1,96,0,1,127, 3,2,1,0,
7,7,1,3,114,117,110,0,0, 10,6,1,4,0,65,42,11
]))).exports.run() === 42
)");
v8::Local<v8::Script> script;
v8::Local<v8::Value> result;
ok = v8::Script::Compile(context, source).ToLocal(&script) &&
script->Run(context).ToLocal(&result) && result->IsTrue();
}
isolate->Dispose();
v8::V8::Dispose();
v8::V8::DisposePlatform();
return ok ? 0 : 1;
}