diff --git a/MODULE.bazel b/MODULE.bazel index b4bcc6f994..3ffde1809c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -807,25 +807,36 @@ inject_repo(crate, "alsa_lib") ] ] -bazel_dep(name = "v8", version = "15.2.124.1") bazel_dep(name = "rules_license", version = "1.0.0") -archive_override( - module_name = "v8", +engine_repository = use_repo_rule("//third_party/v8:engine_repository.bzl", "engine_repository") + +engine_repository( + name = "v8", integrity = "sha256-aNN5G427qQbP/5o+NXONgXR8ZvS6mjf6mfAI6jtxyzI=", patch_strip = 3, patches = [ - "//patches:v8_module_deps.patch", - "//patches:v8_bazel_rules.patch", "//patches:v8_source_portability.patch", "//patches:v8_array_sort_elements_kind.patch", + "//third_party/v8:v8_defs.patch", ], strip_prefix = "v8-15.2.124.1", urls = ["https://github.com/v8/v8/archive/refs/tags/15.2.124.1.tar.gz"], ) -# The dependency repos and their BUILD files belong to Codex. V8 only needs -# its original apparent repo names to resolve to these same imports. +# All V8 inputs are owned here, including the pinned Python generator inputs. +pip.parse( + extra_pip_args = ["--require-hashes"], + hub_name = "v8_python_deps", + python_version = "3.11", + requirements_lock = "@v8//:bazel/requirements.txt", + simpleapi_skip = [ + "jinja2", + "markupsafe", + ], +) +use_repo(pip, "v8_python_deps") + v8_dependencies = use_extension("//third_party/v8:dependencies.bzl", "dependencies") use_repo( v8_dependencies, @@ -838,19 +849,6 @@ use_repo( "v8_simdutf", ) -v8_dependency_bridge = use_extension("@v8//:bazel/codex_deps.bzl", "codex_deps") - -inject_repo( - v8_dependency_bridge, - dragonbox = "v8_dragonbox", - fast_float = "v8_fast_float", - fp16 = "v8_fp16", - highway = "v8_highway", - icu = "v8_icu", - simdutf = "v8_simdutf", - v8_abseil = "v8_abseil", -) - http_archive( name = "v8_crate_152_2_0", build_file = "//third_party/v8:v8_crate.BUILD.bazel", diff --git a/patches/BUILD.bazel b/patches/BUILD.bazel index 039167a738..1c62ed89f2 100644 --- a/patches/BUILD.bazel +++ b/patches/BUILD.bazel @@ -25,8 +25,6 @@ exports_files([ "tikv-jemalloc-sys_make_env.patch", "tikv-jemalloc-sys_dependency_flags.patch", "v8_array_sort_elements_kind.patch", - "v8_bazel_rules.patch", - "v8_module_deps.patch", "v8_source_portability.patch", "webrtc-sys_hermetic_darwin_sysroot.patch", "windows-link.patch", diff --git a/patches/v8_bazel_rules.patch b/patches/v8_bazel_rules.patch deleted file mode 100644 index bcdb9deab5..0000000000 --- a/patches/v8_bazel_rules.patch +++ /dev/null @@ -1,456 +0,0 @@ -# What: adapt upstream V8 Bazel rules to this workspace's hermetic toolchains -# and externally provided dependencies. -# Scope: Bazel BUILD/defs integration only, including dependency -# wiring, generated sources, and visibility; no standalone V8 source patching. - -diff --git a/orig/v8-15.2.124.1/bazel/defs.bzl b/mod/v8-15.2.124.1/bazel/defs.bzl ---- a/orig/v8-15.2.124.1/bazel/defs.bzl -+++ b/mod/v8-15.2.124.1/bazel/defs.bzl -@@ -42,12 +42,30 @@ - ) - - def v8_flag(name, default = False): -- _create_option_flag(name = name, build_setting_default = default, scope = "universal") -- native.config_setting(name = "is_" + name, flag_values = {name: "True"}) -- native.config_setting(name = "is_not_" + name, flag_values = {name: "False"}) -- --def v8_string(name, default = ""): -- _create_option_string(name = name, build_setting_default = default, scope = "universal") -+ _create_option_flag( -+ name = name, -+ build_setting_default = default, -+ scope = "universal", -+ visibility = ["//visibility:public"], -+ ) -+ native.config_setting( -+ name = "is_" + name, -+ flag_values = {name: "True"}, -+ visibility = ["//visibility:public"], -+ ) -+ native.config_setting( -+ name = "is_not_" + name, -+ flag_values = {name: "False"}, -+ visibility = ["//visibility:public"], -+ ) -+ -+def v8_string(name, default = "", visibility = None): -+ _create_option_string( -+ name = name, -+ build_setting_default = default, -+ scope = "universal", -+ visibility = visibility, -+ ) - - def v8_int(name, default = 0): - _create_option_int(name = name, build_setting_default = default, scope = "universal") -@@ -106,7 +124,13 @@ - - def _default_args(): - return struct( -- deps = [":define_flags", "@libcxx//:libc++"], -+ deps = [":define_flags"] + select({ -+ "@v8//:is_v8_use_rusty_v8_custom_libcxx": [ -+ "@@//third_party/v8:rusty_v8_custom_libcxx_headers", -+ "@@//third_party/v8:rusty_v8_custom_libcxx_runtime", -+ ], -+ "//conditions:default": [], -+ }), - defines = select({ - "@v8//bazel/config:is_windows": [ - "UNICODE", -@@ -136,12 +160,15 @@ - ], - "//conditions:default": [], - }) + select({ -- "@v8//bazel/config:is_clang": [ -- "-Wno-invalid-offsetof", -- "-Wno-deprecated-this-capture", -- "-Wno-deprecated-declarations", -- "-std=c++20", -- ], -+ "@v8//:is_v8_use_rusty_v8_custom_libcxx": [ -+ "-nostdinc++", -+ "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS", -+ "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE", -+ "-D_LIBCPP_INSTRUMENTED_WITH_ASAN=0", -+ "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS", -+ ], -+ "//conditions:default": [], -+ }) + select({ - "@v8//bazel/config:is_gcc": [ - "-Wno-extra", - "-Wno-array-bounds", -@@ -161,9 +188,17 @@ - "-std=gnu++2a", - ], - "@v8//bazel/config:is_windows": [ -- "/std:c++20", -- ], -- "//conditions:default": [], -+ "-Wno-invalid-offsetof", -+ "-Wno-deprecated-this-capture", -+ "-Wno-deprecated-declarations", -+ "-std=c++20", -+ ], -+ "//conditions:default": [ -+ "-Wno-invalid-offsetof", -+ "-Wno-deprecated-this-capture", -+ "-Wno-deprecated-declarations", -+ "-std=c++20", -+ ], - }) + select({ - "@v8//bazel/config:is_gcc_fastbuild": [ - # Non-debug builds without optimizations fail because -@@ -187,12 +222,12 @@ - includes = ["include"], - linkopts = select({ - "@v8//bazel/config:is_windows": [ -- "Winmm.lib", -- "DbgHelp.lib", -- "Advapi32.lib", -+ "-lwinmm", -+ "-ldbghelp", -+ "-ladvapi32", - ], - "@v8//bazel/config:is_macos": ["-pthread"], -- "//conditions:default": ["-Wl,--no-as-needed -ldl -latomic -pthread"], -+ "//conditions:default": ["-Wl,--no-as-needed -ldl -pthread"], - }) + select({ - ":should_add_rdynamic": ["-rdynamic"], - "//conditions:default": [], -@@ -466,6 +501,11 @@ - 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 - outs = [ - ctx.actions.declare_file(prefix + "/snapshot" + suffix + ".cc"), - ctx.actions.declare_file(prefix + "/embedded" + suffix + ".S"), -@@ -483,7 +523,7 @@ - "--embedded_src", - outs[1].path, - ] + ctx.attr.args, -- executable = ctx.executable.tool, -+ executable = tool, - progress_message = "Running mksnapshot", - ) - return [DefaultInfo(files = depset(outs))] -@@ -498,6 +538,12 @@ - executable = True, - cfg = "exec", - ), -+ "target_tool": attr.label( -+ mandatory = True, -+ allow_files = True, -+ executable = True, -+ cfg = "target", -+ ), - "target_os": attr.string(mandatory = True), - "prefix": attr.string(mandatory = True), - "suffix": attr.string(mandatory = True), -@@ -511,6 +557,7 @@ - args = args, - prefix = "noicu", - tool = ":noicu/mksnapshot" + suffix, -+ target_tool = ":noicu/mksnapshot" + suffix, - suffix = suffix, - target_os = select({ - "@v8//bazel/config:is_macos": "mac", -@@ -523,6 +570,7 @@ - args = args, - prefix = "icu", - tool = ":icu/mksnapshot" + suffix, -+ target_tool = ":icu/mksnapshot" + suffix, - suffix = suffix, - target_os = select({ - "@v8//bazel/config:is_macos": "mac", -diff --git a/orig/v8-15.2.124.1/BUILD.bazel b/mod/v8-15.2.124.1/BUILD.bazel ---- a/orig/v8-15.2.124.1/BUILD.bazel -+++ b/mod/v8-15.2.124.1/BUILD.bazel -@@ -154,6 +154,10 @@ - - v8_flag(name = "v8_enable_v8_checks") - -+v8_flag(name = "v8_enable_sandbox") -+ -+v8_flag(name = "v8_use_rusty_v8_custom_libcxx") -+ - v8_flag(name = "v8_enable_verify_csa") - - v8_flag(name = "v8_enable_verify_heap") -@@ -319,7 +323,8 @@ - # If no explicit value for v8_enable_pointer_compression, we set it to 'none'. - v8_string( - name = "v8_enable_pointer_compression", -- default = "none", -+ default = "False", -+ visibility = ["//visibility:public"], - ) - - # Default setting for v8_enable_pointer_compression. -@@ -520,6 +525,7 @@ - "v8_enable_slow_dchecks": "ENABLE_SLOW_DCHECKS", - "v8_enable_runtime_call_stats": "V8_RUNTIME_CALL_STATS", - "v8_enable_snapshot_native_code_counters": "V8_SNAPSHOT_NATIVE_CODE_COUNTERS", -+ "v8_enable_sandbox": "V8_ENABLE_SANDBOX", - "v8_enable_trace_maps": "V8_TRACE_MAPS", - "v8_enable_turbofan": "V8_ENABLE_TURBOFAN", - "v8_enable_v8_checks": "V8_ENABLE_CHECKS", -@@ -4170,28 +4176,14 @@ - }), - ) - --v8_library( -- name = "lib_dragonbox", -- srcs = ["third_party/dragonbox/src/include/dragonbox/dragonbox.h"], -- hdrs = [ -- "third_party/dragonbox/src/include/dragonbox/dragonbox.h", -- ], -- includes = [ -- "third_party/dragonbox/src/include", -- ], --) -- --v8_library( -- name = "lib_fp16", -- srcs = ["third_party/fp16/src/include/fp16.h"], -- hdrs = [ -- "third_party/fp16/src/include/fp16/fp16.h", -- "third_party/fp16/src/include/fp16/bitcasts.h", -- "third_party/fp16/src/include/fp16/macros.h", -- ], -- includes = [ -- "third_party/fp16/src/include", -- ], -+alias( -+ name = "lib_dragonbox", -+ actual = "@dragonbox//:dragonbox", -+) -+ -+alias( -+ name = "lib_fp16", -+ actual = "@fp16//:fp16", - ) - - filegroup( -@@ -4486,6 +4478,20 @@ - srcs = [ - "include/js_protocol.pdl", - "src/inspector/inspector_protocol_config.json", -+ "third_party/inspector_protocol/code_generator.py", -+ "third_party/inspector_protocol/pdl.py", -+ "third_party/inspector_protocol/lib/Forward_h.template", -+ "third_party/inspector_protocol/lib/Object_cpp.template", -+ "third_party/inspector_protocol/lib/Object_h.template", -+ "third_party/inspector_protocol/lib/Protocol_cpp.template", -+ "third_party/inspector_protocol/lib/ValueConversions_cpp.template", -+ "third_party/inspector_protocol/lib/ValueConversions_h.template", -+ "third_party/inspector_protocol/lib/Values_cpp.template", -+ "third_party/inspector_protocol/lib/Values_h.template", -+ "third_party/inspector_protocol/templates/Exported_h.template", -+ "third_party/inspector_protocol/templates/Imported_h.template", -+ "third_party/inspector_protocol/templates/TypeBuilder_cpp.template", -+ "third_party/inspector_protocol/templates/TypeBuilder_h.template", - ], - outs = [ - "include/inspector/Debugger.h", -@@ -4507,15 +4513,19 @@ - "src/inspector/protocol/Schema.cpp", - "src/inspector/protocol/Schema.h", - ], -- cmd = "$(location :code_generator) --jinja_dir . \ -- --inspector_protocol_dir third_party/inspector_protocol \ -+ cmd = "INSPECTOR_PROTOCOL_DIR=$$(dirname $(execpath third_party/inspector_protocol/code_generator.py)); \ -+ PYTHONPATH=$$INSPECTOR_PROTOCOL_DIR:external/rules_python++pip+v8_python_deps_311_jinja2/site-packages:external/rules_python++pip+v8_python_deps_311_markupsafe/site-packages:$${PYTHONPATH-} \ -+ $(execpath @rules_python//python/bin:python) $(execpath third_party/inspector_protocol/code_generator.py) --jinja_dir . \ -+ --inspector_protocol_dir $$INSPECTOR_PROTOCOL_DIR \ - --config $(location :src/inspector/inspector_protocol_config.json) \ - --config_value protocol.path=$(location :include/js_protocol.pdl) \ -+ --config_value crdtp.dir=third_party/inspector_protocol/crdtp \ - --output_base $(@D)/src/inspector", -- local = 1, - message = "Generating inspector files", - tools = [ -- ":code_generator", -+ "@rules_python//python/bin:python", -+ requirement("jinja2"), -+ requirement("markupsafe"), - ], - ) - -@@ -4527,6 +4537,35 @@ - ":v8_libsampler_files", - ":v8_shared_internal_headers", - ], -+) -+ -+cc_library( -+ name = "rusty_v8_internal_headers", -+ hdrs = [ -+ "src/libplatform/default-platform.h", -+ ], -+ strip_include_prefix = "", -+ visibility = ["//visibility:public"], -+) -+ -+cc_library( -+ name = "rusty_v8_crdtp_headers", -+ hdrs = [ -+ "third_party/inspector_protocol/crdtp/cbor.h", -+ "third_party/inspector_protocol/crdtp/dispatch.h", -+ "third_party/inspector_protocol/crdtp/error_support.h", -+ "third_party/inspector_protocol/crdtp/export.h", -+ "third_party/inspector_protocol/crdtp/find_by_first.h", -+ "third_party/inspector_protocol/crdtp/frontend_channel.h", -+ "third_party/inspector_protocol/crdtp/json.h", -+ "third_party/inspector_protocol/crdtp/parser_handler.h", -+ "third_party/inspector_protocol/crdtp/protocol_core.h", -+ "third_party/inspector_protocol/crdtp/serializable.h", -+ "third_party/inspector_protocol/crdtp/span.h", -+ "third_party/inspector_protocol/crdtp/status.h", -+ ], -+ strip_include_prefix = "", -+ visibility = ["//visibility:public"], - ) - - filegroup( -@@ -4609,11 +4648,9 @@ - strip_include_prefix = "noicu", - ) - --cc_library( -+alias( - name = "llvm_libc_headers", -- hdrs = glob(["third_party/llvm-libc/src/shared/**/*.h"]), -- includes = ["third_party/llvm-libc/src"], -- defines = ["LIBC_NAMESPACE=__llvm_libc_cr"], -+ actual = "@@//third_party/v8:rusty_v8_llvm_libc_headers", - ) - - v8_library( -@@ -4625,9 +4662,9 @@ - copts = ["-Wno-implicit-fallthrough"], - deps = [ - ":llvm_libc_headers", -- "@abseil-cpp//absl/synchronization", -- "@abseil-cpp//absl/time", -- "@abseil-cpp//absl/functional:overload", -+ "@v8_abseil//:synchronization", -+ "@v8_abseil//:time", -+ "@v8_abseil//:overload", - ], - ) - -@@ -4655,21 +4692,14 @@ - deps = [ - ":torque_base_headers", - ":v8_libbase", -- "@abseil-cpp//absl/container:node_hash_map", -- "@abseil-cpp//absl/container:node_hash_set", -- ], --) -- --cc_library( -- name = "simdutf", -- srcs = ["third_party/simdutf/simdutf.cpp"], -- hdrs = ["third_party/simdutf/simdutf.h"], -- copts = select({ -- "@v8//bazel/config:is_clang": ["-std=c++20"], -- "@v8//bazel/config:is_gcc": ["-std=gnu++2a"], -- "@v8//bazel/config:is_windows": ["/std:c++20"], -- "//conditions:default": [], -- }), -+ "@v8_abseil//:node_hash_map", -+ "@v8_abseil//:node_hash_set", -+ ], -+) -+ -+alias( -+ name = "simdutf", -+ actual = "@simdutf//:simdutf", - ) - - v8_library( -@@ -4686,7 +4716,7 @@ - copts = ["-Wno-implicit-fallthrough"], - icu_deps = [ - ":icu/generated_torque_definitions_headers", -- "//external:icu", -+ "@icu//:icu", - ], - icu_srcs = [ - ":generated_regexp_special_case", -@@ -4701,14 +4731,14 @@ - ], - deps = [ - ":lib_dragonbox", -- "//third_party/fast_float/src:fast_float", -+ "@fast_float//:fast_float", - ":lib_fp16", - ":simdutf", - ":v8_libbase", -- "@abseil-cpp//absl/container:btree", -- "@abseil-cpp//absl/container:flat_hash_map", -- "@abseil-cpp//absl/container:flat_hash_set", -- "@abseil-cpp//absl/functional:overload", -+ "@v8_abseil//:btree", -+ "@v8_abseil//:flat_hash_map", -+ "@v8_abseil//:flat_hash_set", -+ "@v8_abseil//:overload", - "@highway//:hwy", - ], - ) -@@ -4757,6 +4787,7 @@ - alias( - name = "core_lib_icu", - actual = "icu/v8", -+ visibility = ["//visibility:public"], - ) - - v8_library( -@@ -4808,7 +4839,7 @@ - ], - deps = [ - ":v8_libbase", -- "//external:icu", -+ "@icu//:icu", - ], - ) - -@@ -4830,8 +4861,8 @@ - }), - deps = [ - "v8_libbase", -- "@abseil-cpp//absl/container:node_hash_map", -- "@abseil-cpp//absl/container:node_hash_set", -+ "@v8_abseil//:node_hash_map", -+ "@v8_abseil//:node_hash_set", - ], - ) - -@@ -4852,9 +4883,20 @@ - ":icu/generated_torque_initializers", - ":icu/v8_initializers_files", - ], -+ # Match GN's mksnapshot `disable_icf` config. If the linker folds distinct -+ # external-reference helpers together while producing the snapshot, the -+ # final embedder binary may not fold the same pair and startup -+ # deserialization will reject the snapshot. -+ # GN also increases the x64 Windows stack reserve because constructing the -+ # snapshot overflows the linker's 1 MiB default. - linkopts = select({ - "@v8//bazel/config:is_android": ["-llog"], -- "//conditions:default": [], -+ "@v8//bazel/config:is_macos": ["-Wl,-no_deduplicate"], -+ "@v8//bazel/config:is_windows": [ -+ "-Wl,/OPT:NOICF", -+ "-Wl,/STACK:2097152", -+ ], -+ "//conditions:default": ["-Wl,--icf=none"], - }), - noicu_deps = [":v8_libshared_noicu"], - noicu_srcs = [ diff --git a/patches/v8_module_deps.patch b/patches/v8_module_deps.patch deleted file mode 100644 index b0ce2f6298..0000000000 --- a/patches/v8_module_deps.patch +++ /dev/null @@ -1,231 +0,0 @@ -# What: remove Chromium's checkout-only toolchain bootstrapping and expose one -# module-extension bridge for dependency imports owned by Codex. -# Scope: V8 MODULE and the small ingress extension only. Versions, BUILD files, -# and dependency build policy live in //third_party/v8. - -diff --git a/orig/v8-15.2.124.1/MODULE.bazel b/mod/v8-15.2.124.1/MODULE.bazel ---- a/orig/v8-15.2.124.1/MODULE.bazel -+++ b/mod/v8-15.2.124.1/MODULE.bazel -@@ -7,13 +7,13 @@ - bazel_dep(name = "rules_cc", version = "0.2.17") - bazel_dep(name = "rules_python", version = "1.7.0") - bazel_dep(name = "platforms", version = "1.0.0") --bazel_dep(name = "abseil-cpp", version = "20250814.1") --bazel_dep(name = "highway", version = "1.2.0") - - pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") - pip.parse( - hub_name = "v8_python_deps", - python_version = "3.11", -+ # Use the pip resolver to preserve V8's hashes and repository names. -+ simpleapi_skip = ["jinja2", "markupsafe"], - requirements_lock = "//:bazel/requirements.txt", - extra_pip_args = [ - "--require-hashes", -@@ -22,179 +22,15 @@ - ) - use_repo(pip, "v8_python_deps") - --# Define the local LLVM toolchain repository --llvm_toolchain_repository = use_repo_rule("//bazel/toolchain:llvm_repository.bzl", "llvm_toolchain_repository") -- --llvm_toolchain_repository( -- name = "llvm_toolchain", -- path = "third_party/llvm-build/Release+Asserts", -- config_file_content = """ --load("@rules_cc//cc:defs.bzl", "CcToolchainConfigInfo", "cc_common") --load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "feature", "flag_group", "flag_set", "tool_path") -- --def _impl(ctx): -- tool_paths = [ -- tool_path(name = "gcc", path = "bin/clang"), -- tool_path(name = "ld", path = "bin/lld"), -- tool_path(name = "ar", path = "bin/llvm-ar"), -- tool_path(name = "cpp", path = "bin/clang++"), -- tool_path(name = "gcov", path = "/bin/false"), -- tool_path(name = "nm", path = "bin/llvm-nm"), -- tool_path(name = "objdump", path = "bin/llvm-objdump"), -- tool_path(name = "strip", path = "bin/llvm-strip"), -- ] -- -- features = [ -- feature( -- name = "default_compile_flags", -- enabled = True, -- flag_sets = [ -- flag_set( -- actions = [ -- "c-compile", -- "c++-compile", -- "c++-header-parsing", -- "c++-module-compile", -- "c++-module-codegen", -- "linkstamp-compile", -- "assemble", -- "preprocess-assemble", -- ], -- flag_groups = [ -- flag_group( -- flags = [ -- "--sysroot={WORKSPACE_ROOT}/build/linux/debian_bullseye_amd64-sysroot", -- "-nostdinc++", -- "-isystem", -- "{WORKSPACE_ROOT}/buildtools/third_party/libc++", -- "-isystem", -- "{WORKSPACE_ROOT}/third_party/libc++/src/include", -- "-isystem", -- "{WORKSPACE_ROOT}/third_party/libc++abi/src/include", -- "-isystem", -- "{WORKSPACE_ROOT}/third_party/libc++/src/src", -- "-isystem", -- "{WORKSPACE_ROOT}/third_party/llvm-libc/src", -- "-D_LIBCPP_HARDENING_MODE_DEFAULT=_LIBCPP_HARDENING_MODE_NONE", -- "-DLIBC_NAMESPACE=__llvm_libc_cr", -- ], -- ), -- ], -- ), -- ], -- ), -- feature( -- name = "default_linker_flags", -- enabled = True, -- flag_sets = [ -- flag_set( -- actions = [ -- "c++-link-executable", -- "c++-link-dynamic-library", -- "c++-link-nodeps-dynamic-library", -- ], -- flag_groups = [ -- flag_group( -- flags = [ -- "--sysroot={WORKSPACE_ROOT}/build/linux/debian_bullseye_amd64-sysroot", -- "-fuse-ld=lld", -- "-lm", -- "-lpthread", -- ], -- ), -- ], -- ), -- ], -- ), -- ] -- -- return cc_common.create_cc_toolchain_config_info( -- ctx = ctx, -- toolchain_identifier = "local_clang", -- features = features, -- cxx_builtin_include_directories = [ -- "{WORKSPACE_ROOT}/buildtools/third_party/libc++", -- "{WORKSPACE_ROOT}/third_party/libc++/src/include", -- "{WORKSPACE_ROOT}/third_party/libc++abi/src/include", -- "{WORKSPACE_ROOT}/third_party/libc++/src/src", -- "{WORKSPACE_ROOT}/third_party/llvm-libc/src", -- "{WORKSPACE_ROOT}/third_party/llvm-build/Release+Asserts/lib/clang/22/include", -- "{WORKSPACE_ROOT}/third_party/llvm-build/Release+Asserts/lib/clang/23/include", -- "{WORKSPACE_ROOT}/build/linux/debian_bullseye_amd64-sysroot/usr/include", -- "{WORKSPACE_ROOT}/build/linux/debian_bullseye_amd64-sysroot/usr/local/include", -- ], -- host_system_name = "local", -- target_system_name = "local", -- target_cpu = "k8", -- target_libc = "unknown", -- compiler = "clang", -- abi_version = "unknown", -- abi_libc_version = "unknown", -- tool_paths = tool_paths, -- ) -- --cc_toolchain_config = rule( -- implementation = _impl, -- attrs = {}, -- provides = [CcToolchainConfigInfo], -+# Codex supplies the dependency repositories used by its V8 builds. -+codex_deps = use_extension("//:bazel/codex_deps.bzl", "codex_deps") -+use_repo( -+ codex_deps, -+ "v8_abseil", -+ "dragonbox", -+ "fast_float", -+ "fp16", -+ "highway", -+ "icu", -+ "simdutf", - ) --""", -- build_file_content = """ --load("@rules_cc//cc:defs.bzl", "cc_toolchain") --load(":cc_toolchain_config.bzl", "cc_toolchain_config") -- --package(default_visibility = ["//visibility:public"]) -- --filegroup( -- name = "all_files", -- srcs = glob(["**/*"]), --) -- --filegroup(name = "empty") -- --cc_toolchain_config(name = "k8_toolchain_config") -- --cc_toolchain( -- name = "k8_toolchain", -- all_files = ":all_files", -- ar_files = ":all_files", -- compiler_files = ":all_files", -- dwp_files = ":empty", -- linker_files = ":all_files", -- objcopy_files = ":all_files", -- strip_files = ":all_files", -- supports_param_files = 0, -- toolchain_config = ":k8_toolchain_config", -- toolchain_identifier = "local_clang", --) -- --toolchain( -- name = "cc_toolchain_k8", -- exec_compatible_with = [ -- "@platforms//cpu:x86_64", -- "@platforms//os:linux", -- ], -- target_compatible_with = [ -- "@platforms//cpu:x86_64", -- "@platforms//os:linux", -- ], -- toolchain = ":k8_toolchain", -- toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", --) --""", --) -- --register_toolchains("@llvm_toolchain//:cc_toolchain_k8") -- --# Define local repository for libc++ from third_party sources --libcxx_repository = use_repo_rule("//bazel/toolchain:libcxx_repository.bzl", "libcxx_repository") -- --libcxx_repository( -- name = "libcxx", --) -- --single_version_override( -- module_name = "highway", -- patches = ["//bazel/patches:highway_rules_cc.patch"], -- patch_strip = 1, --) - -diff --git a/orig/v8-15.2.124.1/bazel/codex_deps.bzl b/mod/v8-15.2.124.1/bazel/codex_deps.bzl -new file mode 100644 ---- /dev/null -+++ b/mod/v8-15.2.124.1/bazel/codex_deps.bzl -@@ -0,0 +1,10 @@ -+"""Dependency ingress for V8 when built by Codex. -+ -+The root module injects the repositories; this extension declares no defaults -+that could silently select a different dependency from the one Codex builds. -+""" -+ -+def _codex_deps_impl(module_ctx): -+ return module_ctx.extension_metadata(reproducible = True) -+ -+codex_deps = module_extension(implementation = _codex_deps_impl) diff --git a/third_party/v8/BUILD.bazel b/third_party/v8/BUILD.bazel index 333a608f37..ebc2a802be 100644 --- a/third_party/v8/BUILD.bazel +++ b/third_party/v8/BUILD.bazel @@ -10,11 +10,15 @@ exports_files([ "dependencies.bzl", "dependency_config.bzl", "dragonbox.BUILD.bazel", + "engine.BUILD.bazel", + "engine_repository.bzl", + "engine_rules.bzl", "fast_float.BUILD.bazel", "fp16.BUILD.bazel", "highway.BUILD.bazel", "icu.BUILD.bazel", "simdutf.BUILD.bazel", + "v8_defs.patch", ]) config_setting( diff --git a/third_party/v8/README.md b/third_party/v8/README.md index b9659d957e..9c60403e98 100644 --- a/third_party/v8/README.md +++ b/third_party/v8/README.md @@ -35,6 +35,10 @@ Use this as the maintainer flow for a version bump: 2. Update the Bazel versioned inputs in `MODULE.bazel` and the source pins in `third_party/v8/dependencies.bzl` and `abseil_repository.bzl` using [the source dependency update procedure](#updating-source-dependencies). + Verify the imported source groups by querying the source archive and generating Torque + and snapshots for each supported platform. If V8 changes its BUILD section + layout, the importer fails instead of silently using an old inventory; + update that boundary and review its fixed feature and CPU selections. Then refresh the matching checksum manifest and generated checksums below. 3. Publish a release-candidate PR and validate that `v8-canary` passes. 4. If the canary is green, publish the release tag and release build. @@ -147,10 +151,20 @@ here declare the targets V8 uses. Abseil, Highway and simdutf apply their C++ ru settings through `dependency_config.bzl`; ICU defines its settings in its own overlay. -V8's module has a small dependency ingress. The root `MODULE.bazel` injects -the seven Codex repositories there, so V8's `@highway`, `@icu`, etc. resolve to -the same repositories Codex declares. The bridge has no fallback downloads. -V8's BUILD patch still wires these targets into its generator and library graph. +`engine_repository.bzl` fetches the V8 source pin and installs Codex's engine +BUILD into `@v8`. Source filegroups are read from the pinned upstream BUILD +each fetch, including added, removed or reordered groups. The importer rejects +missing boundaries, malformed or empty sections, and new compiled targets. Only +the two known Dragonbox and FP16 declarations are skipped, since the dependency +overlays already supply them. `v8_binary` is valid V8 syntax, but compiled targets +must be reviewed against the owned engine BUILD on an upgrade. The +upstream `bazel/config` platform and CPU package is reused unchanged. +`v8_defs.patch` records just the Codex differences to upstream's +`bazel/defs.bzl`: release flag visibility, libc++ headers/runtime, Windows +compiler and linker settings, and snapshot generation. All engine rules, +including Torque and V8's test configuration helpers, load from that file. +The engine BUILD owns feature policy and dependency targets; the remaining V8 +ABI, runtime and CPU settings still support the existing release commands. V8's private Abseil is built from the pinned 20250814.1 sources and uses `codex_v8_lts_20250814` for its supported inline-namespace option. Protobuf @@ -165,9 +179,12 @@ autoupdater: the prebuilt checksum commands above and their CI check validate published archive/binding pairs, not these source revisions. Bazel verifies the declared download hashes and Git revisions; it does not choose them for us. -Use the V8 tag in the root `MODULE.bazel` `archive_override(module_name = "v8")` +Use the V8 tag in the root `MODULE.bazel` `engine_repository(name = "v8")` (currently `15.2.124.1`) as the input. Read that tag's **unpatched** `DEPS` -and `MODULE.bazel`; the fetched `@v8` MODULE has Codex's bridge applied. +and `MODULE.bazel`; `@v8` deliberately does not include upstream's MODULE. +On an upgrade, also review `v8_defs.patch` against the new `bazel/defs.bzl` +and run the V8 source canary. A cleanly applying patch does not by itself +verify new upstream defaults or code-generation behavior. ```bash v8_tag=15.2.124.1 # Replace with the V8 source tag selected for this upgrade. diff --git a/third_party/v8/engine.BUILD.bazel b/third_party/v8/engine.BUILD.bazel new file mode 100644 index 0000000000..dba5eca64d --- /dev/null +++ b/third_party/v8/engine.BUILD.bazel @@ -0,0 +1,933 @@ +# Copyright 2021 the V8 project authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +load("@@//third_party/v8:engine_rules.bzl", "v8_fixed_source_features") +load("@bazel_skylib//lib:selects.bzl", "selects") +load("@rules_cc//cc:cc_library.bzl", "cc_library") +load("@rules_python//python:defs.bzl", "py_binary", "py_test") +load( + "@v8//:bazel/defs.bzl", + "v8_binary", + "v8_build_config", + "v8_config", + "v8_flag", + "v8_library", + "v8_mksnapshot", + "v8_string", + "v8_torque_files", +) +load("@v8//:bazel/v8-non-pointer-compression.bzl", "v8_binary_non_pointer_compression") +load("@v8_python_deps//:requirements.bzl", "requirement") + +# Used by the Codex-owned pip hub; pin changes travel with the V8 source. +exports_files(["bazel/requirements.txt"]) + +# Codex V8 source policy. Only ABI, runtime and target CPU vary; these still +# accept the existing release inputs. CPU selection lives in bazel/config. +# Upstream experiments, profiling and debug flags use their pinned 15.2 defaults. +# ICU and no-ICU remain separate targets for the engine and its generators. +v8_flag(name = "v8_enable_sandbox") + +v8_flag(name = "v8_use_rusty_v8_custom_libcxx") + +# Maglev is supported on the two architectures shipped by Codex. Keep the +# architecture tests separate from feature policy for host-tool transitions. +selects.config_setting_group( + name = "enable_maglev", + match_any = [ + "@v8//bazel/config:v8_target_x64", + "@v8//bazel/config:v8_target_arm64", + ], +) + +selects.config_setting_group( + name = "enable_maglev_x64", + match_all = [ + ":enable_maglev", + "@v8//bazel/config:v8_target_x64", + ], +) + +selects.config_setting_group( + name = "enable_maglev_arm64", + match_all = [ + ":enable_maglev", + "@v8//bazel/config:v8_target_arm64", + ], +) + +# WebAssembly remains enabled; its source implementation still depends on OS. +selects.config_setting_group( + name = "webassembly_on_posix", + match_any = ["@v8//bazel/config:is_posix"], +) + +selects.config_setting_group( + name = "webassembly_on_windows", + match_any = ["@v8//bazel/config:is_windows"], +) + +# Artifact transitions set True or False, never the upstream "none" auto mode. +# The 32-bit Torque helper can also force this off. +v8_string( + name = "v8_enable_pointer_compression", + default = "False", + visibility = ["//visibility:public"], +) + +config_setting( + name = "is_v8_enable_pointer_compression", + flag_values = {":v8_enable_pointer_compression": "True"}, +) + +# V8's pinned default short-call policy differs on x64 and arm64. In particular +# the legacy arm64 non-pointer-compressed profile still uses short calls. +selects.config_setting_group( + name = "v8_target_x64_default_short_builtin_calls", + match_all = [ + "@v8//bazel/config:v8_target_x64", + ":is_v8_enable_pointer_compression", + ], +) + +selects.config_setting_group( + name = "v8_target_arm64_default_short_builtin_calls", + match_all = [ + "@v8//bazel/config:v8_target_arm64", + "@v8//bazel/config:is_not_android", + ], +) + +selects.config_setting_group( + name = "is_v8_enable_short_builtin_calls", + match_any = [ + ":v8_target_x64_default_short_builtin_calls", + ":v8_target_arm64_default_short_builtin_calls", + ], +) + +# Fixed V8 15.2 Codex feature contract: TurboFan and WebAssembly enabled; +# experiments, VTune and profiling disabled. Do not hard-code ABI-sensitive +# values such as sandbox, pointer compression or target CPU into this baseline. +v8_config( + name = "define_flags", + conditional_defines = {"v8_enable_sandbox": "V8_ENABLE_SANDBOX"}, + defines = [ + "V8_DEPRECATION_WARNINGS", + "V8_IMMINENT_DEPRECATION_WARNINGS", + "V8_ENABLE_LAZY_SOURCE_POSITIONS", + "V8_ENABLE_TURBOFAN", + "V8_ENABLE_WEBASSEMBLY", + "V8_ENABLE_UNDEFINED_DOUBLE", + "V8_USE_HOST_CPU_ARM_FEATURES", + "V8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64", + ] + [ + "GOOGLE3", + "V8_ADVANCED_BIGINT_ALGORITHMS", + "V8_CONCURRENT_MARKING", + "V8_ENABLE_SPARKPLUG", + "V8_ENABLE_EXTENSIBLE_RO_SNAPSHOT", + "V8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA", + "V8_TLS_USED_IN_LIBRARY", + ] + select({ + "@v8//bazel/config:is_debug": [ + "DEBUG", + "V8_ENABLE_CHECKS", + ], + "//conditions:default": [], + }) + select({ + "@v8//bazel/config:asan_enabled": ["V8_USE_ADDRESS_SANITIZER"], + "//conditions:default": [], + }) + select({ + "@v8//bazel/config:hwasan_enabled": ["V8_USE_HWADDRESS_SANITIZER"], + "//conditions:default": [], + }) + select({ + "@v8//bazel/config:msan_enabled": ["V8_USE_MEMORY_SANITIZER"], + "//conditions:default": [], + }) + select({ + "@v8//bazel/config:ubsan_enabled": ["V8_USE_UNDEFINED_BEHAVIOR_SANITIZER"], + "//conditions:default": [], + }) + select( + { + "@v8//bazel/config:v8_target_ia32": ["V8_TARGET_ARCH_IA32"], + "@v8//bazel/config:v8_target_x64": [ + "V8_TARGET_ARCH_X64", + "V8_ENABLE_SPARKPLUG_PLUS", + ], + "@v8//bazel/config:v8_target_arm": [ + "V8_TARGET_ARCH_ARM", + "CAN_USE_ARMV7_INSTRUCTIONS", + "CAN_USE_VFP3_INSTRUCTIONS", + ], + "@v8//bazel/config:v8_target_arm64": [ + "V8_TARGET_ARCH_ARM64", + "V8_ENABLE_SPARKPLUG_PLUS", + ], + "@v8//bazel/config:v8_target_s390x": [ + "V8_TARGET_ARCH_S390X", + ], + "@v8//bazel/config:v8_target_riscv64": [ + # NOTE: Bazel rules for riscv64 weren't tested on a real system. + "V8_TARGET_ARCH_RISCV64", + "CAN_USE_FPU_INSTRUCTIONS", + ], + "@v8//bazel/config:v8_target_ppc64le": [ + # NOTE: Bazel rules for ppc64le weren't tested on a real system. + "V8_TARGET_ARCH_PPC64", + ], + }, + no_match_error = "Please specify a target cpu supported by v8", + ) + select({ + "@v8//bazel/config:is_android": [ + "V8_HAVE_TARGET_OS", + "V8_TARGET_OS_ANDROID", + ], + "@v8//bazel/config:is_linux": [ + "V8_HAVE_TARGET_OS", + "V8_TARGET_OS_LINUX", + ], + "@v8//bazel/config:is_macos": [ + "V8_HAVE_TARGET_OS", + "V8_TARGET_OS_MACOS", + ], + "@v8//bazel/config:is_windows": [ + "V8_HAVE_TARGET_OS", + "V8_TARGET_OS_WIN", + "UNICODE", + "_UNICODE", + "_CRT_RAND_S", + "_WIN32_WINNT=0x0A00", + ], + }) + select({ + ":is_v8_enable_pointer_compression": [ + "V8_COMPRESS_POINTERS", + "V8_31BIT_SMIS_ON_64BIT_ARCH", + "V8_CONTIGUOUS_COMPRESSED_RO_SPACE", + "V8_CONTIGUOUS_COMPRESSED_RO_SPACE_SIZE_MB=8", + ], + "//conditions:default": [], + }) + select({ + ":is_v8_enable_pointer_compression": [ + "V8_COMPRESS_POINTERS_IN_SHARED_CAGE", + ], + "//conditions:default": [], + }) + select({ + ":is_v8_enable_short_builtin_calls": [ + "V8_SHORT_BUILTIN_CALLS", + ], + "//conditions:default": [], + }) + select({ + ":is_v8_enable_pointer_compression": [ + "V8_EXTERNAL_CODE_SPACE", + ], + "//conditions:default": [], + }) + select({ + ":is_v8_enable_pointer_compression": [ + "V8_STATIC_ROOTS", + ], + "//conditions:default": [], + }) + select({ + ":enable_maglev": [ + "V8_ENABLE_MAGLEV", + ], + "//conditions:default": [], + }) + [] + [], + deps = [], +) + +# Source inventory and dependency aliases. + +# The imported groups retain upstream select names. They express our pinned +# feature contract here; only CPU, ABI and the C++ runtime actually vary. +v8_fixed_source_features( + name = "pinned_source_features", + build_setting_default = True, +) + +config_setting( + name = "is_v8_enable_webassembly", + flag_values = {":pinned_source_features": "True"}, +) + +config_setting( + name = "disabled_pinned_source_feature", + flag_values = {":pinned_source_features": "False"}, +) + +alias( + name = "enable_drumbrake_arm64", + actual = ":disabled_pinned_source_feature", +) + +alias( + name = "enable_drumbrake_x64", + actual = ":disabled_pinned_source_feature", +) + +alias( + name = "enable_maglev_arm", + actual = ":disabled_pinned_source_feature", +) + +alias( + name = "enable_maglev_riscv", + actual = ":disabled_pinned_source_feature", +) + +alias( + name = "is_v8_enable_drumbrake", + actual = ":disabled_pinned_source_feature", +) + +alias( + name = "is_v8_enable_experimental_tq_to_tsa", + actual = ":disabled_pinned_source_feature", +) + +alias( + name = "is_v8_wasm_random_fuzzers", + actual = ":disabled_pinned_source_feature", +) + +# @CODEX_V8_UPSTREAM_FILEGROUPS@ + +alias( + name = "lib_dragonbox", + actual = "@v8_dragonbox//:dragonbox", +) + +alias( + name = "lib_fp16", + actual = "@v8_fp16//:fp16", +) + +# Generated files + +# Define file groups for torque definitions and initializers. Both are +# generated together, but we can use output_group to split them. +filegroup( + name = "icu/generated_torque_definitions", + srcs = [":icu/generated_torque_files"], + output_group = "definitions", +) + +filegroup( + name = "noicu/generated_torque_definitions", + srcs = [":noicu/generated_torque_files"], + output_group = "definitions", +) + +filegroup( + name = "icu/generated_torque_initializers", + srcs = [":icu/generated_torque_files"], + output_group = "initializers", +) + +filegroup( + name = "noicu/generated_torque_initializers", + srcs = [":noicu/generated_torque_files"], + output_group = "initializers", +) + +# TODO(victorgomes): Add support to tools/debug_helper, +# which needs class-debug-readers and debug-macros. +v8_torque_files( + name = "generated_torque_files", + args = [] + select({ + "@v8//bazel/config:v8_target_is_32_bits": ["-m32"], + "//conditions:default": [], + }), + definition_extras = [ + "bit-field-asserts.cc", + "builtin-definitions.h", + # "class-debug-readers.cc", + # "class-debug-readers.h", + "class-forward-declarations.h", + # "debug-macros.cc", + # "debug-macros.h", + "instance-types.h", + "interface-descriptors.inc", + ], + icu_srcs = [":icu/torque_files"], + initializer_extras = [ + "csa-types.h", + "enum-verifiers.cc", + "exported-macros-assembler.cc", + "exported-macros-assembler.h", + ], + noicu_srcs = [":noicu/torque_files"], +) + +py_binary( + name = "code_generator", + srcs = [ + "third_party/inspector_protocol/code_generator.py", + "third_party/inspector_protocol/pdl.py", + ], + data = [ + "third_party/inspector_protocol/lib/Forward_h.template", + "third_party/inspector_protocol/lib/Object_cpp.template", + "third_party/inspector_protocol/lib/Object_h.template", + "third_party/inspector_protocol/lib/Protocol_cpp.template", + "third_party/inspector_protocol/lib/ValueConversions_cpp.template", + "third_party/inspector_protocol/lib/ValueConversions_h.template", + "third_party/inspector_protocol/lib/Values_cpp.template", + "third_party/inspector_protocol/lib/Values_h.template", + "third_party/inspector_protocol/templates/Exported_h.template", + "third_party/inspector_protocol/templates/Imported_h.template", + "third_party/inspector_protocol/templates/TypeBuilder_cpp.template", + "third_party/inspector_protocol/templates/TypeBuilder_h.template", + ], + imports = ["third_party/inspector_protocol/"], + deps = [ + requirement("jinja2"), + ], +) + +genrule( + name = "generated_inspector_files", + srcs = [ + "include/js_protocol.pdl", + "src/inspector/inspector_protocol_config.json", + "third_party/inspector_protocol/code_generator.py", + "third_party/inspector_protocol/pdl.py", + "third_party/inspector_protocol/lib/Forward_h.template", + "third_party/inspector_protocol/lib/Object_cpp.template", + "third_party/inspector_protocol/lib/Object_h.template", + "third_party/inspector_protocol/lib/Protocol_cpp.template", + "third_party/inspector_protocol/lib/ValueConversions_cpp.template", + "third_party/inspector_protocol/lib/ValueConversions_h.template", + "third_party/inspector_protocol/lib/Values_cpp.template", + "third_party/inspector_protocol/lib/Values_h.template", + "third_party/inspector_protocol/templates/Exported_h.template", + "third_party/inspector_protocol/templates/Imported_h.template", + "third_party/inspector_protocol/templates/TypeBuilder_cpp.template", + "third_party/inspector_protocol/templates/TypeBuilder_h.template", + ], + outs = [ + "include/inspector/Debugger.h", + "include/inspector/Runtime.h", + "include/inspector/Schema.h", + "src/inspector/protocol/Forward.h", + "src/inspector/protocol/Protocol.cpp", + "src/inspector/protocol/Protocol.h", + "src/inspector/protocol/Console.cpp", + "src/inspector/protocol/Console.h", + "src/inspector/protocol/Debugger.cpp", + "src/inspector/protocol/Debugger.h", + "src/inspector/protocol/HeapProfiler.cpp", + "src/inspector/protocol/HeapProfiler.h", + "src/inspector/protocol/Profiler.cpp", + "src/inspector/protocol/Profiler.h", + "src/inspector/protocol/Runtime.cpp", + "src/inspector/protocol/Runtime.h", + "src/inspector/protocol/Schema.cpp", + "src/inspector/protocol/Schema.h", + ], + cmd = "INSPECTOR_PROTOCOL_DIR=$$(dirname $(execpath third_party/inspector_protocol/code_generator.py)); \ + PYTHONPATH=$$INSPECTOR_PROTOCOL_DIR:external/rules_python++pip+v8_python_deps_311_jinja2/site-packages:external/rules_python++pip+v8_python_deps_311_markupsafe/site-packages:$${PYTHONPATH-} \ + $(execpath @rules_python//python/bin:python) $(execpath third_party/inspector_protocol/code_generator.py) --jinja_dir . \ + --inspector_protocol_dir $$INSPECTOR_PROTOCOL_DIR \ + --config $(location :src/inspector/inspector_protocol_config.json) \ + --config_value protocol.path=$(location :include/js_protocol.pdl) \ + --config_value crdtp.dir=third_party/inspector_protocol/crdtp \ + --output_base $(@D)/src/inspector", + message = "Generating inspector files", + tools = [ + "@rules_python//python/bin:python", + requirement("jinja2"), + requirement("markupsafe"), + ], +) + +filegroup( + name = "v8_common_libshared_files", + srcs = [ + ":torque_runtime_support_files", + ":v8_libplatform_files", + ":v8_libsampler_files", + ":v8_shared_internal_headers", + ], +) + +cc_library( + name = "rusty_v8_internal_headers", + hdrs = [ + "src/libplatform/default-platform.h", + ], + strip_include_prefix = "", + visibility = ["//visibility:public"], +) + +cc_library( + name = "rusty_v8_crdtp_headers", + hdrs = [ + "third_party/inspector_protocol/crdtp/cbor.h", + "third_party/inspector_protocol/crdtp/dispatch.h", + "third_party/inspector_protocol/crdtp/error_support.h", + "third_party/inspector_protocol/crdtp/export.h", + "third_party/inspector_protocol/crdtp/find_by_first.h", + "third_party/inspector_protocol/crdtp/frontend_channel.h", + "third_party/inspector_protocol/crdtp/json.h", + "third_party/inspector_protocol/crdtp/parser_handler.h", + "third_party/inspector_protocol/crdtp/protocol_core.h", + "third_party/inspector_protocol/crdtp/serializable.h", + "third_party/inspector_protocol/crdtp/span.h", + "third_party/inspector_protocol/crdtp/status.h", + ], + strip_include_prefix = "", + visibility = ["//visibility:public"], +) + +filegroup( + name = "d8_files", + srcs = [ + "src/d8/async-hooks-wrapper.cc", + "src/d8/async-hooks-wrapper.h", + "src/d8/d8.cc", + "src/d8/d8.h", + "src/d8/d8-console.cc", + "src/d8/d8-console.h", + "src/d8/d8-js.cc", + "src/d8/d8-platforms.cc", + "src/d8/d8-platforms.h", + "src/d8/d8-posix.cc", + "src/d8/d8-test.cc", + "src/d8/hardware-watchpoints.cc", + "src/d8/hardware-watchpoints.h", + "src/d8/memory-access-information.cc", + "src/d8/memory-access-information.h", + ], +) + +genrule( + name = "generated_bytecode_builtins_list", + srcs = [], + outs = ["builtins-generated/bytecodes-builtins-list.h"], + cmd = "$(location :bytecode_builtins_list_generator) $@", + cmd_bat = "$(location :bytecode_builtins_list_generator) $@", + tools = [":bytecode_builtins_list_generator"], +) + +genrule( + name = "generated_regexp_special_case", + srcs = [], + outs = ["src/regexp/special-case.cc"], + cmd = "$(location :regexp_special_case_generator) $@", + cmd_bat = "$(location :regexp_special_case_generator) $@", + tools = [":regexp_special_case_generator"], +) + +v8_mksnapshot( + name = "generated_snapshot_files", + args = [] + [] + [] + ["--no-native-code-counters"], +) + +# ================================================= +# Libraries rules +# ================================================= + +# NOTE: This allow headers to be accessed without the icu/noicu prefixes. +cc_library( + name = "icu/generated_torque_definitions_headers", + hdrs = [":icu/generated_torque_definitions"], + copts = ["-Wno-implicit-fallthrough"], + strip_include_prefix = "icu", +) + +cc_library( + name = "noicu/generated_torque_definitions_headers", + hdrs = [":noicu/generated_torque_definitions"], + copts = ["-Wno-implicit-fallthrough"], + strip_include_prefix = "noicu", +) + +alias( + name = "llvm_libc_headers", + actual = "@@//third_party/v8:rusty_v8_llvm_libc_headers", +) + +v8_library( + name = "v8_libbase", + srcs = [ + ":v8_libbase_files", + ":v8_shared_internal_headers", + ], + copts = ["-Wno-implicit-fallthrough"], + deps = [ + ":llvm_libc_headers", + "@v8_abseil//:overload", + "@v8_abseil//:synchronization", + "@v8_abseil//:time", + ], +) + +cc_library( + name = "torque_base_headers", + hdrs = [ + "src/torque/kythe-data.h", + "src/torque/torque-compiler.h", + ], + copts = ["-Wno-implicit-fallthrough"], + include_prefix = "third_party/v8", + includes = ["."], +) + +cc_library( + name = "kythe_torque_base", + srcs = [ + ":torque_base_files", + ], + copts = ["-Wno-implicit-fallthrough"] + select({ + "@v8//bazel/config:is_posix": ["-fexceptions"], + "//conditions:default": [], + }), + features = ["-use_header_modules"], + deps = [ + ":torque_base_headers", + ":v8_libbase", + "@v8_abseil//:node_hash_map", + "@v8_abseil//:node_hash_set", + ], +) + +alias( + name = "simdutf", + actual = "@v8_simdutf//:simdutf", +) + +v8_library( + name = "v8_libshared", + srcs = [ + ":v8_base_without_compiler_files", + ":v8_common_libshared_files", + ] + [ + ":v8_compiler_files", + ], + copts = ["-Wno-implicit-fallthrough"], + icu_deps = [ + ":icu/generated_torque_definitions_headers", + "@v8_icu//:icu", + ], + icu_srcs = [ + ":generated_regexp_special_case", + ":icu/generated_torque_definitions", + ":icu/v8_base_without_compiler_files", + ], + noicu_deps = [ + ":noicu/generated_torque_definitions_headers", + ], + noicu_srcs = [ + ":noicu/generated_torque_definitions", + ], + deps = [ + # keep + ":lib_dragonbox", + "@v8_fast_float//:fast_float", + ":lib_fp16", + ":simdutf", + ":v8_libbase", + "@v8_abseil//:btree", + "@v8_abseil//:flat_hash_map", + "@v8_abseil//:flat_hash_set", + "@v8_abseil//:overload", + "@v8_highway//:hwy", + ], +) + +v8_library( + name = "v8", + srcs = [ + ":v8_inspector_files", + ] + [], + hdrs = [":public_header_files"], + copts = ["-Wno-implicit-fallthrough"], + icu_deps = [":icu/v8_libshared"], + icu_srcs = [":icu/snapshot_files"], + noicu_deps = [":noicu/v8_libshared"], + noicu_srcs = [":noicu/snapshot_files"], + visibility = ["//visibility:public"], +) + +v8_library( + name = "wee8", + srcs = [":wee8_files"], + hdrs = [":public_wasm_c_api_header_files"], + copts = ["-Wno-implicit-fallthrough"], + strip_include_prefix = "third_party", + visibility = ["//visibility:public"], + deps = [":noicu/v8"] + [], +) + +alias( + name = "core_lib_noicu", + actual = "noicu/v8", +) + +alias( + name = "core_lib_icu", + actual = "icu/v8", + visibility = ["//visibility:public"], +) + +v8_library( + name = "v8_vtune", + srcs = [ + "third_party/vtune/v8-vtune.h", + "third_party/vtune/vtune-jit.cc", + "third_party/vtune/vtune-jit.h", + ], + copts = ["-I"], + deps = [ + ":core_lib_noicu", + "@intel_ittapi//:lib_ittapi", + ], +) + +# ================================================= +# Binary rules +# ================================================= + +v8_binary( + name = "bytecode_builtins_list_generator", + srcs = [ + "src/builtins/generate-bytecodes-builtins-list.cc", + "src/interpreter/bytecode-operands.cc", + "src/interpreter/bytecode-operands.h", + "src/interpreter/bytecode-traits.h", + "src/interpreter/bytecodes.cc", + "src/interpreter/bytecodes.h", + ], + copts = ["-Wno-implicit-fallthrough"], + deps = ["v8_libbase"], +) + +v8_binary( + name = "regexp_special_case_generator", + srcs = [ + "src/regexp/gen-regexp-special-case.cc", + "src/regexp/special-case.h", + ":v8_shared_internal_headers", + ], + copts = ["-Wno-implicit-fallthrough"], + defines = [ + "V8_INTL_SUPPORT", + "ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC", + # src/regexp/regexp-compiler-tonode.cc uses an unsafe ICU method and + # access a character implicitly. + "UNISTR_FROM_CHAR_EXPLICIT=", + ], + deps = [ + ":v8_libbase", + "@v8_icu//:icu", + ], +) + +v8_binary( + name = "torque", + srcs = [ + "src/torque/torque.cc", + ":torque_base_files", + ], + copts = ["-Wno-implicit-fallthrough"] + select({ + "@v8//bazel/config:is_posix": ["-fexceptions"], + "//conditions:default": [], + }), + features = ["-use_header_modules"], + icu_defines = ["V8_INTL_SUPPORT"], + linkopts = select({ + "@v8//bazel/config:is_android": ["-llog"], + "//conditions:default": [], + }), + deps = [ + "v8_libbase", + "@v8_abseil//:node_hash_map", + "@v8_abseil//:node_hash_set", + ], +) + +v8_binary( + name = "mksnapshot", + srcs = [ + ":mksnapshot_files", + ] + [], + copts = ["-Wno-implicit-fallthrough"], + icu_deps = [":icu/v8_libshared"], + icu_srcs = [ + ":icu/generated_torque_initializers", + ":icu/v8_initializers_files", + ], + # Match GN's mksnapshot `disable_icf` config. If the linker folds distinct + # external-reference helpers together while producing the snapshot, the + # final embedder binary may not fold the same pair and startup + # deserialization will reject the snapshot. + # GN also increases the x64 Windows stack reserve because constructing the + # snapshot overflows the linker's 1 MiB default. + linkopts = select({ + "@v8//bazel/config:is_android": ["-llog"], + "@v8//bazel/config:is_macos": ["-Wl,-no_deduplicate"], + "@v8//bazel/config:is_windows": [ + "-Wl,/OPT:NOICF", + "-Wl,/STACK:2097152", + ], + "//conditions:default": ["-Wl,--icf=none"], + }), + noicu_deps = [":v8_libshared_noicu"], + noicu_srcs = [ + ":noicu/generated_torque_initializers", + ":noicu/v8_initializers_files", + ], +) + +v8_binary( + name = "d8", + srcs = [":d8_files"], + copts = ["-Wno-implicit-fallthrough"], + icu_deps = [":icu/v8"], + noicu_deps = [":noicu/v8"], +) + +# This target forces torque to be compiled without pointer compression. +v8_binary_non_pointer_compression( + name = "noicu/torque_non_pointer_compression", + binary = "noicu/torque", +) + +v8_binary_non_pointer_compression( + name = "icu/torque_non_pointer_compression", + binary = "icu/torque", +) + +alias( + name = "v8ci", + actual = "noicu/v8", +) + +# ================================================= +# Tests +# ================================================= + +v8_build_config( + name = "v8_build_config", + arch = select({ + "@v8//bazel/config:v8_target_arm64": "arm64", + "@v8//bazel/config:v8_target_x64": "x64", + "//conditions:default": "x64", + }), +) + +# Runs mjsunit with d8. +py_test( + name = "noicu/mjsunit", + size = "medium", + srcs = [ + "test/mjsunit/testcfg.py", + "tools/predictable_wrapper.py", + "tools/run-tests.py", + ] + glob(["tools/testrunner/**/*.py"]), + args = [ + "--no-sorting", + "--nopresubmit", + "--variant=google3", + "--outdir noicu", + "--verbose", + ] + select({ + "@v8//bazel/config:v8_target_arm64": [ + "--arch=arm64", + ], + "@v8//bazel/config:v8_target_x64": [ + "--arch=x64", + ], + "//conditions:default": [], + }) + [ + "mjsunit", + ], + data = [ + "test", + ":noicu/d8", + ":noicu/v8_build_config", + "//testing/pybase", + ] + glob(["test/**"]) + glob(["tools/**/*.js"]) + glob(["tools/**/*.mjs"]), + main = "tools/run-tests.py", + tags = [ + # Disable sanitizers, as they don't work in general in V8. + "nosan", + ], +) + +py_test( + name = "icu/mjsunit", + size = "medium", + srcs = [ + "test/mjsunit/testcfg.py", + "tools/predictable_wrapper.py", + "tools/run-tests.py", + ] + glob(["tools/testrunner/**/*.py"]), + args = [ + "--no-sorting", + "--nopresubmit", + "--variant=google3", + "--outdir icu", + "--verbose", + ] + select({ + "@v8//bazel/config:v8_target_arm64": [ + "--arch=arm64", + ], + "@v8//bazel/config:v8_target_x64": [ + "--arch=x64", + ], + "//conditions:default": [], + }) + [ + "mjsunit", + ], + data = [ + "test", + ":icu/d8", + ":icu/v8_build_config", + "//testing/pybase", + ] + glob(["test/**"]) + glob(["tools/**/*.js"]) + glob(["tools/**/*.mjs"]), + main = "tools/run-tests.py", + tags = [ + # Disable sanitizers, as they don't work in general in V8. + "nosan", + ], +) + +py_test( + name = "icu/intl", + size = "medium", + srcs = [ + "test/intl/testcfg.py", + "tools/predictable_wrapper.py", + "tools/run-tests.py", + ] + glob(["tools/testrunner/**/*.py"]), + args = [ + "--no-sorting", + "--nopresubmit", + "--variant=google3", + "--outdir icu", + "--verbose", + ] + select({ + "@v8//bazel/config:v8_target_arm64": [ + "--arch=arm64", + ], + "@v8//bazel/config:v8_target_x64": [ + "--arch=x64", + ], + "//conditions:default": [], + }) + [ + "intl", + ], + data = [ + "test", + ":icu/d8", + ":icu/v8_build_config", + "//testing/pybase", + ] + glob(["test/**"]) + glob(["tools/**/*.js"]) + glob(["tools/**/*.mjs"]), + main = "tools/run-tests.py", + tags = [ + # Disable sanitizers, as they don't work in general in V8. + "nosan", + ], +) diff --git a/third_party/v8/engine_repository.bzl b/third_party/v8/engine_repository.bzl new file mode 100644 index 0000000000..dd6b966623 --- /dev/null +++ b/third_party/v8/engine_repository.bzl @@ -0,0 +1,93 @@ +"""V8 source import with Codex-owned Bazel entry points. + +The root package is placed inside the fetched source tree so relative source +labels and globs have their normal Bazel semantics. Reuse upstream's platform +and CPU configuration in place, with Codex's narrow patch to bazel/defs.bzl. +V8's MODULE and toolchain BUILD files are never part of Codex's dependency or +toolchain graph. +""" + +# Upstream keeps its source groups in BUILD.bazel, which cannot be loaded as +# a Starlark library. Reuse filegroups, so labels/globs retain their semantics +# inside @v8. Compiled targets (including valid V8 v8_library/v8_binary calls) +# belong in engine.BUILD.bazel, where we wire Codex's dependencies and runtime. +_INVENTORY_SLOT = "# @CODEX_V8_UPSTREAM_FILEGROUPS@" +_FILE_GROUPS = "# File group rules" +_GENERATED_FILES = "# Generated files" + +def _upstream_filegroups(upstream): + before_and_groups = upstream.split(_FILE_GROUPS) + if len(before_and_groups) != 2: + fail("V8 source import: expected one File group rules section; review the new pin's BUILD.bazel") + groups_and_after = before_and_groups[1].split(_GENERATED_FILES) + if len(groups_and_after) != 2: + fail("V8 source import: expected one Generated files boundary; review the new pin's BUILD.bazel") + + groups = [] + statement = [] + for line in groups_and_after[0].split("\n"): + if statement: + statement.append(line) + if line == ")": + source = "\n".join(statement) + if statement[0] == "filegroup(": + groups.append(source) + elif 'name = "lib_dragonbox",' not in source and 'name = "lib_fp16",' not in source: + fail("V8 filegroup import: unexpected library; review and wire it in third_party/v8/engine.BUILD.bazel: " + source) + statement = [] + elif line in ["filegroup(", "v8_library("]: + # The pinned section happens to contain two libraries. Both are + # already provided by our dependency overlays; skip only those names. + statement = [line] + elif line.strip() and not line.startswith("#"): + fail("V8 filegroup import: only filegroups can be reused here; review compiled targets (including v8_binary) in third_party/v8/engine.BUILD.bazel. Unexpected statement: " + line) + + # Group count and library order can change without changing the owned graph. + # Fail only when the source section is empty, malformed, or unsafe to reuse. + if statement: + fail("V8 filegroup import: unterminated statement; review the pinned BUILD.bazel: " + "\n".join(statement)) + if not groups: + fail("V8 filegroup import: no filegroups found; review the pinned BUILD.bazel") + return "\n\n".join(groups) + +def _engine_repository_impl(ctx): + ctx.download_and_extract( + url = ctx.attr.urls, + integrity = ctx.attr.integrity, + stripPrefix = ctx.attr.strip_prefix, + ) + inventory = _upstream_filegroups(ctx.read("BUILD.bazel")) + template = ctx.read(ctx.attr._engine_build) + if template.count(_INVENTORY_SLOT) != 1: + fail("Codex V8 BUILD template must contain exactly one upstream filegroup slot") + + for patch in ctx.attr.patches: + ctx.patch(patch, strip = ctx.attr.patch_strip) + + # Preserve V8's source layout and the two third-party package boundaries + # (disarm and fadec); neither is in the Codex V8 closure. Keep upstream's + # platform/CPU package and prevent upstream toolchain discovery. + for path in [ + "MODULE.bazel", + "BUILD.bazel", + "bazel/toolchain/BUILD.bazel", + "bazel/patches/BUILD.bazel", + ]: + ctx.delete(path) + ctx.file("BUILD.bazel", template.replace(_INVENTORY_SLOT, inventory)) + +engine_repository = repository_rule( + implementation = _engine_repository_impl, + attrs = { + "urls": attr.string_list(mandatory = True), + "integrity": attr.string(mandatory = True), + "strip_prefix": attr.string(mandatory = True), + "patches": attr.label_list(allow_files = True), + "patch_strip": attr.int(default = 3), + "_engine_build": attr.label( + default = Label("//third_party/v8:engine.BUILD.bazel"), + allow_single_file = True, + ), + }, + doc = "Fetch the pinned V8 source tree and install Codex's engine graph.", +) diff --git a/third_party/v8/engine_rules.bzl b/third_party/v8/engine_rules.bzl new file mode 100644 index 0000000000..87261f33aa --- /dev/null +++ b/third_party/v8/engine_rules.bzl @@ -0,0 +1,13 @@ +"""Codex's fixed selection for branches of the imported V8 source inventory.""" + +load("@v8//:bazel/defs.bzl", "FlagInfo") + +def _options_impl(ctx): + return FlagInfo(value = ctx.build_setting_value) + +# Source-only features keep upstream select names without adding CLI options. +# ABI/runtime settings are still V8 release inputs until artifact profiles take over. +v8_fixed_source_features = rule( + implementation = _options_impl, + build_setting = config.bool(flag = False), +) diff --git a/third_party/v8/v8_defs.patch b/third_party/v8/v8_defs.patch new file mode 100644 index 0000000000..fea274539d --- /dev/null +++ b/third_party/v8/v8_defs.patch @@ -0,0 +1,176 @@ +# What: adapt the pinned V8 rule helpers to Codex's engine configuration. +# Scope: bazel/defs.bzl only; the engine graph and dependency choices live in +# third_party/v8/engine.BUILD.bazel. The platform/CPU config is unmodified V8. +# Preserve the existing release flags, Chromium libc++ headers/runtime, Clang +# Windows driver flags, and Windows target-ABI snapshot tool. The optional +# Linux backtrace link flag is omitted because that feature is fixed off. +# On a V8 pin change, review these hunks and build the native canary matrix. + +--- a/orig/v8-15.2.124.1/bazel/defs.bzl ++++ b/mod/v8-15.2.124.1/bazel/defs.bzl +@@ -42,12 +42,30 @@ + ) + + def v8_flag(name, default = False): +- _create_option_flag(name = name, build_setting_default = default, scope = "universal") +- native.config_setting(name = "is_" + name, flag_values = {name: "True"}) +- native.config_setting(name = "is_not_" + name, flag_values = {name: "False"}) +- +-def v8_string(name, default = ""): +- _create_option_string(name = name, build_setting_default = default, scope = "universal") ++ _create_option_flag( ++ name = name, ++ build_setting_default = default, ++ scope = "universal", ++ visibility = ["//visibility:public"], ++ ) ++ native.config_setting( ++ name = "is_" + name, ++ flag_values = {name: "True"}, ++ visibility = ["//visibility:public"], ++ ) ++ native.config_setting( ++ name = "is_not_" + name, ++ flag_values = {name: "False"}, ++ visibility = ["//visibility:public"], ++ ) ++ ++def v8_string(name, default = "", visibility = None): ++ _create_option_string( ++ name = name, ++ build_setting_default = default, ++ scope = "universal", ++ visibility = visibility, ++ ) + + def v8_int(name, default = 0): + _create_option_int(name = name, build_setting_default = default, scope = "universal") +@@ -106,7 +124,13 @@ + + def _default_args(): + return struct( +- deps = [":define_flags", "@libcxx//:libc++"], ++ deps = [":define_flags"] + select({ ++ "@v8//:is_v8_use_rusty_v8_custom_libcxx": [ ++ "@@//third_party/v8:rusty_v8_custom_libcxx_headers", ++ "@@//third_party/v8:rusty_v8_custom_libcxx_runtime", ++ ], ++ "//conditions:default": [], ++ }), + defines = select({ + "@v8//bazel/config:is_windows": [ + "UNICODE", +@@ -136,12 +160,15 @@ + ], + "//conditions:default": [], + }) + select({ +- "@v8//bazel/config:is_clang": [ +- "-Wno-invalid-offsetof", +- "-Wno-deprecated-this-capture", +- "-Wno-deprecated-declarations", +- "-std=c++20", +- ], ++ "@v8//:is_v8_use_rusty_v8_custom_libcxx": [ ++ "-nostdinc++", ++ "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS", ++ "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE", ++ "-D_LIBCPP_INSTRUMENTED_WITH_ASAN=0", ++ "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS", ++ ], ++ "//conditions:default": [], ++ }) + select({ + "@v8//bazel/config:is_gcc": [ + "-Wno-extra", + "-Wno-array-bounds", +@@ -161,9 +188,17 @@ + "-std=gnu++2a", + ], + "@v8//bazel/config:is_windows": [ +- "/std:c++20", +- ], +- "//conditions:default": [], ++ "-Wno-invalid-offsetof", ++ "-Wno-deprecated-this-capture", ++ "-Wno-deprecated-declarations", ++ "-std=c++20", ++ ], ++ "//conditions:default": [ ++ "-Wno-invalid-offsetof", ++ "-Wno-deprecated-this-capture", ++ "-Wno-deprecated-declarations", ++ "-std=c++20", ++ ], + }) + select({ + "@v8//bazel/config:is_gcc_fastbuild": [ + # Non-debug builds without optimizations fail because +@@ -187,15 +222,12 @@ + includes = ["include"], + linkopts = select({ + "@v8//bazel/config:is_windows": [ +- "Winmm.lib", +- "DbgHelp.lib", +- "Advapi32.lib", ++ "-lwinmm", ++ "-ldbghelp", ++ "-ladvapi32", + ], + "@v8//bazel/config:is_macos": ["-pthread"], +- "//conditions:default": ["-Wl,--no-as-needed -ldl -latomic -pthread"], +- }) + select({ +- ":should_add_rdynamic": ["-rdynamic"], +- "//conditions:default": [], ++ "//conditions:default": ["-Wl,--no-as-needed -ldl -pthread"], + }), + ) + +@@ -466,6 +498,12 @@ + 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 + outs = [ + ctx.actions.declare_file(prefix + "/snapshot" + suffix + ".cc"), + ctx.actions.declare_file(prefix + "/embedded" + suffix + ".S"), +@@ -483,7 +521,7 @@ + "--embedded_src", + outs[1].path, + ] + ctx.attr.args, +- executable = ctx.executable.tool, ++ executable = tool, + progress_message = "Running mksnapshot", + ) + return [DefaultInfo(files = depset(outs))] +@@ -498,6 +536,12 @@ + executable = True, + cfg = "exec", + ), ++ "target_tool": attr.label( ++ mandatory = True, ++ allow_files = True, ++ executable = True, ++ cfg = "target", ++ ), + "target_os": attr.string(mandatory = True), + "prefix": attr.string(mandatory = True), + "suffix": attr.string(mandatory = True), +@@ -511,6 +555,7 @@ + args = args, + prefix = "noicu", + tool = ":noicu/mksnapshot" + suffix, ++ target_tool = ":noicu/mksnapshot" + suffix, + suffix = suffix, + target_os = select({ + "@v8//bazel/config:is_macos": "mac", +@@ -523,6 +568,7 @@ + args = args, + prefix = "icu", + tool = ":icu/mksnapshot" + suffix, ++ target_tool = ":icu/mksnapshot" + suffix, + suffix = suffix, + target_os = select({ + "@v8//bazel/config:is_macos": "mac",