diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000000..8e2b597466 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,277 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## What this repo is + +`envoyproxy/toolshed` is a multi-language CI and development tooling monorepo for the Envoy proxy project. It contains Python packages (published to PyPI), Bazel build rules (published to the Bazel Central Registry), Rust binaries, TypeScript GitHub Actions, shell scripts, and jq modules. + +## Build systems + +The repo uses **two parallel build systems** covering different areas: + +- **Pants** — manages all Python packages under `py/` +- **Bazel** — manages build rules, C++ compile targets, and integration; all Bazel commands run from the `bazel/` subdirectory + +Pants explicitly ignores the `bazel/` directory; Bazel does not manage Python packages. + +## Common commands + +### Python (Pants) + +`pants` is already on PATH — do **not** run `./get-pants.sh`. + +```bash +# Run all tests +pants test :: + +# Run tests for a single package +pants test envoy.dependency.check:: + +# Filter tests by name +pants test --debug envoy.dependency.check:: -- -k checker_cves + +# Coverage report +pants test --open-coverage :: + +# Lint (flake8 + docformatter) +pants lint :: + +# Type-check (mypy) +pants check :: + +# Package (wheel) +pants package :: +``` + +### Bazel + +All Bazel commands must run from the `bazel/` directory. + +```bash +cd bazel + +bazel build //... +bazel test //... +bazel test --config=ci //... # CI-style, suppressed progress +bazel build --enable_bzlmod //... # bzlmod mode (default is WORKSPACE mode) +bazel build --config=gcc //... # GCC toolchain +``` + +The `.bazelrc` disables bzlmod by default (`--noenable_bzlmod`). The Bazel module is `envoy_toolshed` version `0.3.32-dev`. + +### Rust (from `rust/`) + +```bash +cd rust +cargo build --release -p glint +cargo build --release -p toolshed-echo +cargo tarpaulin --config tarpaulin.toml --features test --lib --bins # coverage +cargo test --package glint --test integration_test --verbose +``` + +### JavaScript (per-package from `js//`) + +```bash +cd js/ +npm ci --legacy-peer-deps +npm run lint +npm test +npm run build +``` + +### Global lint (shell, yaml, glint) + +```bash +envoy.code.check . -c glint shellcheck yamllint +``` + +### V8 wee8 static library + +```bash +# Local build (no RBE) — takes 30–120 min cold +cd bazel +bazel build -c opt --enable_bzlmod --noenable_workspace //v8:wee8_package_linux_x86_64 + +# Cross-compile for aarch64 from an x86_64 machine +bazel build -c opt --enable_bzlmod --noenable_workspace \ + --platforms=@toolchains_llvm//platforms:linux-aarch64 \ + //v8:wee8_package_linux_aarch64 + +# Quick Starlark syntax check +bazel query --enable_bzlmod --noenable_workspace //v8:wee8_package_linux_x86_64 +``` + +Output tarballs land in `bazel-bin/v8/v8-wee8-{version}-linux-{arch}.tar.xz`. + +CI (`package-v8` in `bazel.yml`) builds both arches on `ubuntu-24.04` (x86_64) with RBE. +The aarch64 build cross-compiles via `--platforms=@toolchains_llvm//platforms:linux-aarch64`. +A native arm64 runner was tried but abandoned: V8's `code_generator` exec tool (a Python venv) +fails on aarch64 exec platforms due to a venv bootstrap issue. + +## Architecture + +### Python packages (`py/`) + +Two namespaces: +- **`aio.*`** — generic async libraries (not Envoy-specific): core utilities, run framework, checker framework +- **`envoy.*`** — Envoy-specific runners and checkers: dependency CVE checking, code linting, release management, GitHub automation, distribution verification + +All packages are async-first (`asyncio`). Two runnable archetypes: +- **Runners** — run a series of steps, exit on failure +- **Checkers** — run a series of checks, accumulate errors/warnings/successes + +Packages are consumed by Envoy via `rules_python` from PyPI. To test changes locally in an Envoy environment without publishing, add an editable path reference to Envoy's `tools/dev/requirements.txt`: +``` +-e file:///path/to/toolshed/py/envoy.dependency.check#egg=envoy.dependency.check&cachebust=000 +``` +Increment `cachebust` on each change to bust Bazel's cache. + +### Bazel rules (`bazel/`) + +Reusable Starlark rules for: +- C++ compilation with LLVM 18.x toolchains (`bazel/compile/` — MSAN/TSAN sanitizer libraries, libcxx cross-compile bundles) +- Debian sysroot generation for cross-compilation (`bazel/sysroot/`) +- Envoy website Python dependency targets (`bazel/website/`) +- V8 wee8 prebuilt library distribution (`bazel/v8/`) + +A local BCR is maintained in `bazel-registry/` for publishing `envoy_toolshed` to the Bazel Central Registry. + +### V8 wee8 prebuilt library (`bazel/v8/`) — **IN PROGRESS** 🚧 + +**Purpose:** Provide prebuilt V8 wee8 static libraries (`libwee8.a`) to eliminate 30-120 minute V8 build times for Envoy and other consumers. + +**Status (as of 2026-08-18):** Infrastructure 95% complete, blocked on transitive dependencies issue. + +**Completed Steps:** +1. ✅ **Artifact build pipeline** — PR #5019 merged (Aug 13, 2026) +2. ✅ **bins-v0.2.8 release** — Published (Aug 14, 2026) with 3 wee8 tarballs: + - `v8-wee8-14.6.202.10-linux-x86_64.tar.xz` (libcxx, 15.2 MB) + - `v8-wee8-14.6.202.10-linux-x86_64-libstdcxx.tar.xz` (libstdc++, 15.2 MB) + - `v8-wee8-14.6.202.10-linux-aarch64.tar.xz` (libcxx, 14.4 MB) +3. ✅ **Release automation** — wee8 SHA propagation in bazel prepare workflow (PRs #5043, #5047) +4. ✅ **Bazel module v0.4.6** — Published (Aug 16, 2026) with V8 infrastructure +5. ✅ **Post-merge improvements** — PRs #5050, #5052, #5053, #5066 (hermetic builds, multi-stdlib, platform selection, tests) +6. ✅ **Envoy integration branch** — `manage-wee8-library` created with setup_wee8_prebuilt() configured + +**Current V8 version:** `14.6.202.10` (in `bazel/versions.bzl`) + +**Current Blocker:** + +`@proxy_wasm_cpp_host//:v8_lib` compiles `src/v8/v8.cc` which includes abseil headers (e.g., `absl/strings/str_format.h`). The original `@v8//:wee8` target provided these as transitive dependencies, but our prebuilt wee8 BUILD template doesn't include any deps. + +**Error:** +``` +external/proxy_wasm_cpp_host/src/v8/v8.cc:33:10: fatal error: 'absl/strings/str_format.h' file not found +``` + +**Two Paths Forward:** + +**Path A: Fix toolshed BUILD template** (cleaner, recommended) +1. Update `_WEE8_BUILD` in `bazel/v8/wee8_prebuilt.bzl` to add deps: + ```python + cc_library( + name = "wee8", + srcs = ["lib/libwee8.a"], + hdrs = [":headers"], + includes = [".", "include"], + linkstatic = True, + deps = [ + "@abseil-cpp//absl/strings:str_format", + "@abseil-cpp//absl/container:flat_hash_map", + "@abseil-cpp//absl/container:flat_hash_set", + "@abseil-cpp//absl/container:btree", + # Add other V8 transitive deps as needed + ], + ) + ``` +2. Cut toolshed v0.4.7 release +3. Update Envoy's `repository_locations.bzl` to use v0.4.7 +4. Complete Envoy integration + +**Path B: Patch proxy_wasm v8_lib** (faster, but messier) +1. Extend `bazel/proxy_wasm_cpp_host.patch` to add abseil deps directly to the `v8_lib` target +2. Works with current toolshed v0.4.6 +3. Less clean - puts dependency knowledge in wrong place + +**Current Envoy branch state (`manage-wee8-library`):** +- ✅ `setup_wee8_prebuilt()` configured in `bazel/repositories_extra.bzl` +- ✅ `bazel/proxy_wasm_cpp_host.patch` updated to alias wee8_no_pointer_compression +- ✅ V8 BUILD patched via `patch_cmds` to use prebuilt (avoids patch file format issues) +- ❌ Blocked on missing abseil deps compilation error + +**What's available:** + +**For WORKSPACE consumers (Envoy):** +```python +# In bazel/repositories_extra.bzl +load("@envoy_toolshed//v8:wee8_prebuilt.bzl", "setup_wee8_prebuilt") + +def envoy_dependencies_extra(...): + setup_wee8_prebuilt() # Creates @wee8_prebuilt_* repos +``` + +**For bzlmod consumers:** +```python +# In MODULE.bazel +bazel_dep(name = "envoy_toolshed", version = "0.4.6.envoy") # When available in BCR + +# Use the platform-agnostic alias +deps = ["@envoy_toolshed//v8:wee8"] +``` + +**Platform selection** (automatic via `@envoy_toolshed//v8:wee8` alias): +- Linux x86_64 + Clang → `@wee8_prebuilt_x86_64//:wee8` (libcxx) +- Linux x86_64 + GCC → `@wee8_prebuilt_x86_64_libstdcxx//:wee8` (libstdc++) +- Linux aarch64 + Clang → `@wee8_prebuilt_aarch64//:wee8` (libcxx) +- Other platforms → `@v8//:wee8` (fallback: build from source) + +**Key files:** +- `bazel/v8/wee8_package.bzl` — Build rule for creating prebuilt tarballs +- `bazel/v8/wee8_prebuilt.bzl` — Repository rules for consuming prebuilts (`setup_wee8_prebuilt()`) +- `bazel/v8/extensions.bzl` — bzlmod module extension (`wee8_prebuilt_extension`) +- `bazel/v8/BUILD` — Platform-agnostic `//v8:wee8` alias +- `bazel/v8/package/BUILD` — Packaging targets for CI +- `bazel/versions.bzl` — `V8_VERSION = "14.6.202.10"` and `wee8_sha256` hashes + +**Next Steps:** +1. **Immediate:** Add abseil deps to `_WEE8_BUILD` template in toolshed +2. Cut toolshed v0.4.7 release +3. Update Envoy to v0.4.7 and complete integration testing +4. Open Envoy PR for wee8 prebuilt integration +5. Open bazel-registry PR for envoy_toolshed@0.4.6.envoy (or 0.4.7) + +**Build time savings (when complete):** 30-120 minutes → seconds + +**When bumping V8 version:** +1. Update `V8_VERSION` in `bazel/versions.bzl` +2. Update `bazel_dep(name = "v8", version = "...")` in `bazel/MODULE.bazel` +3. Cut a new bins release (wee8 SHAs auto-update in bazel prepare workflow) +4. Cut a new bazel module release + +**Local testing with unpublished tarball:** +```bash +export V8_PREBUILT_PATH=/path/to/dir/containing/tarball +``` + +### Rust (`rust/`) + +Cargo workspace with members: `core`, `echo`, `glint`, `runner`, `test`. +- `glint` — the primary linting binary used in global CI lint checks +- `toolshed-echo` — an echo server binary + +### JavaScript/TypeScript (`js/`) + +Nine composite GitHub Actions built with TypeScript + `ncc`: +`appauth`, `dispatch`, `github/checks`, `github/mutex`, `github/script/run`, `hashfiles`, `jq`, `retest`, `torun`. + +## Python coding standards + +- Python 3.12 required (`>=3.12,<3.13`) +- All code must be type-hinted; mypy must pass +- Async-first: use `asyncio` patterns throughout +- Use `breakpoint()` (not `print`) for debugging; `pants test --debug` drops into pdb + +## CI + +GitHub Actions workflows are path-filtered so each language area only triggers on its relevant files. Key workflows: `py.yml` (Python), `bazel.yml` (Bazel), `rust.yml` (Rust), `js.yml` (JavaScript), `lint.yml` (global lint on every PR). diff --git a/bazel/MODULE.bazel b/bazel/MODULE.bazel index 061c77ded4..315432dfc1 100644 --- a/bazel/MODULE.bazel +++ b/bazel/MODULE.bazel @@ -9,6 +9,22 @@ bazel_dep(name = "bazel_skylib", version = "1.8.2") bazel_dep(name = "platforms", version = "1.0.0") bazel_dep(name = "rules_cc", version = "0.2.17") bazel_dep(name = "v8", version = "14.6.202.10.envoy") + +# Override V8 to apply Envoy-specific patches for ABI compatibility +archive_override( + module_name = "v8", + urls = ["https://github.com/v8/v8/archive/refs/tags/14.6.202.10.tar.gz"], + strip_prefix = "v8-14.6.202.10", + integrity = "sha256-CcPZ95amcfuWMMcZADLwAXHOme/9fIDHquuhSKe8vBs=", + patches = [ + "//v8/patches:v8_no_python_load.patch", + "//v8/patches:v8_novtune.patch", + "//v8/patches:v8_ppc64le.patch", + "//v8/patches:v8_python.patch", + "//v8/patches:v8_module.patch", + ], + patch_strip = 1, +) bazel_dep(name = "rules_foreign_cc", version = "0.15.1") bazel_dep(name = "rules_pkg", version = "1.1.0") bazel_dep(name = "rules_python", version = "1.7.0") @@ -61,7 +77,14 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip") for python_version in PYTHON_VERSIONS ] -use_repo(pip, "pip3", "website_pip3") +# V8 Python dependencies for code generation +pip.parse( + hub_name = "base_pip3", + python_version = PYTHON_VERSION_DEFAULT, + requirements_lock = "//v8:requirements.txt", +) + +use_repo(pip, "pip3", "website_pip3", "base_pip3") # Load llvm_source for compile targets http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") diff --git a/bazel/MODULE.bazel.lock b/bazel/MODULE.bazel.lock index 60af7d73b2..8bb613a8a5 100644 --- a/bazel/MODULE.bazel.lock +++ b/bazel/MODULE.bazel.lock @@ -76,10 +76,6 @@ "https://bcr.bazel.build/modules/bazel_worker_java/0.0.8/source.json": "9395c4679444bc47bf7e51a710366a4480aa371c6f6bed01868e2fabcf11acec", "https://bcr.bazel.build/modules/buildozer/7.1.2/MODULE.bazel": "2e8dd40ede9c454042645fd8d8d0cd1527966aa5c919de86661e62953cd73d84", "https://bcr.bazel.build/modules/buildozer/7.1.2/source.json": "c9028a501d2db85793a6996205c8de120944f50a0d570438fcae0457a5f9d1f8", - "https://bcr.bazel.build/modules/dragonbox/0.0.0-241028-6c7c925.envoy/MODULE.bazel": "not found", - "https://bcr.bazel.build/modules/fast_float/8.0.2/MODULE.bazel": "43504664efdfa4c6cf1349626c87135c9b87926325c720458f396eee25568eda", - "https://bcr.bazel.build/modules/fast_float/8.0.2/source.json": "8b83304ea4c3c1e43cc74e644918394a799b0f2cebe3b9ffbbe37ac75dcfb171", - "https://bcr.bazel.build/modules/fp16/0.0.0-260704-3d2de18.envoy/MODULE.bazel": "not found", "https://bcr.bazel.build/modules/gawk/5.3.2.bcr.1/MODULE.bazel": "cdf8cbe5ee750db04b78878c9633cc76e80dcf4416cbe982ac3a9222f80713c8", "https://bcr.bazel.build/modules/gawk/5.3.2.bcr.1/source.json": "fa7b512dfcb5eafd90ce3959cf42a2a6fe96144ebbb4b3b3928054895f2afac2", "https://bcr.bazel.build/modules/gazelle/0.32.0/MODULE.bazel": "b499f58a5d0d3537f3cf5b76d8ada18242f64ec474d8391247438bf04f58c7b8", @@ -99,7 +95,6 @@ "https://bcr.bazel.build/modules/helly25_bzl/0.4.3/source.json": "e8c54d81e72633fb6f1d23c7e2d44e0b39b1caef2a256141136a2f63e6204b78", "https://bcr.bazel.build/modules/highway/1.2.0/MODULE.bazel": "605dc84b4931a409f16d920409dc38718798754c1afa4c80115a32118d67acb3", "https://bcr.bazel.build/modules/highway/1.2.0/source.json": "01a2c7e56a1850a28c0026c0adc32e52db44c6a1df142b3f88b2a3747a5bff7d", - "https://bcr.bazel.build/modules/icu/78.2.envoy/MODULE.bazel": "not found", "https://bcr.bazel.build/modules/jq.bzl/0.1.0/MODULE.bazel": "2ce69b1af49952cd4121a9c3055faa679e748ce774c7f1fda9657f936cae902f", "https://bcr.bazel.build/modules/jq.bzl/0.1.0/source.json": "746bf13cac0860f091df5e4911d0c593971cd8796b5ad4e809b2f8e133eee3d5", "https://bcr.bazel.build/modules/jsoncpp/1.9.5/MODULE.bazel": "31271aedc59e815656f5736f282bb7509a97c7ecb43e927ac1a37966e0578075", @@ -260,7 +255,6 @@ "https://bcr.bazel.build/modules/rules_shell/0.6.1/source.json": "20ec05cd5e592055e214b2da8ccb283c7f2a421ea0dc2acbf1aa792e11c03d0c", "https://bcr.bazel.build/modules/rules_swift/1.16.0/MODULE.bazel": "4a09f199545a60d09895e8281362b1ff3bb08bbde69c6fc87aff5b92fcc916ca", "https://bcr.bazel.build/modules/rules_swift/2.1.1/MODULE.bazel": "494900a80f944fc7aa61500c2073d9729dff0b764f0e89b824eb746959bc1046", - "https://bcr.bazel.build/modules/simdutf/8.1.0.envoy/MODULE.bazel": "not found", "https://bcr.bazel.build/modules/stardoc/0.5.1/MODULE.bazel": "1a05d92974d0c122f5ccf09291442580317cdd859f07a8655f1db9a60374f9f8", "https://bcr.bazel.build/modules/stardoc/0.5.3/MODULE.bazel": "c7f6948dae6999bf0db32c1858ae345f112cacf98f174c7a8bb707e41b974f1c", "https://bcr.bazel.build/modules/stardoc/0.5.6/MODULE.bazel": "c43dabc564990eeab55e25ed61c07a1aadafe9ece96a4efabb3f8bf9063b71ef", @@ -277,7 +271,6 @@ "https://bcr.bazel.build/modules/toolchains_llvm/1.8.0.envoy/MODULE.bazel": "not found", "https://bcr.bazel.build/modules/upb/0.0.0-20220923-a547704/MODULE.bazel": "7298990c00040a0e2f121f6c32544bab27d4452f80d9ce51349b1a28f3005c43", "https://bcr.bazel.build/modules/upb/0.0.0-20230516-61a97ef/MODULE.bazel": "c0df5e35ad55e264160417fd0875932ee3c9dda63d9fccace35ac62f45e1b6f9", - "https://bcr.bazel.build/modules/v8/14.6.202.10.envoy/MODULE.bazel": "not found", "https://bcr.bazel.build/modules/yq.bzl/0.1.1/MODULE.bazel": "9039681f9bcb8958ee2c87ffc74bdafba9f4369096a2b5634b88abc0eaefa072", "https://bcr.bazel.build/modules/yq.bzl/0.1.1/source.json": "2d2bad780a9f2b9195a4a370314d2c17ae95eaa745cefc2e12fbc49759b15aa3", "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0", @@ -286,27 +279,17 @@ "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/source.json": "22bc55c47af97246cfc093d0acf683a7869377de362b5d1c552c2c2e16b7a806", "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198", "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/bazel_registry.json": "51bd3a0b193753e419c5d3db38e92fbcb9f7f97fd992ef2e24a0addd7274b37a", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/dragonbox/0.0.0-241028-6c7c925.envoy/MODULE.bazel": "56dd26c839325bc2c40cc1879c00cab3397cd83fe3cf6ab8ccaf7fd6ad1b890d", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/dragonbox/0.0.0-241028-6c7c925.envoy/source.json": "642addb5bea17b6570a138ccfb4f50f34c810c9e3416748a09e1ac723b01021f", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/fp16/0.0.0-260704-3d2de18.envoy/MODULE.bazel": "27e5020ea158fdc725eafed3443b6fa9a1555d52505dafcdc3e6ea74d9e112c1", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/fp16/0.0.0-260704-3d2de18.envoy/source.json": "ccc308b4d5afbba59ce93809243da68a5402414bb7f707d2b691df68ab896250", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/icu/78.2.envoy/MODULE.bazel": "bed492d3dffffca822867b4b034191069ea917cd5c1b98ad3c5e609227d0f387", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/icu/78.2.envoy/source.json": "d3c0d7c00cdb28b6294356ec253a0ee994e2d65f912b92075ea5ddd049df283b", "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/protobuf/35.1.bcr.envoy/MODULE.bazel": "a42d2e15b0ffb57474df57e2cc274aa9ad2e52e6e9e7bc19e9c529b0d4093d5f", "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/protobuf/35.1.bcr.envoy/source.json": "5ee2c32f315c4be232f955a963f37e631f70a4d32cd3dd536b46c48920a98944", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/simdutf/8.1.0.envoy/MODULE.bazel": "d7288f3bd5168bc92aff3591e5f7a3a58277bddcc7fc70fa125f39ac9445f4b7", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/simdutf/8.1.0.envoy/source.json": "b95d6bfb222cf92c83d3352ec0c550394d801e2b2700b160b692cbe4b40b8342", "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/toolchains_llvm/1.8.0.envoy/MODULE.bazel": "93909b69ee77410306b1b591653f7f89ecda4c7d88d42c468dd1e5e7afc6fe65", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/toolchains_llvm/1.8.0.envoy/source.json": "de9de2b3f608568feb51501cfc1418bdf024a274c670f92ab792a6a070f03ed3", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/v8/14.6.202.10.envoy/MODULE.bazel": "57fa395049458e9768b26e4789236ee620bd177414bf979cf583887f06c71749", - "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/v8/14.6.202.10.envoy/source.json": "068a8822f21c1c488982f6b3fd5c52858e8db025ebc3458170d3ed940b425a57" + "https://raw.githubusercontent.com/envoyproxy/bazel-registry/5aa09470cb04646d9d416b142eab5c9569cc074e/modules/toolchains_llvm/1.8.0.envoy/source.json": "de9de2b3f608568feb51501cfc1418bdf024a274c670f92ab792a6a070f03ed3" }, "selectedYankedVersions": {}, "moduleExtensions": { "//compile:extensions.bzl%libcxx_extension": { "general": { - "bzlTransitiveDigest": "BTuyHAmPV6RLjmwYvHgt5sqEor5vYxcSNJW+rLVnLU4=", - "usagesDigest": "RN4CLPdbGThKbAP902x5jh5QAjMcWrWkUrFVQZo2yX8=", + "bzlTransitiveDigest": "xq4mUY6BVQnnWqOzX/XORJO7GVFn1zwGLk82OjEZLF4=", + "usagesDigest": "4ZFkgLasgQCq+IJRwL+VcSDPET1TRc2r/Um+adJlR3M=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -400,8 +383,8 @@ }, "//compile:extensions.bzl%llvm_minimal_extension": { "general": { - "bzlTransitiveDigest": "BTuyHAmPV6RLjmwYvHgt5sqEor5vYxcSNJW+rLVnLU4=", - "usagesDigest": "zTRetCqgCTR/JYUTsNeIov/5K+KNmJAxmPtAfB+35B4=", + "bzlTransitiveDigest": "xq4mUY6BVQnnWqOzX/XORJO7GVFn1zwGLk82OjEZLF4=", + "usagesDigest": "Q+CKSP0adR7YFwQRyGmwMLzUFi/fI4mpjnKPqgG4qPE=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -409,24 +392,24 @@ "llvm_minimal_linux_x64": { "repoRuleId": "@@//compile:llvm_minimal.bzl%llvm_minimal_repo", "attributes": { - "url": "https://github.com/envoyproxy/toolshed/releases/download/bins-v0.2.7/llvm-minimal-22.1.8-Linux-X64.tar.zst", - "sha256": "3055f223cb27740e319412303c8298787b78062839d8809b88b13c4d6bcd82ca", + "url": "https://github.com/envoyproxy/toolshed/releases/download/bins-v0.2.8/llvm-minimal-22.1.8-Linux-X64.tar.zst", + "sha256": "6cb4cca6df33be00c80fa1639062c973d1cafe4e7ad98a9b4bdf21bf9dec5806", "strip_prefix": "llvm-minimal-22.1.8-Linux-X64" } }, "llvm_minimal_linux_arm64": { "repoRuleId": "@@//compile:llvm_minimal.bzl%llvm_minimal_repo", "attributes": { - "url": "https://github.com/envoyproxy/toolshed/releases/download/bins-v0.2.7/llvm-minimal-22.1.8-Linux-ARM64.tar.zst", - "sha256": "b00ea67259e613907da30cb5d8290192b54ab656f4759ace6794f3e10de1d0ed", + "url": "https://github.com/envoyproxy/toolshed/releases/download/bins-v0.2.8/llvm-minimal-22.1.8-Linux-ARM64.tar.zst", + "sha256": "9a6cc0a84d524342e578db739b04e8a3875adb40b38887e4e074661e925f8a9c", "strip_prefix": "llvm-minimal-22.1.8-Linux-ARM64" } }, "llvm_minimal_macos_arm64": { "repoRuleId": "@@//compile:llvm_minimal.bzl%llvm_minimal_repo", "attributes": { - "url": "https://github.com/envoyproxy/toolshed/releases/download/bins-v0.2.7/llvm-minimal-22.1.8-macOS-ARM64.tar.zst", - "sha256": "04a2ac21e89a42dba532509ee67c246b71ec8a15c6cef0f2d63e349fb120934c", + "url": "https://github.com/envoyproxy/toolshed/releases/download/bins-v0.2.8/llvm-minimal-22.1.8-macOS-ARM64.tar.zst", + "sha256": "928e51aa7c97fbb8c5c50075118f4b36e36363b1a2c3af2dfef9aea1ef526ade", "strip_prefix": "llvm-minimal-22.1.8-macOS-ARM64" } } @@ -512,8 +495,8 @@ }, "//sysroot:extensions.bzl%sysroot_extension": { "general": { - "bzlTransitiveDigest": "8mBbKuC9X+dVsJfKM+AgJFJoBBNzOGVJZxdCfSxLqq0=", - "usagesDigest": "wKAMwdm/oEYUzhed5dKuDJChGeMSDIyTPv9j0p3ta18=", + "bzlTransitiveDigest": "PF3oNYod5GkYA2DCs46F5a8BkZbFeJLt6wv1gZYWk30=", + "usagesDigest": "QuvSVj2nF2HTzMnymPuZHLvRfdfCftaYggoWoY1FCyo=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -521,8 +504,8 @@ "sysroot_linux_amd64": { "repoRuleId": "@@//sysroot:sysroot.bzl%sysroot", "attributes": { - "version": "0.2.7", - "sha256": "fe05fe5200c2854286f5d7c5680fa05d203bf9de247b6df8d4994945743c94ff", + "version": "0.2.8", + "sha256": "63b6ff808f87b03fefb695941906e419b8f88f8e27150b3e2007dbc0012b78a8", "arch": "amd64", "glibc_version": "2.31", "stdcc_version": "13" @@ -531,8 +514,8 @@ "sysroot_linux_arm64": { "repoRuleId": "@@//sysroot:sysroot.bzl%sysroot", "attributes": { - "version": "0.2.7", - "sha256": "7a2781b72d55a178f57bb637b4c1e11f2703f2c8e6af221fc48c427f044aa839", + "version": "0.2.8", + "sha256": "8f3847a6a5147dd5c13c92914f009c38792dbe82196a77187bc284b937c0cc6c", "arch": "arm64", "glibc_version": "2.31", "stdcc_version": "13" @@ -544,8 +527,8 @@ }, "//v8:extensions.bzl%wee8_prebuilt_extension": { "general": { - "bzlTransitiveDigest": "3XVk7hxXkbm3MI5PCrruGa7H/eKm1U3zjVGWrvQLw4Q=", - "usagesDigest": "G3ksytQP2i8GCDK2aPOHdeCILz9E6+K7AK5dsV7Mi3g=", + "bzlTransitiveDigest": "K6tAjGXmbq82fj/0ojlHuEaWcbPmEdyUvmyMBnp1J54=", + "usagesDigest": "qtgEPyqlaewbvM4bt1SZIGrtGJ58GcpfmXLpk1VMdL8=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, @@ -553,8 +536,8 @@ "wee8_prebuilt_x86_64": { "repoRuleId": "@@//v8:wee8_prebuilt.bzl%wee8_prebuilt", "attributes": { - "version": "0.2.7", - "sha256": "4bb306264d85dc629e7bb03ede97064de6c2e6452044ef6e528f7e319f51d482", + "version": "0.2.8", + "sha256": "96e3146e68dc2d1ae299ba5845c2a9edb2cb3dfe64fbedbcc77b339a95061d80", "arch": "x86_64", "stdlib": "libcxx" } @@ -562,8 +545,8 @@ "wee8_prebuilt_x86_64_libstdcxx": { "repoRuleId": "@@//v8:wee8_prebuilt.bzl%wee8_prebuilt", "attributes": { - "version": "0.2.7", - "sha256": "9a92188a27c2b8f8ac0ff2548c259bd1ce375431af6ee7b67626d22745bd0f8a", + "version": "0.2.8", + "sha256": "874a66ebf631f13189b30179fceb232fabde59f8ca6a47b6a1a82d04db9afeee", "arch": "x86_64", "stdlib": "libstdcxx" } @@ -571,8 +554,8 @@ "wee8_prebuilt_aarch64": { "repoRuleId": "@@//v8:wee8_prebuilt.bzl%wee8_prebuilt", "attributes": { - "version": "0.2.7", - "sha256": "9c4ce19dd446f62791979e4cd03c2da4df43d035479820db5a4a35aee605c3d8", + "version": "0.2.8", + "sha256": "cacd8cf4b17bba81dc2a506b21c7314fcedb0fc6507c581dbc6c4827a9994cf5", "arch": "aarch64", "stdlib": "libcxx" } diff --git a/bazel/bazel/BUILD b/bazel/bazel/BUILD new file mode 100644 index 0000000000..f16672dd22 --- /dev/null +++ b/bazel/bazel/BUILD @@ -0,0 +1,6 @@ +# Dummy config flags for V8's Envoy patches +config_setting( + name = "no_debug_info", + define_values = {"debug_symbols": "no"}, + visibility = ["//visibility:public"], +) diff --git a/bazel/v8/patches/BUILD b/bazel/v8/patches/BUILD new file mode 100644 index 0000000000..9980678c43 --- /dev/null +++ b/bazel/v8/patches/BUILD @@ -0,0 +1,16 @@ +"""Envoy-specific V8 patches for ABI compatibility. + +These patches are copied from envoyproxy/envoy and applied during V8 builds +to ensure the prebuilt wee8 library matches Envoy's expectations. +""" + +licenses(["notice"]) # Apache 2 + +exports_files([ + "v8.patch", + "v8_no_python_load.patch", + "v8_novtune.patch", + "v8_ppc64le.patch", + "v8_python.patch", + "v8_module.patch", +]) diff --git a/bazel/v8/patches/v8.patch b/bazel/v8/patches/v8.patch new file mode 100644 index 0000000000..2feb5e6e41 --- /dev/null +++ b/bazel/v8/patches/v8.patch @@ -0,0 +1,190 @@ +diff --git a/BUILD.bazel b/BUILD.bazel +index 85f31b7a..eeba8efa 100644 +--- a/BUILD.bazel ++++ b/BUILD.bazel +@@ -6,7 +6,7 @@ load("@bazel_skylib//lib:selects.bzl", "selects") + load("@rules_cc//cc:cc_library.bzl", "cc_library") + load("@rules_cc//cc:cc_binary.bzl", "cc_binary") + load("@rules_python//python:defs.bzl", "py_binary", "py_test") +-load("@v8_python_deps//:requirements.bzl", "requirement") ++load("@base_pip3//:requirements.bzl", "requirement") + load( + "@v8//:bazel/defs.bzl", + "v8_binary", +@@ -303,7 +303,7 @@ v8_int( + # 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", + ) + + # Default setting for v8_enable_pointer_compression. +@@ -4607,10 +4607,10 @@ v8_library( + ":noicu/generated_torque_definitions", + ], + deps = [ +- ":lib_dragonbox", +- "//third_party/fast_float/src:fast_float", +- ":lib_fp16", +- ":simdutf", ++ "@dragonbox//:dragonbox", ++ "@fast_float//:fast_float", ++ "@fp16//:FP16", ++ "@simdutf//:simdutf", + ":v8_libbase", + "@abseil-cpp//absl/container:btree", + "@abseil-cpp//absl/container:flat_hash_map", +diff --git a/bazel/defs.bzl b/bazel/defs.bzl +index 9648e4a5..75102917 100644 +--- a/bazel/defs.bzl ++++ b/bazel/defs.bzl +@@ -98,7 +98,7 @@ def _default_args(): + def _default_args(): + return struct( +- deps = [":define_flags", "@libcxx//:libc++"], ++ deps = [":define_flags"], + defines = select({ + "@v8//bazel/config:is_windows": [ + "UNICODE", +@@ -112,8 +112,7 @@ def _default_args(): + "-fPIC", + "-fno-strict-aliasing", +- "-fconstexpr-steps=2000000", +- "-Werror", ++ "-Wno-error", # Envoy build should not fail for warnings in dependencies + "-Wextra", + "-Wno-unneeded-internal-declaration", + "-Wno-unknown-warning-option", # b/330781959 +@@ -123,6 +122,9 @@ def _default_args(): + "-Wno-implicit-int-float-conversion", + "-Wno-deprecated-copy", + "-Wno-non-virtual-dtor", ++ "-Wno-invalid-offsetof", ++ "-Wno-dangling-pointer", ++ "-Wno-dangling-reference", + "-Wno-unnecessary-virtual-specifier", + "-isystem .", + ], +@@ -133,6 +135,8 @@ def _default_args(): + "@v8//bazel/config:is_clang": [ + "-Wno-invalid-offsetof", ++ # -fconstexpr-steps is clang-only; moved here from is_posix block. ++ "-fconstexpr-steps=2000000", + "-Wno-deprecated-this-capture", + "-Wno-deprecated-declarations", + "-std=c++20", +@@ -148,6 +152,9 @@ def _default_args(): + "-Wno-return-type", + "-Wno-stringop-overflow", + "-Wno-deprecated-this-capture", ++ "-Wno-error", # Envoy build should not fail for warnings in dependencies ++ "-Wno-unused-variable", ++ "-flax-vector-conversions", # for GCC builds on ARM + # Use GNU dialect, because GCC doesn't allow using + # ##__VA_ARGS__ when in standards-conforming mode. + "-std=gnu++2a", +@@ -184,10 +192,27 @@ def _default_args(): + "Advapi32.lib", + ], + "@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": [], ++ }) + select({ ++ "@envoy//bazel:no_debug_info": [ ++ "-g0", ++ ], ++ "//conditions:default": [], ++ }) + select({ ++ "@v8//bazel/config:is_macos": [ ++ # The clang available on macOS catalina has a warning that isn't clean on v8 code. ++ "-Wno-range-loop-analysis", ++ ++ # To supress warning on deprecated declaration on v8 code. For example: ++ # external/v8/src/base/platform/platform-darwin.cc:56:22: 'getsectdatafromheader_64' ++ # is deprecated: first deprecated in macOS 13.0. ++ # https://bugs.chromium.org/p/v8/issues/detail?id=13428. ++ "-Wno-deprecated-declarations", ++ ], ++ "//conditions:default": [], + }), + ) + +diff --git a/src/common/globals.h b/src/common/globals.h +--- a/src/common/globals.h ++++ b/src/common/globals.h +@@ -578,7 +578,7 @@ static const char* kPointerTableAddressSpaceName = "v8-pointer-table"; + // virtual memory ranges (PR_SET_VMA_ANON_NAME on Linux). + // TODO(saelo): It might be nicer to have one name per table type, e.g. + // v8-external-pointer-table, v8-trusted-pointer-table, etc. +-static const char* kPointerTableAddressSpaceName = "v8-pointer-table"; ++[[maybe_unused]] static const char* kPointerTableAddressSpaceName = "v8-pointer-table"; + + // + // JavaScript Dispatch Table +diff --git a/src/wasm/c-api.cc b/src/wasm/c-api.cc +index 78e62abb..d7edf951 100644 +--- a/src/wasm/c-api.cc ++++ b/src/wasm/c-api.cc +@@ -2482,6 +2482,8 @@ WASM_EXPORT auto Instance::exports() const -> ownvec { + + } // namespace wasm + ++#if 0 ++ + // BEGIN FILE wasm-c.cc + + extern "C" { +@@ -3528,3 +3530,5 @@ wasm_instance_t* wasm_frame_instance(const wasm_frame_t* frame) { + #undef WASM_DEFINE_SHARABLE_REF + + } // extern "C" ++ ++#endif +diff --git a/src/objects/objects-inl.h b/src/objects/objects-inl.h +--- a/src/objects/objects-inl.h ++++ b/src/objects/objects-inl.h +@@ -1618,11 +1618,13 @@ + #ifndef V8_DISABLE_WRITE_BARRIERS + if (emit_write_barrier == EmitWriteBarrier::kYes) { + WriteBarrier::ForValue(*this, MaybeObjectSlot(map_slot()), value, + UPDATE_WRITE_BARRIER); + } else { + DCHECK_EQ(emit_write_barrier, EmitWriteBarrier::kNo); ++#if V8_VERIFY_WRITE_BARRIERS + DCHECK(!WriteBarrier::IsRequired(*this, value)); ++#endif + } + #endif + } +@@ -1641,10 +1643,12 @@ + #ifndef V8_DISABLE_WRITE_BARRIERS + if (mode != SKIP_WRITE_BARRIER) { + DCHECK(!value.is_null()); + WriteBarrier::ForValue(*this, MaybeObjectSlot(map_slot()), value, mode); + } else { ++#if V8_VERIFY_WRITE_BARRIERS + SLOW_DCHECK( + // We allow writes of a null map before root initialisation. + value.is_null() ? !isolate->read_only_heap()->roots_init_complete() + : !WriteBarrier::IsRequired(*this, value)); ++#endif + } + #endif + } +diff --git a/third_party/inspector_protocol/code_generator.py b/third_party/inspector_protocol/code_generator.py +index 49952dda..268af813 100755 +--- a/third_party/inspector_protocol/code_generator.py ++++ b/third_party/inspector_protocol/code_generator.py +@@ -16,6 +16,8 @@ try: + except ImportError: + import simplejson as json + ++sys.path += [os.path.dirname(__file__)] ++ + import pdl + + try: diff --git a/bazel/v8/patches/v8_module.patch b/bazel/v8/patches/v8_module.patch new file mode 100644 index 0000000000..d1acf90336 --- /dev/null +++ b/bazel/v8/patches/v8_module.patch @@ -0,0 +1,335 @@ +--- a/MODULE.bazel 2026-08-19 19:01:32.169095878 +0200 ++++ b/MODULE.bazel 2026-08-19 19:02:31.860618418 +0200 +@@ -21,169 +21,169 @@ + ], + ) + 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("@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, +- 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", +- ], +- toolchain_identifier = "local_clang", +- 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], +-) +-""", +- build_file_content = """ +-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 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("@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, ++# 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", ++# ], ++# toolchain_identifier = "local_clang", ++# 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], ++# ) ++# """, ++# build_file_content = """ ++# 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") + diff --git a/bazel/v8/patches/v8_no_python_load.patch b/bazel/v8/patches/v8_no_python_load.patch new file mode 100644 index 0000000000..903783bc44 --- /dev/null +++ b/bazel/v8/patches/v8_no_python_load.patch @@ -0,0 +1,190 @@ +diff --git a/BUILD.bazel b/BUILD.bazel +index 85f31b7a..eeba8efa 100644 +--- a/BUILD.bazel ++++ b/BUILD.bazel +@@ -6,7 +6,7 @@ load("@bazel_skylib//lib:selects.bzl", "selects") + load("@rules_cc//cc:cc_library.bzl", "cc_library") + load("@rules_cc//cc:cc_binary.bzl", "cc_binary") + load("@rules_python//python:defs.bzl", "py_binary", "py_test") +-load("@v8_python_deps//:requirements.bzl", "requirement") ++load("@base_pip3//:requirements.bzl", "requirement") + load( + "@v8//:bazel/defs.bzl", + "v8_binary", +@@ -303,7 +303,7 @@ v8_int( + # 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", + ) + + # Default setting for v8_enable_pointer_compression. +@@ -4607,10 +4607,10 @@ v8_library( + ":noicu/generated_torque_definitions", + ], + deps = [ +- ":lib_dragonbox", +- "//third_party/fast_float/src:fast_float", +- ":lib_fp16", +- ":simdutf", ++ "@dragonbox//:dragonbox", ++ "@fast_float//:fast_float", ++ "@fp16//:FP16", ++ "@simdutf//:simdutf", + ":v8_libbase", + "@abseil-cpp//absl/container:btree", + "@abseil-cpp//absl/container:flat_hash_map", +diff --git a/bazel/defs.bzl b/bazel/defs.bzl +index 9648e4a5..75102917 100644 +--- a/bazel/defs.bzl ++++ b/bazel/defs.bzl +@@ -98,7 +98,7 @@ def _default_args(): + def _default_args(): + return struct( +- deps = [":define_flags", "@libcxx//:libc++"], ++ deps = [":define_flags"], + defines = select({ + "@v8//bazel/config:is_windows": [ + "UNICODE", +@@ -112,8 +112,7 @@ def _default_args(): + "-fPIC", + "-fno-strict-aliasing", +- "-fconstexpr-steps=2000000", +- "-Werror", ++ "-Wno-error", # Envoy build should not fail for warnings in dependencies + "-Wextra", + "-Wno-unneeded-internal-declaration", + "-Wno-unknown-warning-option", # b/330781959 +@@ -123,6 +122,9 @@ def _default_args(): + "-Wno-implicit-int-float-conversion", + "-Wno-deprecated-copy", + "-Wno-non-virtual-dtor", ++ "-Wno-invalid-offsetof", ++ "-Wno-dangling-pointer", ++ "-Wno-dangling-reference", + "-Wno-unnecessary-virtual-specifier", + "-isystem .", + ], +@@ -133,6 +135,8 @@ def _default_args(): + "@v8//bazel/config:is_clang": [ + "-Wno-invalid-offsetof", ++ # -fconstexpr-steps is clang-only; moved here from is_posix block. ++ "-fconstexpr-steps=2000000", + "-Wno-deprecated-this-capture", + "-Wno-deprecated-declarations", + "-std=c++20", +@@ -148,6 +152,9 @@ def _default_args(): + "-Wno-return-type", + "-Wno-stringop-overflow", + "-Wno-deprecated-this-capture", ++ "-Wno-error", # Envoy build should not fail for warnings in dependencies ++ "-Wno-unused-variable", ++ "-flax-vector-conversions", # for GCC builds on ARM + # Use GNU dialect, because GCC doesn't allow using + # ##__VA_ARGS__ when in standards-conforming mode. + "-std=gnu++2a", +@@ -184,10 +192,27 @@ def _default_args(): + "Advapi32.lib", + ], + "@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": [], ++ }) + select({ ++ "@envoy_toolshed//bazel:no_debug_info": [ ++ "-g0", ++ ], ++ "//conditions:default": [], ++ }) + select({ ++ "@v8//bazel/config:is_macos": [ ++ # The clang available on macOS catalina has a warning that isn't clean on v8 code. ++ "-Wno-range-loop-analysis", ++ ++ # To supress warning on deprecated declaration on v8 code. For example: ++ # external/v8/src/base/platform/platform-darwin.cc:56:22: 'getsectdatafromheader_64' ++ # is deprecated: first deprecated in macOS 13.0. ++ # https://bugs.chromium.org/p/v8/issues/detail?id=13428. ++ "-Wno-deprecated-declarations", ++ ], ++ "//conditions:default": [], + }), + ) + +diff --git a/src/common/globals.h b/src/common/globals.h +--- a/src/common/globals.h ++++ b/src/common/globals.h +@@ -578,7 +578,7 @@ static const char* kPointerTableAddressSpaceName = "v8-pointer-table"; + // virtual memory ranges (PR_SET_VMA_ANON_NAME on Linux). + // TODO(saelo): It might be nicer to have one name per table type, e.g. + // v8-external-pointer-table, v8-trusted-pointer-table, etc. +-static const char* kPointerTableAddressSpaceName = "v8-pointer-table"; ++[[maybe_unused]] static const char* kPointerTableAddressSpaceName = "v8-pointer-table"; + + // + // JavaScript Dispatch Table +diff --git a/src/wasm/c-api.cc b/src/wasm/c-api.cc +index 78e62abb..d7edf951 100644 +--- a/src/wasm/c-api.cc ++++ b/src/wasm/c-api.cc +@@ -2482,6 +2482,8 @@ WASM_EXPORT auto Instance::exports() const -> ownvec { + + } // namespace wasm + ++#if 0 ++ + // BEGIN FILE wasm-c.cc + + extern "C" { +@@ -3528,3 +3530,5 @@ wasm_instance_t* wasm_frame_instance(const wasm_frame_t* frame) { + #undef WASM_DEFINE_SHARABLE_REF + + } // extern "C" ++ ++#endif +diff --git a/src/objects/objects-inl.h b/src/objects/objects-inl.h +--- a/src/objects/objects-inl.h ++++ b/src/objects/objects-inl.h +@@ -1618,11 +1618,13 @@ + #ifndef V8_DISABLE_WRITE_BARRIERS + if (emit_write_barrier == EmitWriteBarrier::kYes) { + WriteBarrier::ForValue(*this, MaybeObjectSlot(map_slot()), value, + UPDATE_WRITE_BARRIER); + } else { + DCHECK_EQ(emit_write_barrier, EmitWriteBarrier::kNo); ++#if V8_VERIFY_WRITE_BARRIERS + DCHECK(!WriteBarrier::IsRequired(*this, value)); ++#endif + } + #endif + } +@@ -1641,10 +1643,12 @@ + #ifndef V8_DISABLE_WRITE_BARRIERS + if (mode != SKIP_WRITE_BARRIER) { + DCHECK(!value.is_null()); + WriteBarrier::ForValue(*this, MaybeObjectSlot(map_slot()), value, mode); + } else { ++#if V8_VERIFY_WRITE_BARRIERS + SLOW_DCHECK( + // We allow writes of a null map before root initialisation. + value.is_null() ? !isolate->read_only_heap()->roots_init_complete() + : !WriteBarrier::IsRequired(*this, value)); ++#endif + } + #endif + } +diff --git a/third_party/inspector_protocol/code_generator.py b/third_party/inspector_protocol/code_generator.py +index 49952dda..268af813 100755 +--- a/third_party/inspector_protocol/code_generator.py ++++ b/third_party/inspector_protocol/code_generator.py +@@ -16,6 +16,8 @@ try: + except ImportError: + import simplejson as json + ++sys.path += [os.path.dirname(__file__)] ++ + import pdl + + try: diff --git a/bazel/v8/patches/v8_novtune.patch b/bazel/v8/patches/v8_novtune.patch new file mode 100644 index 0000000000..64226df377 --- /dev/null +++ b/bazel/v8/patches/v8_novtune.patch @@ -0,0 +1,18 @@ +diff --git a/BUILD.bazel b/BUILD.bazel +index 3f5a87d054e..740b1f1773b 100644 +--- a/BUILD.bazel ++++ b/BUILD.bazel +@@ -4477,12 +4477,7 @@ v8_library( + copts = ["-Wno-implicit-fallthrough"], + strip_include_prefix = "third_party", + visibility = ["//visibility:public"], +- deps = [":noicu/v8"] + select({ +- ":is_v8_enable_vtunejit": [ +- ":v8_vtune", +- ], +- "//conditions:default": [], +- }), ++ deps = [":noicu/v8"], + ) + + alias( diff --git a/bazel/v8/patches/v8_ppc64le.patch b/bazel/v8/patches/v8_ppc64le.patch new file mode 100644 index 0000000000..c149df5c0a --- /dev/null +++ b/bazel/v8/patches/v8_ppc64le.patch @@ -0,0 +1,13 @@ +diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel +index 448260d..fe50366 100644 +--- a/bazel/config/BUILD.bazel ++++ b/bazel/config/BUILD.bazel +@@ -61,7 +61,7 @@ config_setting( + + config_setting( + name = "platform_cpu_ppc64le", +- constraint_values = ["@platforms//cpu:ppc"], ++ constraint_values = ["@platforms//cpu:ppc64le"], + ) + + v8_target_cpu( diff --git a/bazel/v8/patches/v8_python.patch b/bazel/v8/patches/v8_python.patch new file mode 100644 index 0000000000..eef2930edd --- /dev/null +++ b/bazel/v8/patches/v8_python.patch @@ -0,0 +1,22 @@ +diff --git a/BUILD.bazel b/BUILD.bazel +index f2b2f4da0f8..26aebd1fdca 100644 +--- a/BUILD.bazel ++++ b/BUILD.bazel +@@ -4136,11 +4136,15 @@ genrule( + "src/inspector/protocol/Schema.cpp", + "src/inspector/protocol/Schema.h", + ], +- cmd = "$(location :code_generator) --jinja_dir . \ ++ cmd = """ ++ export PATH=$$(dirname $$(realpath $(PYTHON3))):$$PATH ++ $(location :code_generator) --jinja_dir . \ + --inspector_protocol_dir third_party/inspector_protocol \ + --config $(location :src/inspector/inspector_protocol_config.json) \ + --config_value protocol.path=$(location :include/js_protocol.pdl) \ +- --output_base $(@D)/src/inspector", ++ --output_base $(@D)/src/inspector ++ """, ++ toolchains = ["@rules_python//python:current_py_toolchain"], + local = 1, + message = "Generating inspector files", + tools = [ diff --git a/bazel/v8/requirements.txt b/bazel/v8/requirements.txt new file mode 100644 index 0000000000..cf9ba3062f --- /dev/null +++ b/bazel/v8/requirements.txt @@ -0,0 +1,4 @@ +# Minimal Python requirements for V8 code generation +# V8 primarily needs jinja2 for code generation from templates +jinja2==3.1.4 +markupsafe==2.1.5 diff --git a/bazel/v8/wee8_prebuilt.bzl b/bazel/v8/wee8_prebuilt.bzl index 9d0a4f9971..da62321ab1 100644 --- a/bazel/v8/wee8_prebuilt.bzl +++ b/bazel/v8/wee8_prebuilt.bzl @@ -35,8 +35,15 @@ cc_library( includes = [ ".", "include", + "third_party", + ], + defines = [ + "V8_ENABLE_WEBASSEMBLY", ], linkstatic = True, + deps = [ + "@abseil-cpp//absl/strings:str_format", + ], ) """ @@ -180,3 +187,32 @@ def setup_wee8_prebuilt( arch = arch, stdlib = stdlib, ) + +_V8_ALIAS_BUILD = """\ +# Auto-generated by envoy_toolshed//v8:wee8_prebuilt.bzl +# This repository provides a @v8//:wee8 alias to the prebuilt wee8 library. +package(default_visibility = ["//visibility:public"]) + +alias( + name = "wee8", + actual = "@envoy_toolshed//v8:wee8", +) +""" + +def _v8_prebuilt_alias_impl(ctx): + """Create a @v8 repository that aliases to envoy_toolshed prebuilt wee8.""" + ctx.file("BUILD.bazel", _V8_ALIAS_BUILD) + ctx.file("WORKSPACE", "") + +_v8_prebuilt_alias = repository_rule( + implementation = _v8_prebuilt_alias_impl, + doc = "Creates a @v8 repository alias to use prebuilt wee8", +) + +def v8_prebuilt_alias(): + """Create @v8 repository that aliases to envoy_toolshed prebuilt wee8. + + This allows external dependencies (like proxy_wasm_cpp_host) that reference + @v8//:wee8 to automatically use the prebuilt library instead of building from source. + """ + _v8_prebuilt_alias(name = "v8")