From f6f9ce8fd421a4d8ac67e8cbbb7216ff76ec82f8 Mon Sep 17 00:00:00 2001 From: Matt Hargett Date: Sat, 21 Nov 2026 14:41:09 -0800 Subject: [PATCH 1/3] Add opt-in Android Intl archives with size-optimized ThinLTO --- .github/workflows/build-matrix.yml | 35 +++++++++++++++++++----------- README.md | 13 +++++++++++ patches/android_build.patch | 21 ++++++++++++++++++ scripts/matrix/build-android.sh | 30 ++++++++++++++++++++++++- tests/android-intl-smoke.cc | 33 ++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 tests/android-intl-smoke.cc diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml index 843f329..03347de 100644 --- a/.github/workflows/build-matrix.yml +++ b/.github/workflows/build-matrix.yml @@ -8,7 +8,7 @@ on: platforms: description: Which platforms to build type: choice - options: [all, android, ios] + options: [all, android, ios, android-intl] default: all push: branches: [main] @@ -55,19 +55,20 @@ jobs: 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' && '{"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// 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 }} @@ -87,8 +88,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 }}" @@ -146,25 +147,33 @@ 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" + "$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++" \ + -std=c++20 -Os -Wl,--gc-sections -I"$dist/include" tests/android-intl-smoke.cc \ + "$dist/lib/libv8_monolith.a" -static-libstdc++ -llog -landroid -latomic -ldl -lm -o "$dist/intl-smoke" + - 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 @@ -181,12 +190,12 @@ 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 diff --git a/README.md b/README.md index cec50ac..7dad00e 100644 --- a/README.md +++ b/README.md @@ -199,3 +199,16 @@ 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. 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. diff --git a/patches/android_build.patch b/patches/android_build.patch index fc1b229..869f2d0 100644 --- a/patches/android_build.patch +++ b/patches/android_build.patch @@ -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 != "" && diff --git a/scripts/matrix/build-android.sh b/scripts/matrix/build-android.sh index 45a3317..c7aa3b3 100755 --- a/scripts/matrix/build-android.sh +++ b/scripts/matrix/build-android.sh @@ -13,6 +13,7 @@ source "$ROOT_DIR/config.env" V8_DIR="$ROOT_DIR/.v8/v8" NDK_ROOT="" ABI="" +PROFILE=default CC_WRAPPER="" NINJA_ARGS=() @@ -22,6 +23,7 @@ Usage: $(basename "$0") --abi [--v8-dir ] [--ndk-root ] [--cc-wrapper ] [-- ] --abi armeabi-v7a | arm64-v8a | x86 | x86_64 + --profile default | intl | intl-a73 (arm64 with CRC and crypto) --v8-dir V8 sources (default: $V8_DIR) --ndk-root NDK to build against; must be the same one the runtime is built with. Defaults to \$ANDROID_NDK_ROOT. @@ -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 ;; @@ -128,6 +131,22 @@ 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 optimize_for_size=true v8_jitless=false" + 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" @@ -141,7 +160,16 @@ 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. diff --git a/tests/android-intl-smoke.cc b/tests/android-intl-smoke.cc new file mode 100644 index 0000000..fca7a76 --- /dev/null +++ b/tests/android-intl-smoke.cc @@ -0,0 +1,33 @@ +#include +#include + +int main() { + auto platform = v8::platform::NewDefaultPlatform(); + v8::V8::InitializePlatform(platform.get()); + v8::V8::Initialize(); + auto allocator = std::unique_ptr( + 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 WebAssembly.Instance(new WebAssembly.Module( + new Uint8Array([0,97,115,109,1,0,0,0]))) instanceof WebAssembly.Instance + )"); + v8::Local script; + v8::Local 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; +} From 24d94dfae5eed4defdd6cece8c0bcb5f36f44025 Mon Sep 17 00:00:00 2001 From: Matt Hargett Date: Sat, 21 Nov 2026 14:45:14 -0800 Subject: [PATCH 2/3] Allow forks to exercise only the optional Android matrix by push --- .github/workflows/build-matrix.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml index 03347de..176fd7b 100644 --- a/.github/workflows/build-matrix.yml +++ b/.github/workflows/build-matrix.yml @@ -11,7 +11,7 @@ on: options: [all, android, ios, android-intl] default: all push: - branches: [main] + branches: [main, build/android-intl] tags: ['v8-*'] pull_request: paths: @@ -60,7 +60,7 @@ jobs: timeout-minutes: 300 strategy: fail-fast: false - matrix: ${{ fromJSON(inputs.platforms == '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"]}') }} + 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// holds finished tarballs (expired quickly; a miss # just means building, as before) and sccache/ holds the compiler cache @@ -203,7 +203,7 @@ jobs: 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: From 7d810e817b4cce7f254237d624f50865ed64a373 Mon Sep 17 00:00:00 2001 From: Matt Hargett Date: Sat, 21 Nov 2026 16:39:15 -0800 Subject: [PATCH 3/3] Package the V8 public ABI and validate Android 10 embedder linkage --- .github/workflows/build-matrix.yml | 15 +++++++++++---- README.md | 5 ++++- scripts/matrix/build-android.sh | 6 +++++- tests/android-intl-smoke.cc | 7 +++++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-matrix.yml b/.github/workflows/build-matrix.yml index 176fd7b..2d7d4ab 100644 --- a/.github/workflows/build-matrix.yml +++ b/.github/workflows/build-matrix.yml @@ -19,6 +19,7 @@ on: - 'patches/**' - 'scripts/matrix/**' - 'tests/apple-args.py' + - 'tests/android-intl-smoke.cc' - '.github/workflows/build-matrix.yml' permissions: @@ -50,7 +51,7 @@ 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: @@ -158,9 +159,15 @@ jobs: if: matrix.profile && steps.cache.outputs.hit != 'true' run: | dist="dist/android-$ARTIFACT" - "$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++" \ - -std=c++20 -Os -Wl,--gc-sections -I"$dist/include" tests/android-intl-smoke.cc \ - "$dist/lib/libv8_monolith.a" -static-libstdc++ -llog -landroid -latomic -ldl -lm -o "$dist/intl-smoke" + 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' diff --git a/README.md b/README.md index 7dad00e..d1c56bd 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,10 @@ 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. Existing releases and compact default builds are unchanged. +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 diff --git a/scripts/matrix/build-android.sh b/scripts/matrix/build-android.sh index c7aa3b3..076a11e 100755 --- a/scripts/matrix/build-android.sh +++ b/scripts/matrix/build-android.sh @@ -140,7 +140,8 @@ case "$PROFILE" in 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 optimize_for_size=true v8_jitless=false" + 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" @@ -174,6 +175,9 @@ 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/" diff --git a/tests/android-intl-smoke.cc b/tests/android-intl-smoke.cc index fca7a76..a94cfac 100644 --- a/tests/android-intl-smoke.cc +++ b/tests/android-intl-smoke.cc @@ -18,8 +18,11 @@ int main() { 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 WebAssembly.Instance(new WebAssembly.Module( - new Uint8Array([0,97,115,109,1,0,0,0]))) instanceof WebAssembly.Instance + 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 script; v8::Local result;