From 6366a7206ad65293ccf088fec9f54d17495b23cb Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Wed, 10 Jun 2026 05:46:03 +0000 Subject: [PATCH] build(v8): configure cross-build snapshot tools --- .bazelrc | 1 + MODULE.bazel | 1 + patches/BUILD.bazel | 1 + patches/v8_host_mksnapshot.patch | 64 ++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 patches/v8_host_mksnapshot.patch diff --git a/.bazelrc b/.bazelrc index c58667b46e..fa93a15aa0 100644 --- a/.bazelrc +++ b/.bazelrc @@ -189,6 +189,7 @@ common:ci-windows-cross --strategy=TestRunner=local # V8 embeds IsolateData offsets in snapshot builtins; Windows snapshots must be # generated by a Windows mksnapshot binary rather than the Linux RBE host tool. common:ci-windows-cross --strategy=V8Mksnapshot=local +common:ci-windows-cross --@v8//:v8_use_target_mksnapshot=True common:ci-windows-cross --local_test_jobs=4 common:ci-windows-cross --test_env=RUST_TEST_THREADS=1 # Native Windows CI still covers the PowerShell tests. The cross-built gnullvm diff --git a/MODULE.bazel b/MODULE.bazel index 559516bd1a..d601910f0d 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -430,6 +430,7 @@ archive_override( patches = [ "//patches:v8_module_deps.patch", "//patches:v8_bazel_rules.patch", + "//patches:v8_host_mksnapshot.patch", "//patches:v8_source_portability.patch", ], strip_prefix = "v8-14.9.207.2", diff --git a/patches/BUILD.bazel b/patches/BUILD.bazel index a431c3f3a6..b5f5d95495 100644 --- a/patches/BUILD.bazel +++ b/patches/BUILD.bazel @@ -21,6 +21,7 @@ exports_files([ "rusty_v8_prebuilt_out_dir.patch", "ring_windows_msvc_include_dirs.patch", "v8_bazel_rules.patch", + "v8_host_mksnapshot.patch", "v8_module_deps.patch", "v8_source_portability.patch", "webrtc-sys_hermetic_darwin_sysroot.patch", diff --git a/patches/v8_host_mksnapshot.patch b/patches/v8_host_mksnapshot.patch new file mode 100644 index 0000000000..8cd4ab3f9a --- /dev/null +++ b/patches/v8_host_mksnapshot.patch @@ -0,0 +1,64 @@ +# What: use a host-native V8 snapshot generator for hermetic cross-builds while +# retaining an opt-in target-native path for Windows CI. +# Scope: V8 Bazel snapshot tool selection only. + +diff --git a/orig/v8-14.9.207.2/bazel/defs.bzl b/mod/v8-14.9.207.2/bazel/defs.bzl +--- a/orig/v8-14.9.207.2/bazel/defs.bzl ++++ b/mod/v8-14.9.207.2/bazel/defs.bzl +@@ -488,11 +488,7 @@ + def _mksnapshot(ctx): + prefix = ctx.attr.prefix + suffix = ctx.attr.suffix +- # Windows cross-builds use Linux for the exec configuration, but the +- # snapshot generator must match the target ABI and run on the Windows +- # runner. Action strategies only choose where an action runs; they cannot +- # change this executable from the exec to the target configuration. +- tool = ctx.executable.target_tool if ctx.attr.target_os == "win" else ctx.executable.tool ++ tool = ctx.executable.target_tool if ctx.attr.use_target_tool else ctx.executable.tool + outs = [ + ctx.actions.declare_file(prefix + "/snapshot" + suffix + ".cc"), + ctx.actions.declare_file(prefix + "/embedded" + suffix + ".S"), +@@ -531,6 +527,7 @@ + executable = True, + cfg = "target", + ), ++ "use_target_tool": attr.bool(mandatory = True), + "target_os": attr.string(mandatory = True), + "prefix": attr.string(mandatory = True), + "suffix": attr.string(mandatory = True), +@@ -545,8 +542,14 @@ + prefix = "noicu", + tool = ":noicu/mksnapshot" + suffix, + target_tool = ":noicu/mksnapshot" + suffix, ++ use_target_tool = select({ ++ "@v8//:is_v8_use_target_mksnapshot": True, ++ "//conditions:default": False, ++ }), + suffix = suffix, + target_os = select({ ++ "@v8//bazel/config:is_android": "android", ++ "@v8//bazel/config:is_linux": "linux", + "@v8//bazel/config:is_macos": "mac", + "@v8//bazel/config:is_windows": "win", + "//conditions:default": "", +@@ -558,8 +561,14 @@ + prefix = "icu", + tool = ":icu/mksnapshot" + suffix, + target_tool = ":icu/mksnapshot" + suffix, ++ use_target_tool = select({ ++ "@v8//:is_v8_use_target_mksnapshot": True, ++ "//conditions:default": False, ++ }), + suffix = suffix, + target_os = select({ ++ "@v8//bazel/config:is_android": "android", ++ "@v8//bazel/config:is_linux": "linux", + "@v8//bazel/config:is_macos": "mac", + "@v8//bazel/config:is_windows": "win", + "//conditions:default": "", +diff --git a/orig/v8-14.9.207.2/BUILD.bazel b/mod/v8-14.9.207.2/BUILD.bazel +--- a/orig/v8-14.9.207.2/BUILD.bazel ++++ b/mod/v8-14.9.207.2/BUILD.bazel +@@ -154,0 +155,2 @@ ++v8_flag(name = "v8_use_target_mksnapshot") ++