From b47b5dae0da6ccff60eb956e3c251b6e91fc93ad Mon Sep 17 00:00:00 2001 From: Channing Conger Date: Fri, 8 May 2026 00:23:13 -0700 Subject: [PATCH] bazel: build rusty_v8 release artifacts hermetically --- .bazelrc | 5 + .github/scripts/rusty_v8_bazel.py | 174 ++------------- .github/scripts/test_rusty_v8_bazel.py | 171 +++++--------- .github/workflows/rusty-v8-release.yml | 209 ++++++++---------- .github/workflows/v8-canary.yml | 205 ++++++++--------- MODULE.bazel | 30 +++ patches/BUILD.bazel | 1 + patches/rules_cc_rusty_v8_custom_libcxx.patch | 35 +++ patches/v8_bazel_rules.patch | 175 ++++++++++++--- third_party/v8/BUILD.bazel | 119 ++++++---- third_party/v8/README.md | 35 +-- third_party/v8/libcxx.BUILD.bazel | 157 +++++++++++++ third_party/v8/libcxx_config/BUILD.bazel | 12 + .../v8/libcxx_config/__assertion_handler | 27 +++ third_party/v8/libcxx_config/__config_site | 55 +++++ third_party/v8/libcxxabi.BUILD.bazel | 98 ++++++++ third_party/v8/llvm_libc.BUILD.bazel | 10 + 17 files changed, 917 insertions(+), 601 deletions(-) create mode 100644 patches/rules_cc_rusty_v8_custom_libcxx.patch create mode 100644 third_party/v8/libcxx.BUILD.bazel create mode 100644 third_party/v8/libcxx_config/BUILD.bazel create mode 100644 third_party/v8/libcxx_config/__assertion_handler create mode 100644 third_party/v8/libcxx_config/__config_site create mode 100644 third_party/v8/libcxxabi.BUILD.bazel create mode 100644 third_party/v8/llvm_libc.BUILD.bazel diff --git a/.bazelrc b/.bazelrc index 911e0802b5..6357eb83e4 100644 --- a/.bazelrc +++ b/.bazelrc @@ -193,5 +193,10 @@ common --@v8//:v8_enable_sandbox=True common:v8-release-compat --@v8//:v8_enable_pointer_compression=False common:v8-release-compat --@v8//:v8_enable_sandbox=False +# Match rusty_v8's upstream GN release contract for published artifacts: every +# target object uses Chromium's custom libc++ headers and the archive folds in +# the matching runtime objects. +common:rusty-v8-upstream-libcxx --@v8//:v8_use_rusty_v8_custom_libcxx=True + # Optional per-user local overrides. try-import %workspace%/user.bazelrc diff --git a/.github/scripts/rusty_v8_bazel.py b/.github/scripts/rusty_v8_bazel.py index 33455b93a1..f380cc7a51 100644 --- a/.github/scripts/rusty_v8_bazel.py +++ b/.github/scripts/rusty_v8_bazel.py @@ -9,7 +9,6 @@ import re import shutil import subprocess import sys -import tempfile import tomllib from pathlib import Path @@ -23,14 +22,9 @@ from rusty_v8_module_bazel import ( ROOT = Path(__file__).resolve().parents[2] MODULE_BAZEL = ROOT / "MODULE.bazel" RUSTY_V8_CHECKSUMS_DIR = ROOT / "third_party" / "v8" -STATIC_RUNTIME_ARCHIVE_LABELS = [ - "@llvm//runtimes/libcxx:libcxx.static", - "@llvm//runtimes/libcxx:libcxxabi.static", -] -LLVM_AR_LABEL = "@llvm//tools:llvm-ar" -LLVM_RANLIB_LABEL = "@llvm//tools:llvm-ranlib" RELEASE_ARTIFACT_PROFILE = "release" SANDBOX_ARTIFACT_PROFILE = "ptrcomp_sandbox_release" +ARTIFACT_BAZEL_CONFIGS = ["rusty-v8-upstream-libcxx"] def bazel_execroot() -> Path: @@ -116,10 +110,8 @@ def ensure_bazel_output_files( compilation_mode: str = "fastbuild", bazel_configs: list[str] | None = None, ) -> list[Path]: - outputs = bazel_output_files(platform, labels, compilation_mode, bazel_configs) - if all(path.exists() for path in outputs): - return outputs - + # Bazel output paths can be reused across config flips, so existence alone + # does not prove the files match the requested flags. bazel_build(platform, labels, compilation_mode, bazel_configs) outputs = bazel_output_files(platform, labels, compilation_mode, bazel_configs) missing = [str(path) for path in outputs if not path.exists()] @@ -128,6 +120,14 @@ def ensure_bazel_output_files( return outputs +def artifact_bazel_configs(bazel_configs: list[str] | None = None) -> list[str]: + configured = list(ARTIFACT_BAZEL_CONFIGS) + for config in bazel_configs or []: + if config not in configured: + configured.append(config) + return configured + + def release_pair_label(target: str, sandbox: bool = False) -> str: target_suffix = target.replace("-", "_") pair_kind = "sandbox_release_pair" if sandbox else "release_pair" @@ -184,7 +184,7 @@ def command_manifest_path(manifest: Path | None, version: str) -> Path: def staged_archive_name(target: str, source_path: Path, artifact_profile: str) -> str: - if source_path.suffix == ".lib": + if target.endswith("-pc-windows-msvc"): return f"rusty_v8_{artifact_profile}_{target}.lib.gz" return f"librusty_v8_{artifact_profile}_{target}.a.gz" @@ -197,122 +197,6 @@ def staged_checksums_name(target: str, artifact_profile: str) -> str: return f"rusty_v8_{artifact_profile}_{target}.sha256" -def needs_merged_runtime_archive(target: str, source_path: Path) -> bool: - return source_path.suffix == ".a" and target.endswith( - ("-unknown-linux-gnu", "-unknown-linux-musl") - ) - - -def single_bazel_output_file( - platform: str, - label: str, - compilation_mode: str = "fastbuild", - bazel_configs: list[str] | None = None, -) -> Path: - outputs = ensure_bazel_output_files(platform, [label], compilation_mode, bazel_configs) - if len(outputs) != 1: - raise SystemExit(f"expected exactly one output for {label}, found {outputs}") - return outputs[0] - - -def host_runnable_bazel_output_file( - platform: str, - label: str, - compilation_mode: str = "fastbuild", - bazel_configs: list[str] | None = None, -) -> Path: - outputs = ensure_bazel_output_files(platform, [label], compilation_mode, bazel_configs) - if len(outputs) == 1: - return outputs[0] - - runnable_outputs = [] - for output in outputs: - try: - result = subprocess.run( - [str(output), "--version"], - cwd=ROOT, - capture_output=True, - text=True, - ) - except OSError: - continue - if result.returncode == 0: - runnable_outputs.append(output) - - if len(runnable_outputs) != 1: - raise SystemExit( - f"expected exactly one host-runnable output for {label}, " - f"found {runnable_outputs} from {outputs}" - ) - return runnable_outputs[0] - - -def merged_archive( - platform: str, - lib_path: Path, - extra_archives: list[Path], - compilation_mode: str = "fastbuild", - bazel_configs: list[str] | None = None, -) -> Path: - llvm_ar = host_runnable_bazel_output_file( - platform, - LLVM_AR_LABEL, - compilation_mode, - bazel_configs, - ) - llvm_ranlib = host_runnable_bazel_output_file( - platform, - LLVM_RANLIB_LABEL, - compilation_mode, - bazel_configs, - ) - temp_dir = Path(tempfile.mkdtemp(prefix="rusty-v8-runtime-stage-")) - merged_archive = temp_dir / lib_path.name - merge_commands = "\n".join( - [ - f"create {merged_archive}", - f"addlib {lib_path}", - *[f"addlib {archive}" for archive in extra_archives], - "save", - "end", - ] - ) - subprocess.run( - [str(llvm_ar), "-M"], - cwd=ROOT, - check=True, - input=merge_commands, - text=True, - ) - subprocess.run([str(llvm_ranlib), str(merged_archive)], cwd=ROOT, check=True) - return merged_archive - - -def merged_built_runtime_archive( - platform: str, - lib_path: Path, - compilation_mode: str = "fastbuild", - bazel_configs: list[str] | None = None, -) -> Path: - runtime_archives = [ - single_bazel_output_file(platform, label, compilation_mode, bazel_configs) - for label in STATIC_RUNTIME_ARCHIVE_LABELS - ] - return merged_archive( - platform, - lib_path, - runtime_archives, - compilation_mode, - bazel_configs, - ) - - -def upstream_release_pair_paths(source_root: Path, target: str) -> tuple[Path, Path]: - lib_name = "rusty_v8.lib" if target.endswith("-pc-windows-msvc") else "librusty_v8.a" - gn_out = source_root / "target" / target / "release" / "gn_out" - return gn_out / "obj" / lib_name, gn_out / "src_binding.rs" - - def stage_artifacts( target: str, lib_path: Path, @@ -355,16 +239,6 @@ def stage_artifacts( print(staged_checksums) -def stage_upstream_release_pair( - source_root: Path, - target: str, - output_dir: Path, - sandbox: bool = False, -) -> None: - lib_path, binding_path = upstream_release_pair_paths(source_root, target) - stage_artifacts(target, lib_path, binding_path, output_dir, sandbox) - - def stage_release_pair( platform: str, target: str, @@ -373,6 +247,7 @@ def stage_release_pair( bazel_configs: list[str] | None = None, sandbox: bool = False, ) -> None: + bazel_configs = artifact_bazel_configs(bazel_configs) outputs = ensure_bazel_output_files( platform, [release_pair_label(target, sandbox)], @@ -390,12 +265,7 @@ def stage_release_pair( except StopIteration as exc: raise SystemExit(f"missing Rust binding output for {target}") from exc - source_archive = ( - merged_built_runtime_archive(platform, lib_path, compilation_mode, bazel_configs) - if needs_merged_runtime_archive(target, lib_path) - else lib_path - ) - stage_artifacts(target, source_archive, binding_path, output_dir, sandbox) + stage_artifacts(target, lib_path, binding_path, output_dir, sandbox) def parse_args() -> argparse.Namespace: @@ -419,14 +289,6 @@ def parse_args() -> argparse.Namespace: choices=["fastbuild", "opt", "dbg"], ) - stage_upstream_release_pair_parser = subparsers.add_parser( - "stage-upstream-release-pair" - ) - stage_upstream_release_pair_parser.add_argument("--source-root", type=Path, required=True) - stage_upstream_release_pair_parser.add_argument("--target", required=True) - stage_upstream_release_pair_parser.add_argument("--output-dir", required=True) - stage_upstream_release_pair_parser.add_argument("--sandbox", action="store_true") - subparsers.add_parser("resolved-v8-crate-version") check_module_bazel_parser = subparsers.add_parser("check-module-bazel") @@ -462,14 +324,6 @@ def main() -> int: sandbox=args.sandbox, ) return 0 - if args.command == "stage-upstream-release-pair": - stage_upstream_release_pair( - source_root=args.source_root, - target=args.target, - output_dir=Path(args.output_dir), - sandbox=args.sandbox, - ) - return 0 if args.command == "resolved-v8-crate-version": print(resolved_v8_crate_version()) return 0 diff --git a/.github/scripts/test_rusty_v8_bazel.py b/.github/scripts/test_rusty_v8_bazel.py index 5d68336980..66c69f9a5b 100644 --- a/.github/scripts/test_rusty_v8_bazel.py +++ b/.github/scripts/test_rusty_v8_bazel.py @@ -4,9 +4,8 @@ from __future__ import annotations import textwrap import unittest -from tempfile import TemporaryDirectory from pathlib import Path -from unittest.mock import Mock +from tempfile import TemporaryDirectory from unittest.mock import patch import rusty_v8_bazel @@ -14,6 +13,22 @@ import rusty_v8_module_bazel class RustyV8BazelTest(unittest.TestCase): + def test_artifact_bazel_configs_always_enable_upstream_libcxx(self) -> None: + self.assertEqual( + ["rusty-v8-upstream-libcxx"], + rusty_v8_bazel.artifact_bazel_configs(), + ) + self.assertEqual( + ["rusty-v8-upstream-libcxx", "v8-release-compat"], + rusty_v8_bazel.artifact_bazel_configs(["v8-release-compat"]), + ) + self.assertEqual( + ["rusty-v8-upstream-libcxx", "v8-release-compat"], + rusty_v8_bazel.artifact_bazel_configs( + ["rusty-v8-upstream-libcxx", "v8-release-compat"] + ), + ) + def test_release_pair_labels_and_staged_names_distinguish_sandbox_artifacts(self) -> None: self.assertEqual( "//third_party/v8:rusty_v8_release_pair_x86_64_unknown_linux_musl", @@ -36,7 +51,7 @@ class RustyV8BazelTest(unittest.TestCase): ), ) self.assertEqual( - "librusty_v8_ptrcomp_sandbox_release_x86_64-pc-windows-msvc.a.gz", + "rusty_v8_ptrcomp_sandbox_release_x86_64-pc-windows-msvc.lib.gz", rusty_v8_bazel.staged_archive_name( "x86_64-pc-windows-msvc", Path("v8.a"), @@ -58,77 +73,18 @@ class RustyV8BazelTest(unittest.TestCase): ), ) - def test_needs_merged_runtime_archive(self) -> None: - for target in [ - "x86_64-unknown-linux-gnu", - "x86_64-unknown-linux-musl", - ]: - self.assertTrue(rusty_v8_bazel.needs_merged_runtime_archive(target, Path("v8.a"))) - - self.assertFalse( - rusty_v8_bazel.needs_merged_runtime_archive( - "x86_64-apple-darwin", - Path("v8.a"), - ) - ) - self.assertFalse( - rusty_v8_bazel.needs_merged_runtime_archive( - "x86_64-pc-windows-msvc", - Path("v8.a"), - ) - ) - - def test_upstream_release_pair_paths(self) -> None: - self.assertEqual( - ( - Path( - "/tmp/rusty_v8/target/x86_64-apple-darwin/release/gn_out/obj/" - "librusty_v8.a" - ), - Path( - "/tmp/rusty_v8/target/x86_64-apple-darwin/release/gn_out/" - "src_binding.rs" - ), - ), - rusty_v8_bazel.upstream_release_pair_paths( - Path("/tmp/rusty_v8"), - "x86_64-apple-darwin", - ), - ) - self.assertEqual( - ( - Path( - "/tmp/rusty_v8/target/x86_64-pc-windows-msvc/release/gn_out/" - "obj/rusty_v8.lib" - ), - Path( - "/tmp/rusty_v8/target/x86_64-pc-windows-msvc/release/gn_out/" - "src_binding.rs" - ), - ), - rusty_v8_bazel.upstream_release_pair_paths( - Path("/tmp/rusty_v8"), - "x86_64-pc-windows-msvc", - ), - ) - - def test_stage_upstream_release_pair(self) -> None: + def test_stage_artifacts(self) -> None: with TemporaryDirectory() as source_dir, TemporaryDirectory() as output_dir: source_root = Path(source_dir) - gn_out = ( - source_root - / "target" - / "aarch64-apple-darwin" - / "release" - / "gn_out" - ) - (gn_out / "obj").mkdir(parents=True) - (gn_out / "obj" / "librusty_v8.a").write_bytes(b"archive") - (gn_out / "src_binding.rs").write_text("binding") + archive = source_root / "librusty_v8.a" + binding = source_root / "src_binding.rs" + archive.write_bytes(b"archive") + binding.write_text("binding") - rusty_v8_bazel.stage_upstream_release_pair( - source_root, + rusty_v8_bazel.stage_artifacts( "aarch64-apple-darwin", + archive, + binding, Path(output_dir), sandbox=True, ) @@ -142,53 +98,40 @@ class RustyV8BazelTest(unittest.TestCase): {path.name for path in Path(output_dir).iterdir()}, ) - @patch("rusty_v8_bazel.ensure_bazel_output_files") - @patch("rusty_v8_bazel.subprocess.run") - def test_host_runnable_bazel_output_file_selects_runnable_candidate( - self, - run: Mock, - ensure_outputs: Mock, - ) -> None: - amd64_tool = Path("/tmp/llvm-amd64/bin/llvm-ar") - arm64_tool = Path("/tmp/llvm-arm64/bin/llvm-ar") - ensure_outputs.return_value = [amd64_tool, arm64_tool] - run.side_effect = [ - OSError("Exec format error"), - Mock(returncode=0), - ] + def test_ensure_bazel_output_files_rebuilds_existing_outputs(self) -> None: + with TemporaryDirectory() as output_dir: + output = Path(output_dir) / "libv8.a" + output.write_bytes(b"archive") - self.assertEqual( - arm64_tool, - rusty_v8_bazel.host_runnable_bazel_output_file( - "linux_arm64_musl", - "@llvm//tools:llvm-ar", + with ( + patch.object(rusty_v8_bazel, "bazel_build") as bazel_build, + patch.object( + rusty_v8_bazel, + "bazel_output_files", + return_value=[output], + ) as bazel_output_files, + ): + self.assertEqual( + [output], + rusty_v8_bazel.ensure_bazel_output_files( + "macos_arm64", + ["//third_party/v8:pair"], + "opt", + ["rusty-v8-upstream-libcxx"], + ), + ) + + bazel_build.assert_called_once_with( + "macos_arm64", + ["//third_party/v8:pair"], "opt", - ), - ) - - @patch("rusty_v8_bazel.ensure_bazel_output_files") - @patch("rusty_v8_bazel.subprocess.run") - def test_host_runnable_bazel_output_file_rejects_ambiguous_candidates( - self, - run: Mock, - ensure_outputs: Mock, - ) -> None: - amd64_tool = Path("/tmp/llvm-amd64/bin/llvm-ar") - arm64_tool = Path("/tmp/llvm-arm64/bin/llvm-ar") - ensure_outputs.return_value = [amd64_tool, arm64_tool] - run.side_effect = [ - Mock(returncode=0), - Mock(returncode=0), - ] - - with self.assertRaisesRegex( - SystemExit, - "expected exactly one host-runnable output", - ): - rusty_v8_bazel.host_runnable_bazel_output_file( - "linux_arm64_musl", - "@llvm//tools:llvm-ar", + ["rusty-v8-upstream-libcxx"], + ) + bazel_output_files.assert_called_once_with( + "macos_arm64", + ["//third_party/v8:pair"], "opt", + ["rusty-v8-upstream-libcxx"], ) def test_update_module_bazel_replaces_and_inserts_sha256(self) -> None: diff --git a/.github/workflows/rusty-v8-release.yml b/.github/workflows/rusty-v8-release.yml index 24c63bf703..0b1776ba73 100644 --- a/.github/workflows/rusty-v8-release.yml +++ b/.github/workflows/rusty-v8-release.yml @@ -64,63 +64,77 @@ jobs: matrix: include: - runner: ubuntu-24.04 - producer: upstream + bazel_config: ci-v8 + platform: linux_amd64 + sandbox: false + target: x86_64-unknown-linux-gnu + variant: release + - runner: ubuntu-24.04 + bazel_config: ci-v8 + platform: linux_amd64 sandbox: true target: x86_64-unknown-linux-gnu variant: ptrcomp-sandbox - runner: ubuntu-24.04-arm - producer: upstream + bazel_config: ci-v8 + platform: linux_arm64 + sandbox: false + target: aarch64-unknown-linux-gnu + variant: release + - runner: ubuntu-24.04-arm + bazel_config: ci-v8 + platform: linux_arm64 sandbox: true target: aarch64-unknown-linux-gnu variant: ptrcomp-sandbox - - runner: macos-15-large - producer: upstream + - runner: macos-15-xlarge + bazel_config: ci-macos + platform: macos_amd64 + sandbox: false + target: x86_64-apple-darwin + variant: release + - runner: macos-15-xlarge + bazel_config: ci-macos + platform: macos_amd64 sandbox: true target: x86_64-apple-darwin variant: ptrcomp-sandbox - - runner: macos-15 - producer: upstream + - runner: macos-15-xlarge + bazel_config: ci-macos + platform: macos_arm64 + sandbox: false + target: aarch64-apple-darwin + variant: release + - runner: macos-15-xlarge + bazel_config: ci-macos + platform: macos_arm64 sandbox: true target: aarch64-apple-darwin variant: ptrcomp-sandbox - runner: ubuntu-24.04 - producer: bazel bazel_config: ci-v8 platform: linux_amd64_musl sandbox: false target: x86_64-unknown-linux-musl variant: release - runner: ubuntu-24.04-arm - producer: bazel bazel_config: ci-v8 platform: linux_arm64_musl sandbox: false target: aarch64-unknown-linux-musl variant: release - runner: ubuntu-24.04 - producer: bazel bazel_config: ci-v8 platform: linux_amd64_musl sandbox: true target: x86_64-unknown-linux-musl variant: ptrcomp-sandbox - runner: ubuntu-24.04-arm - producer: bazel bazel_config: ci-v8 platform: linux_arm64_musl sandbox: true target: aarch64-unknown-linux-musl variant: ptrcomp-sandbox - - runner: windows-2022 - producer: upstream - sandbox: true - target: x86_64-pc-windows-msvc - variant: ptrcomp-sandbox - - runner: windows-2022 - producer: upstream - sandbox: true - target: aarch64-pc-windows-msvc - variant: ptrcomp-sandbox steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 @@ -128,7 +142,6 @@ jobs: persist-credentials: false - name: Set up Bazel - if: matrix.producer == 'bazel' uses: ./.github/actions/setup-bazel-ci with: target: ${{ matrix.target }} @@ -138,76 +151,12 @@ jobs: with: python-version: "3.12" - - name: Configure git for upstream checkout - if: matrix.producer == 'upstream' - shell: bash - run: git config --global core.symlinks true - - - name: Check out upstream rusty_v8 - if: matrix.producer == 'upstream' - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - with: - repository: denoland/rusty_v8 - ref: v${{ needs.metadata.outputs.v8_version }} - path: upstream-rusty-v8 - submodules: recursive - - - name: Set up upstream Rust toolchain - if: matrix.producer == 'upstream' + - name: Set up Rust toolchain for Cargo smoke uses: dtolnay/rust-toolchain@a0b273b48ed29de4470960879e8381ff45632f26 # 1.93.0 with: - toolchain: "1.91.0" - targets: ${{ matrix.target }} - - - name: Install Clang for upstream Linux build - if: matrix.producer == 'upstream' && runner.os == 'Linux' - shell: bash - run: | - set -euo pipefail - - echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" | sudo tee /etc/apt/sources.list.d/llvm-toolchain-noble-19.list - curl https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/llvm-snapshot.gpg >/dev/null - sudo apt-get update - sudo apt-get install -y lld-19 clang-19 clang-tools-19 clang-tidy-19 clang-format-19 libclang-19-dev - echo "LIBCLANG_PATH=/usr/lib/llvm-19/lib" >> "${GITHUB_ENV}" - - - name: Set LIBCLANG_PATH for upstream macOS build - if: matrix.producer == 'upstream' && runner.os == 'macOS' - shell: bash - run: | - set -euo pipefail - xcode_clang_lib="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib" - echo "LIBCLANG_PATH=${xcode_clang_lib}" >> "${GITHUB_ENV}" - - - name: Install Chromium clang for ARM64 MSVC cross build - if: matrix.producer == 'upstream' && matrix.target == 'aarch64-pc-windows-msvc' - shell: bash - working-directory: upstream-rusty-v8 - run: python3 tools/clang/scripts/update.py - - - name: Build upstream rusty_v8 release pair - if: matrix.producer == 'upstream' - env: - TARGET: ${{ matrix.target }} - shell: bash - working-directory: upstream-rusty-v8 - run: | - set -euo pipefail - - cargo_args=( - build - --locked - --release - --target "${TARGET}" - ) - if [[ "${{ matrix.sandbox }}" == "true" ]]; then - cargo_args+=(--features v8_enable_sandbox) - fi - - V8_FROM_SOURCE=true cargo "${cargo_args[@]}" + toolchain: "1.93.0" - name: Build Bazel V8 release pair - if: matrix.producer == 'bazel' env: BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }} PLATFORM: ${{ matrix.platform }} @@ -229,15 +178,10 @@ jobs: -c opt "--platforms=@llvm//platforms:${PLATFORM}" + --config=rusty-v8-upstream-libcxx "${pair_target}" --build_metadata=COMMIT_SHA=$(git rev-parse HEAD) ) - if [[ "${TARGET}" == *-unknown-linux-* ]]; then - bazel_args+=( - "@llvm//runtimes/libcxx:libcxx.static" - "@llvm//runtimes/libcxx:libcxxabi.static" - ) - fi if [[ "${SANDBOX}" != "true" ]]; then bazel_args+=(--config=v8-release-compat) fi @@ -251,38 +195,64 @@ jobs: - name: Stage release pair env: PLATFORM: ${{ matrix.platform }} - PRODUCER: ${{ matrix.producer }} SANDBOX: ${{ matrix.sandbox }} TARGET: ${{ matrix.target }} shell: bash run: | set -euo pipefail - if [[ "${PRODUCER}" == "upstream" ]]; then - stage_args=( - --source-root upstream-rusty-v8 - --target "${TARGET}" - --output-dir "dist/${TARGET}" - ) - if [[ "${SANDBOX}" == "true" ]]; then - stage_args+=(--sandbox) - fi - python3 .github/scripts/rusty_v8_bazel.py stage-upstream-release-pair "${stage_args[@]}" + stage_args=( + --platform "${PLATFORM}" + --target "${TARGET}" + --compilation-mode opt + --output-dir "dist/${TARGET}" + ) + if [[ "${SANDBOX}" == "true" ]]; then + stage_args+=(--sandbox) else - stage_args=( - --platform "${PLATFORM}" - --target "${TARGET}" - --compilation-mode opt - --output-dir "dist/${TARGET}" - ) - if [[ "${SANDBOX}" == "true" ]]; then - stage_args+=(--sandbox) - else - stage_args+=(--bazel-config v8-release-compat) - fi - python3 .github/scripts/rusty_v8_bazel.py stage-release-pair "${stage_args[@]}" + stage_args+=(--bazel-config v8-release-compat) fi + python3 .github/scripts/rusty_v8_bazel.py stage-release-pair "${stage_args[@]}" + + - name: Smoke test staged artifact with Cargo + env: + SANDBOX: ${{ matrix.sandbox }} + TARGET: ${{ matrix.target }} + shell: bash + run: | + set -euo pipefail + + host_arch="$(uname -m)" + case "${TARGET}:${host_arch}" in + x86_64-apple-darwin:x86_64|aarch64-apple-darwin:arm64|x86_64-unknown-linux-gnu:x86_64|aarch64-unknown-linux-gnu:aarch64) + ;; + *) + echo "Skipping non-native Cargo smoke for ${TARGET} on ${host_arch}." + exit 0 + ;; + esac + + archive="$(find "dist/${TARGET}" -maxdepth 1 -type f -name 'librusty_v8_*.a.gz' -print -quit)" + binding="$(find "dist/${TARGET}" -maxdepth 1 -type f -name 'src_binding_*.rs' -print -quit)" + if [[ -z "${archive}" || -z "${binding}" ]]; then + echo "Missing staged archive or binding for ${TARGET}." >&2 + exit 1 + fi + + cargo_args=(test -p codex-v8-poc) + if [[ "${SANDBOX}" == "true" ]]; then + cargo_args+=(--features sandbox) + fi + + ( + cd codex-rs + CARGO_TARGET_DIR="${RUNNER_TEMP}/rusty-v8-cargo-smoke-${TARGET}-${SANDBOX}" \ + RUSTY_V8_ARCHIVE="${GITHUB_WORKSPACE}/${archive}" \ + RUSTY_V8_SRC_BINDING_PATH="${GITHUB_WORKSPACE}/${binding}" \ + cargo "${cargo_args[@]}" + ) + - name: Upload staged artifacts uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 with: @@ -328,16 +298,13 @@ jobs: # Keep V8 artifact releases out of Codex's normal "latest release" channel. prerelease: true - - name: Amend existing GitHub Release with sandbox artifacts + - name: Amend existing GitHub Release if: ${{ steps.release.outputs.exists == 'true' }} uses: softprops/action-gh-release@153bb8e04406b158c6c84fc1615b65b24149a1fe # v2.6.1 with: tag_name: ${{ needs.metadata.outputs.release_tag }} name: ${{ needs.metadata.outputs.release_tag }} - files: | - dist/**/librusty_v8_ptrcomp_sandbox_release_*.a.gz - dist/**/src_binding_ptrcomp_sandbox_release_*.rs - dist/**/rusty_v8_ptrcomp_sandbox_release_*.sha256 + files: dist/** overwrite_files: true # Keep V8 artifact releases out of Codex's normal "latest release" channel. prerelease: true diff --git a/.github/workflows/v8-canary.yml b/.github/workflows/v8-canary.yml index d3c7c9ea48..315d15e32b 100644 --- a/.github/workflows/v8-canary.yml +++ b/.github/workflows/v8-canary.yml @@ -11,6 +11,7 @@ on: - "MODULE.bazel.lock" - "codex-rs/Cargo.toml" - "patches/BUILD.bazel" + - "patches/rules_cc_*.patch" - "patches/v8_*.patch" - "third_party/v8/**" push: @@ -25,6 +26,7 @@ on: - "MODULE.bazel.lock" - "codex-rs/Cargo.toml" - "patches/BUILD.bazel" + - "patches/rules_cc_*.patch" - "patches/v8_*.patch" - "third_party/v8/**" workflow_dispatch: @@ -59,7 +61,7 @@ jobs: echo "version=${version}" >> "$GITHUB_OUTPUT" build: - name: Build ${{ matrix.target }} + name: Build ${{ matrix.variant }} ${{ matrix.target }} needs: metadata runs-on: ${{ matrix.runner }} permissions: @@ -70,64 +72,77 @@ jobs: matrix: include: - runner: ubuntu-24.04 - producer: upstream + bazel_config: ci-v8 + platform: linux_amd64 + sandbox: false + target: x86_64-unknown-linux-gnu + variant: release + - runner: ubuntu-24.04 + bazel_config: ci-v8 + platform: linux_amd64 sandbox: true target: x86_64-unknown-linux-gnu variant: ptrcomp-sandbox - runner: ubuntu-24.04-arm - producer: upstream + bazel_config: ci-v8 + platform: linux_arm64 + sandbox: false + target: aarch64-unknown-linux-gnu + variant: release + - runner: ubuntu-24.04-arm + bazel_config: ci-v8 + platform: linux_arm64 sandbox: true target: aarch64-unknown-linux-gnu variant: ptrcomp-sandbox - - runner: macos-15-large - producer: upstream + - runner: macos-15-xlarge + bazel_config: ci-macos + platform: macos_amd64 + sandbox: false + target: x86_64-apple-darwin + variant: release + - runner: macos-15-xlarge + bazel_config: ci-macos + platform: macos_amd64 sandbox: true target: x86_64-apple-darwin variant: ptrcomp-sandbox - - runner: macos-15 - producer: upstream + - runner: macos-15-xlarge + bazel_config: ci-macos + platform: macos_arm64 + sandbox: false + target: aarch64-apple-darwin + variant: release + - runner: macos-15-xlarge + bazel_config: ci-macos + platform: macos_arm64 sandbox: true target: aarch64-apple-darwin variant: ptrcomp-sandbox - runner: ubuntu-24.04 - producer: bazel bazel_config: ci-v8 platform: linux_amd64_musl sandbox: false target: x86_64-unknown-linux-musl variant: release - runner: ubuntu-24.04 - producer: bazel bazel_config: ci-v8 platform: linux_amd64_musl sandbox: true target: x86_64-unknown-linux-musl variant: ptrcomp-sandbox - runner: ubuntu-24.04-arm - producer: bazel bazel_config: ci-v8 platform: linux_arm64_musl sandbox: false target: aarch64-unknown-linux-musl variant: release - runner: ubuntu-24.04-arm - producer: bazel bazel_config: ci-v8 platform: linux_arm64_musl sandbox: true target: aarch64-unknown-linux-musl variant: ptrcomp-sandbox - - runner: windows-2022 - producer: upstream - sandbox: true - target: x86_64-pc-windows-msvc - variant: ptrcomp-sandbox - - runner: windows-2022 - producer: upstream - sandbox: true - target: aarch64-pc-windows-msvc - variant: ptrcomp-sandbox - steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: @@ -135,7 +150,6 @@ jobs: persist-credentials: false - name: Set up Bazel - if: matrix.producer == 'bazel' uses: ./.github/actions/setup-bazel-ci with: target: ${{ matrix.target }} @@ -145,76 +159,12 @@ jobs: with: python-version: "3.12" - - name: Configure git for upstream checkout - if: matrix.producer == 'upstream' - shell: bash - run: git config --global core.symlinks true - - - name: Check out upstream rusty_v8 - if: matrix.producer == 'upstream' - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - with: - repository: denoland/rusty_v8 - ref: v${{ needs.metadata.outputs.v8_version }} - path: upstream-rusty-v8 - submodules: recursive - - - name: Set up upstream Rust toolchain - if: matrix.producer == 'upstream' + - name: Set up Rust toolchain for Cargo smoke uses: dtolnay/rust-toolchain@a0b273b48ed29de4470960879e8381ff45632f26 # 1.93.0 with: - toolchain: "1.91.0" - targets: ${{ matrix.target }} - - - name: Install Clang for upstream Linux build - if: matrix.producer == 'upstream' && runner.os == 'Linux' - shell: bash - run: | - set -euo pipefail - - echo "deb http://apt.llvm.org/noble/ llvm-toolchain-noble-19 main" | sudo tee /etc/apt/sources.list.d/llvm-toolchain-noble-19.list - curl https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/llvm-snapshot.gpg >/dev/null - sudo apt-get update - sudo apt-get install -y lld-19 clang-19 clang-tools-19 clang-tidy-19 clang-format-19 libclang-19-dev - echo "LIBCLANG_PATH=/usr/lib/llvm-19/lib" >> "${GITHUB_ENV}" - - - name: Set LIBCLANG_PATH for upstream macOS build - if: matrix.producer == 'upstream' && runner.os == 'macOS' - shell: bash - run: | - set -euo pipefail - xcode_clang_lib="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib" - echo "LIBCLANG_PATH=${xcode_clang_lib}" >> "${GITHUB_ENV}" - - - name: Install Chromium clang for ARM64 MSVC cross build - if: matrix.producer == 'upstream' && matrix.target == 'aarch64-pc-windows-msvc' - shell: bash - working-directory: upstream-rusty-v8 - run: python3 tools/clang/scripts/update.py - - - name: Build upstream rusty_v8 release pair - if: matrix.producer == 'upstream' - env: - TARGET: ${{ matrix.target }} - shell: bash - working-directory: upstream-rusty-v8 - run: | - set -euo pipefail - - cargo_args=( - build - --locked - --release - --target "${TARGET}" - ) - if [[ "${{ matrix.sandbox }}" == "true" ]]; then - cargo_args+=(--features v8_enable_sandbox) - fi - - V8_FROM_SOURCE=true cargo "${cargo_args[@]}" + toolchain: "1.93.0" - name: Build Bazel V8 release pair - if: matrix.producer == 'bazel' env: BUILDBUDDY_API_KEY: ${{ secrets.BUILDBUDDY_API_KEY }} PLATFORM: ${{ matrix.platform }} @@ -234,15 +184,10 @@ jobs: bazel_args=( build "--platforms=@llvm//platforms:${PLATFORM}" + --config=rusty-v8-upstream-libcxx "${pair_target}" --build_metadata=COMMIT_SHA=$(git rev-parse HEAD) ) - if [[ "${TARGET}" == *-unknown-linux-* ]]; then - bazel_args+=( - "@llvm//runtimes/libcxx:libcxx.static" - "@llvm//runtimes/libcxx:libcxxabi.static" - ) - fi if [[ "${SANDBOX}" != "true" ]]; then bazel_args+=(--config=v8-release-compat) fi @@ -256,37 +201,63 @@ jobs: - name: Stage release pair env: PLATFORM: ${{ matrix.platform }} - PRODUCER: ${{ matrix.producer }} SANDBOX: ${{ matrix.sandbox }} TARGET: ${{ matrix.target }} shell: bash run: | set -euo pipefail - if [[ "${PRODUCER}" == "upstream" ]]; then - stage_args=( - --source-root upstream-rusty-v8 - --target "${TARGET}" - --output-dir "dist/${TARGET}" - ) - if [[ "${SANDBOX}" == "true" ]]; then - stage_args+=(--sandbox) - fi - python3 .github/scripts/rusty_v8_bazel.py stage-upstream-release-pair "${stage_args[@]}" + stage_args=( + --platform "${PLATFORM}" + --target "${TARGET}" + --output-dir "dist/${TARGET}" + ) + if [[ "${SANDBOX}" == "true" ]]; then + stage_args+=(--sandbox) else - stage_args=( - --platform "${PLATFORM}" - --target "${TARGET}" - --output-dir "dist/${TARGET}" - ) - if [[ "${SANDBOX}" == "true" ]]; then - stage_args+=(--sandbox) - else - stage_args+=(--bazel-config v8-release-compat) - fi - python3 .github/scripts/rusty_v8_bazel.py stage-release-pair "${stage_args[@]}" + stage_args+=(--bazel-config v8-release-compat) fi + python3 .github/scripts/rusty_v8_bazel.py stage-release-pair "${stage_args[@]}" + + - name: Smoke test staged artifact with Cargo + env: + SANDBOX: ${{ matrix.sandbox }} + TARGET: ${{ matrix.target }} + shell: bash + run: | + set -euo pipefail + + host_arch="$(uname -m)" + case "${TARGET}:${host_arch}" in + x86_64-apple-darwin:x86_64|aarch64-apple-darwin:arm64|x86_64-unknown-linux-gnu:x86_64|aarch64-unknown-linux-gnu:aarch64) + ;; + *) + echo "Skipping non-native Cargo smoke for ${TARGET} on ${host_arch}." + exit 0 + ;; + esac + + archive="$(find "dist/${TARGET}" -maxdepth 1 -type f -name 'librusty_v8_*.a.gz' -print -quit)" + binding="$(find "dist/${TARGET}" -maxdepth 1 -type f -name 'src_binding_*.rs' -print -quit)" + if [[ -z "${archive}" || -z "${binding}" ]]; then + echo "Missing staged archive or binding for ${TARGET}." >&2 + exit 1 + fi + + cargo_args=(test -p codex-v8-poc) + if [[ "${SANDBOX}" == "true" ]]; then + cargo_args+=(--features sandbox) + fi + + ( + cd codex-rs + CARGO_TARGET_DIR="${RUNNER_TEMP}/rusty-v8-cargo-smoke-${TARGET}-${SANDBOX}" \ + RUSTY_V8_ARCHIVE="${GITHUB_WORKSPACE}/${archive}" \ + RUSTY_V8_SRC_BINDING_PATH="${GITHUB_WORKSPACE}/${binding}" \ + cargo "${cargo_args[@]}" + ) + - name: Upload staged artifacts uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 with: diff --git a/MODULE.bazel b/MODULE.bazel index 6aa9925fc7..dac8ded4ff 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -77,6 +77,13 @@ use_repo(osx, "macos_sdk") # Needed to disable xcode... bazel_dep(name = "apple_support", version = "2.1.0") bazel_dep(name = "rules_cc", version = "0.2.16") +single_version_override( + module_name = "rules_cc", + patch_strip = 1, + patches = [ + "//patches:rules_cc_rusty_v8_custom_libcxx.patch", + ], +) bazel_dep(name = "rules_platform", version = "0.1.0") bazel_dep(name = "rules_rs", version = "0.0.58") # `rules_rs` still does not model `windows-gnullvm` as a distinct Windows exec @@ -439,6 +446,29 @@ http_archive( urls = ["https://static.crates.io/crates/v8/v8-147.4.0.crate"], ) +git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "rusty_v8_libcxx", + build_file = "//third_party/v8:libcxx.BUILD.bazel", + commit = "7ab65651aed6802d2599dcb7a73b1f82d5179d05", + remote = "https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxx.git", +) + +git_repository( + name = "rusty_v8_libcxxabi", + build_file = "//third_party/v8:libcxxabi.BUILD.bazel", + commit = "8f11bb1d4438d0239d0dfc1bd9456a9f31629dda", + remote = "https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libcxxabi.git", +) + +git_repository( + name = "rusty_v8_llvm_libc", + build_file = "//third_party/v8:llvm_libc.BUILD.bazel", + commit = "b3aa5bb702ff9e890179fd1e7d3ba346e17ecf8e", + remote = "https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libc.git", +) + http_file( name = "rusty_v8_146_4_0_aarch64_apple_darwin_archive", downloaded_file_path = "librusty_v8_release_aarch64-apple-darwin.a.gz", diff --git a/patches/BUILD.bazel b/patches/BUILD.bazel index b58292c727..3a5345de0f 100644 --- a/patches/BUILD.bazel +++ b/patches/BUILD.bazel @@ -12,6 +12,7 @@ exports_files([ "rules_rust_windows_process_wrapper_skip_temp_outputs.patch", "rules_rust_windows_msvc_direct_link_args.patch", "rules_rust_windows_gnullvm_build_script.patch", + "rules_cc_rusty_v8_custom_libcxx.patch", "rules_rs_windows_gnullvm_exec.patch", "rules_rs_windows_exec_linker.patch", "rusty_v8_prebuilt_out_dir.patch", diff --git a/patches/rules_cc_rusty_v8_custom_libcxx.patch b/patches/rules_cc_rusty_v8_custom_libcxx.patch new file mode 100644 index 0000000000..1e4e7d9d53 --- /dev/null +++ b/patches/rules_cc_rusty_v8_custom_libcxx.patch @@ -0,0 +1,35 @@ +diff --git a/cc/cc_library.bzl b/cc/cc_library.bzl +--- a/cc/cc_library.bzl ++++ b/cc/cc_library.bzl +@@ -16,4 +16,31 @@ + load("@cc_compatibility_proxy//:proxy.bzl", _cc_library = "cc_library") + ++_RUSTY_V8_CUSTOM_LIBCXX_COPTS = select({ ++ "@@//third_party/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": [], ++}) ++ ++_RUSTY_V8_CUSTOM_LIBCXX_DEPS = select({ ++ "@@//third_party/v8:use_rusty_v8_custom_libcxx": [ ++ "@@//third_party/v8:rusty_v8_custom_libcxx_headers", ++ ], ++ "//conditions:default": [], ++}) ++ ++def _should_use_rusty_v8_custom_libcxx(): ++ # V8 and ICU are patched in-tree. Abseil is the only external dependency ++ # that still exchanges STL types with the artifact objects. ++ return native.repository_name() == "@abseil-cpp+" ++ + def cc_library(**kwargs): ++ if _should_use_rusty_v8_custom_libcxx(): ++ kwargs["copts"] = (kwargs.get("copts", []) or []) + _RUSTY_V8_CUSTOM_LIBCXX_COPTS ++ kwargs["deps"] = (kwargs.get("deps", []) or []) + _RUSTY_V8_CUSTOM_LIBCXX_DEPS ++ kwargs["features"] = (kwargs.get("features", []) or []) + ["-module_maps"] + _cc_library(**kwargs) diff --git a/patches/v8_bazel_rules.patch b/patches/v8_bazel_rules.patch index 70ab440d85..71265b32ae 100644 --- a/patches/v8_bazel_rules.patch +++ b/patches/v8_bazel_rules.patch @@ -7,16 +7,47 @@ diff --git a/orig/v8-14.6.202.11/bazel/defs.bzl b/mod/v8-14.6.202.11/bazel/defs. index 9648e4a..88efd41 100644 --- a/orig/v8-14.6.202.11/bazel/defs.bzl +++ b/mod/v8-14.6.202.11/bazel/defs.bzl -@@ -97,7 +97,7 @@ v8_config = rule( +@@ -33,9 +33,21 @@ + ) + + def v8_flag(name, default = False): +- _create_option_flag(name = name, build_setting_default = default) +- native.config_setting(name = "is_" + name, flag_values = {name: "True"}) +- native.config_setting(name = "is_not_" + name, flag_values = {name: "False"}) ++ _create_option_flag( ++ name = name, ++ build_setting_default = default, ++ 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 = ""): + _create_option_string(name = name, build_setting_default = default) +@@ -97,7 +109,13 @@ def _default_args(): return struct( - deps = [":define_flags", "@libcxx//:libc++"], -+ deps = [":define_flags"], ++ 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", -@@ -128,12 +128,6 @@ def _default_args(): +@@ -127,12 +145,15 @@ ], "//conditions:default": [], }) + select({ @@ -26,20 +57,29 @@ index 9648e4a..88efd41 100644 - "-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", -@@ -155,7 +149,15 @@ def _default_args(): -- "@v8//bazel/config:is_windows": [ +@@ -152,9 +173,17 @@ + "-std=gnu++2a", + ], + "@v8//bazel/config:is_windows": [ - "/std:c++20", -- ], -- "//conditions:default": [], -+ "@v8//bazel/config:is_windows": [ + "-Wno-invalid-offsetof", + "-Wno-deprecated-this-capture", + "-Wno-deprecated-declarations", + "-std=c++20", -+ ], + ], +- "//conditions:default": [], + "//conditions:default": [ + "-Wno-invalid-offsetof", + "-Wno-deprecated-this-capture", @@ -49,7 +89,9 @@ index 9648e4a..88efd41 100644 }) + select({ "@v8//bazel/config:is_gcc_fastbuild": [ # Non-debug builds without optimizations fail because -@@ -180,10 +179,10 @@ def _default_args(): +@@ -178,12 +207,12 @@ + includes = ["include"], + linkopts = select({ "@v8//bazel/config:is_windows": [ - "Winmm.lib", - "DbgHelp.lib", @@ -65,19 +107,21 @@ index 9648e4a..88efd41 100644 ":should_add_rdynamic": ["-rdynamic"], "//conditions:default": [], diff --git a/orig/v8-14.6.202.11/BUILD.bazel b/mod/v8-14.6.202.11/BUILD.bazel -index 85f31b7..bbc351b 100644 +index 421ebcd..52283ea 100644 --- a/orig/v8-14.6.202.11/BUILD.bazel +++ b/mod/v8-14.6.202.11/BUILD.bazel -@@ -148,6 +148,8 @@ v8_flag(name = "v8_enable_trace_maps") +@@ -148,6 +148,10 @@ v8_flag(name = "v8_enable_trace_maps") 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") -@@ -303,7 +305,7 @@ v8_int( +@@ -313,7 +317,7 @@ v8_int( # If no explicit value for v8_enable_pointer_compression, we set it to 'none'. v8_string( name = "v8_enable_pointer_compression", @@ -86,7 +130,7 @@ index 85f31b7..bbc351b 100644 ) # Default setting for v8_enable_pointer_compression. -@@ -503,6 +505,7 @@ v8_config( +@@ -513,6 +517,7 @@ v8_config( "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", @@ -94,7 +138,7 @@ index 85f31b7..bbc351b 100644 "v8_enable_trace_maps": "V8_TRACE_MAPS", "v8_enable_turbofan": "V8_ENABLE_TURBOFAN", "v8_enable_v8_checks": "V8_ENABLE_CHECKS", -@@ -4077,28 +4080,14 @@ filegroup( +@@ -4098,28 +4103,14 @@ filegroup( }), ) @@ -129,7 +173,7 @@ index 85f31b7..bbc351b 100644 ) filegroup( -@@ -4405,6 +4394,20 @@ genrule( +@@ -4422,6 +4413,20 @@ genrule( srcs = [ "include/js_protocol.pdl", "src/inspector/inspector_protocol_config.json", @@ -150,7 +194,7 @@ index 85f31b7..bbc351b 100644 ], outs = [ "include/inspector/Debugger.h", -@@ -4426,15 +4429,19 @@ genrule( +@@ -4443,15 +4448,19 @@ genrule( "src/inspector/protocol/Schema.cpp", "src/inspector/protocol/Schema.h", ], @@ -174,7 +218,7 @@ index 85f31b7..bbc351b 100644 ], ) -@@ -4448,6 +4455,15 @@ filegroup( +@@ -4465,6 +4474,15 @@ filegroup( ], ) @@ -190,7 +234,7 @@ index 85f31b7..bbc351b 100644 filegroup( name = "d8_files", srcs = [ -@@ -4567,16 +4583,9 @@ cc_library( +@@ -4584,16 +4602,9 @@ cc_library( ], ) @@ -210,7 +254,7 @@ index 85f31b7..bbc351b 100644 ) v8_library( -@@ -4593,7 +4602,7 @@ v8_library( +@@ -4610,7 +4621,7 @@ v8_library( copts = ["-Wno-implicit-fallthrough"], icu_deps = [ ":icu/generated_torque_definitions_headers", @@ -219,7 +263,7 @@ index 85f31b7..bbc351b 100644 ], icu_srcs = [ ":generated_regexp_special_case", -@@ -4608,7 +4617,7 @@ v8_library( +@@ -4625,7 +4636,7 @@ v8_library( ], deps = [ ":lib_dragonbox", @@ -228,7 +272,7 @@ index 85f31b7..bbc351b 100644 ":lib_fp16", ":simdutf", ":v8_libbase", -@@ -4664,6 +4673,7 @@ alias( +@@ -4681,6 +4692,7 @@ alias( alias( name = "core_lib_icu", actual = "icu/v8", @@ -236,7 +280,7 @@ index 85f31b7..bbc351b 100644 ) v8_library( -@@ -4715,7 +4725,7 @@ v8_binary( +@@ -4732,7 +4744,7 @@ v8_binary( ], deps = [ ":v8_libbase", @@ -245,17 +289,53 @@ index 85f31b7..bbc351b 100644 ], ) +@@ -4772,9 +4784,15 @@ v8_binary( + ":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. + linkopts = select({ + "@v8//bazel/config:is_android": ["-llog"], +- "//conditions:default": [], ++ "@v8//bazel/config:is_macos": ["-Wl,-no_deduplicate"], ++ "@v8//bazel/config:is_windows": ["/OPT:NOICF"], ++ "//conditions:default": ["-Wl,--icf=none"], + }), + noicu_deps = [":v8_libshared_noicu"], + noicu_srcs = [ diff --git a/orig/v8-14.6.202.11/bazel/BUILD.icu b/mod/v8-14.6.202.11/bazel/BUILD.icu -index 5fda2f4..381386c 100644 +index 5fda2f4..9729451 100644 --- a/orig/v8-14.6.202.11/bazel/BUILD.icu +++ b/mod/v8-14.6.202.11/bazel/BUILD.icu -@@ -1,3 +1,5 @@ +@@ -1,3 +1,24 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") ++ ++CUSTOM_LIBCXX_COPTS = select({ ++ "@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": [], ++}) ++ ++CUSTOM_LIBCXX_DEPS = 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": [], ++}) + # 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. -@@ -16,10 +18,7 @@ cc_library( +@@ -16,15 +37,12 @@ ]), copts = select({ "@platforms//os:windows": [ @@ -267,7 +347,21 @@ index 5fda2f4..381386c 100644 ], "//conditions:default": [ "-Wno-deprecated-declarations", -@@ -65,10 +64,7 @@ cc_library( + ], +- }), ++ }) + CUSTOM_LIBCXX_COPTS, + data = [":icudata"], + defines = [ + "HAVE_DLOPEN=0", +@@ -54,6 +72,7 @@ + "U_ICUDATAENTRY_IN_COMMON", + ], + tags = ["requires-rtti"], ++ deps = CUSTOM_LIBCXX_DEPS, + alwayslink = 1, + ) + +@@ -65,19 +84,16 @@ ]), copts = select({ "@platforms//os:windows": [ @@ -279,7 +373,18 @@ index 5fda2f4..381386c 100644 ], "//conditions:default": [ "-Wno-deprecated-declarations", -@@ -93,10 +89,7 @@ cc_library( + ], +- }), ++ }) + CUSTOM_LIBCXX_COPTS, + local_defines = [ + "U_I18N_IMPLEMENTATION", + ], +- deps = [":icuuc"], ++ deps = [":icuuc"] + CUSTOM_LIBCXX_DEPS, + alwayslink = 1, + ) + +@@ -93,13 +109,10 @@ ]), copts = select({ "@platforms//os:windows": [ @@ -290,4 +395,16 @@ index 5fda2f4..381386c 100644 + "-Wno-deprecated-declarations", ], "//conditions:default": [], - }), +- }), ++ }) + CUSTOM_LIBCXX_COPTS, + include_prefix = "third_party/icu", + local_defines = [ + "U_COMMON_IMPLEMENTATION", +@@ -108,6 +121,6 @@ + deps = [ + ":icui18n", + ":icuuc", +- ], ++ ] + CUSTOM_LIBCXX_DEPS, + alwayslink = 1, + ) diff --git a/third_party/v8/BUILD.bazel b/third_party/v8/BUILD.bazel index f122433f73..9d26188348 100644 --- a/third_party/v8/BUILD.bazel +++ b/third_party/v8/BUILD.bazel @@ -22,6 +22,13 @@ config_setting( ], ) +config_setting( + name = "use_rusty_v8_custom_libcxx", + flag_values = { + "@v8//:v8_use_rusty_v8_custom_libcxx": "True", + }, +) + alias( name = "v8_146_4_0_x86_64_apple_darwin", actual = "@rusty_v8_146_4_0_x86_64_apple_darwin_archive//file", @@ -165,11 +172,40 @@ alias( V8_COPTS = ["-std=c++20"] +V8_CUSTOM_LIBCXX_COPTS = select({ + ":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": [], +}) + V8_STATIC_LIBRARY_FEATURES = [ "-symbol_check", "-validate-static-library", ] +cc_library( + name = "rusty_v8_custom_libcxx_headers", + deps = [ + "@rusty_v8_libcxx//:headers", + "@rusty_v8_libcxxabi//:headers", + ], + visibility = ["//visibility:public"], +) + +cc_library( + name = "rusty_v8_custom_libcxx_runtime", + deps = [ + "@rusty_v8_libcxx//:libcxx", + "@rusty_v8_libcxxabi//:libcxxabi", + ], + visibility = ["//visibility:public"], +) + genrule( name = "binding_cc", srcs = ["@v8_crate_146_4_0//:binding_cc"], @@ -239,11 +275,16 @@ cc_library( name = "v8_147_4_0_binding", srcs = [":binding_cc_147_4_0"], hdrs = [":support_h_147_4_0"], - copts = V8_COPTS, + copts = V8_COPTS + V8_CUSTOM_LIBCXX_COPTS, deps = [ "@v8//:core_lib_icu", "@v8//:rusty_v8_internal_headers", - ], + ] + select({ + ":use_rusty_v8_custom_libcxx": [ + ":rusty_v8_custom_libcxx_headers", + ], + "//conditions:default": [], + }), ) cc_static_library( @@ -330,19 +371,28 @@ filegroup( cc_static_library( name = "v8_147_4_0_aarch64_apple_darwin_bazel", - deps = [":v8_147_4_0_binding"], + deps = [ + ":rusty_v8_custom_libcxx_runtime", + ":v8_147_4_0_binding", + ], features = V8_STATIC_LIBRARY_FEATURES, ) cc_static_library( name = "v8_147_4_0_aarch64_unknown_linux_gnu_bazel", - deps = [":v8_147_4_0_binding"], + deps = [ + ":rusty_v8_custom_libcxx_runtime", + ":v8_147_4_0_binding", + ], features = V8_STATIC_LIBRARY_FEATURES, ) cc_static_library( name = "v8_147_4_0_aarch64_unknown_linux_musl_release_base", - deps = [":v8_147_4_0_binding"], + deps = [ + ":rusty_v8_custom_libcxx_runtime", + ":v8_147_4_0_binding", + ], features = V8_STATIC_LIBRARY_FEATURES, ) @@ -372,31 +422,28 @@ EOF cc_static_library( name = "v8_147_4_0_x86_64_apple_darwin_bazel", - deps = [":v8_147_4_0_binding"], + deps = [ + ":rusty_v8_custom_libcxx_runtime", + ":v8_147_4_0_binding", + ], features = V8_STATIC_LIBRARY_FEATURES, ) cc_static_library( name = "v8_147_4_0_x86_64_unknown_linux_gnu_bazel", - deps = [":v8_147_4_0_binding"], + deps = [ + ":rusty_v8_custom_libcxx_runtime", + ":v8_147_4_0_binding", + ], features = V8_STATIC_LIBRARY_FEATURES, ) cc_static_library( name = "v8_147_4_0_x86_64_unknown_linux_musl_release", - deps = [":v8_147_4_0_binding"], - features = V8_STATIC_LIBRARY_FEATURES, -) - -cc_static_library( - name = "v8_147_4_0_aarch64_pc_windows_msvc_bazel", - deps = [":v8_147_4_0_binding"], - features = V8_STATIC_LIBRARY_FEATURES, -) - -cc_static_library( - name = "v8_147_4_0_x86_64_pc_windows_msvc_bazel", - deps = [":v8_147_4_0_binding"], + deps = [ + ":rusty_v8_custom_libcxx_runtime", + ":v8_147_4_0_binding", + ], features = V8_STATIC_LIBRARY_FEATURES, ) @@ -443,32 +490,32 @@ filegroup( filegroup( name = "rusty_v8_release_pair_x86_64_apple_darwin", srcs = [ - ":v8_146_4_0_x86_64_apple_darwin", - ":src_binding_release_x86_64_apple_darwin", + ":v8_147_4_0_x86_64_apple_darwin_bazel", + ":src_binding_release_x86_64_apple_darwin_147_4_0_release", ], ) filegroup( name = "rusty_v8_release_pair_aarch64_apple_darwin", srcs = [ - ":v8_146_4_0_aarch64_apple_darwin", - ":src_binding_release_aarch64_apple_darwin", + ":v8_147_4_0_aarch64_apple_darwin_bazel", + ":src_binding_release_aarch64_apple_darwin_147_4_0_release", ], ) filegroup( name = "rusty_v8_release_pair_x86_64_unknown_linux_gnu", srcs = [ - ":v8_146_4_0_x86_64_unknown_linux_gnu", - ":src_binding_release_x86_64_unknown_linux_gnu", + ":v8_147_4_0_x86_64_unknown_linux_gnu_bazel", + ":src_binding_release_x86_64_unknown_linux_gnu_147_4_0_release", ], ) filegroup( name = "rusty_v8_release_pair_aarch64_unknown_linux_gnu", srcs = [ - ":v8_146_4_0_aarch64_unknown_linux_gnu", - ":src_binding_release_aarch64_unknown_linux_gnu", + ":v8_147_4_0_aarch64_unknown_linux_gnu_bazel", + ":src_binding_release_aarch64_unknown_linux_gnu_147_4_0_release", ], ) @@ -551,19 +598,3 @@ filegroup( ":src_binding_release_aarch64_unknown_linux_musl_147_4_0_release", ], ) - -filegroup( - name = "rusty_v8_sandbox_release_pair_x86_64_pc_windows_msvc", - srcs = [ - ":v8_147_4_0_x86_64_pc_windows_msvc_bazel", - ":src_binding_release_x86_64_pc_windows_msvc_147_4_0_release", - ], -) - -filegroup( - name = "rusty_v8_sandbox_release_pair_aarch64_pc_windows_msvc", - srcs = [ - ":v8_147_4_0_aarch64_pc_windows_msvc_bazel", - ":src_binding_release_aarch64_pc_windows_msvc_147_4_0_release", - ], -) diff --git a/third_party/v8/README.md b/third_party/v8/README.md index 2d15a1b3dc..dc38cdc5da 100644 --- a/third_party/v8/README.md +++ b/third_party/v8/README.md @@ -21,7 +21,7 @@ artifact contract. Current pinned versions: - Rust crate: `v8 = =147.4.0` -- Embedded upstream V8 source for musl release builds: `14.7.173.20` +- Embedded upstream V8 source for Bazel-produced release builds: `14.7.173.20` When bumping the Rust crate version, keep the checked-in checksum manifest and `MODULE.bazel` in sync: @@ -40,7 +40,7 @@ The consumer-facing selectors are: - `//third_party/v8:rusty_v8_archive_for_target` - `//third_party/v8:rusty_v8_binding_for_target` -Current musl release assets are expected at the tag: +Published release assets are expected at the tag: - `rusty-v8-v` @@ -57,12 +57,12 @@ their raw names: - `src_binding_ptrcomp_sandbox_release_.rs` The dedicated publishing workflow is `.github/workflows/rusty-v8-release.yml`. -For GNU Linux, Darwin, and Windows MSVC, the workflow checks out the exact -upstream `denoland/rusty_v8` tag and uses its `V8_FROM_SOURCE=true` Cargo/GN -build to produce sandbox-profile artifacts with the same archive shape upstream -publishes. Musl remains an extra platform that upstream does not publish, so -tagged runs still build the current musl release pairs with our Bazel producer: +Tagged runs build release artifacts from the Bazel graph itself: +- `//third_party/v8:rusty_v8_release_pair_x86_64_apple_darwin` +- `//third_party/v8:rusty_v8_release_pair_aarch64_apple_darwin` +- `//third_party/v8:rusty_v8_release_pair_x86_64_unknown_linux_gnu` +- `//third_party/v8:rusty_v8_release_pair_aarch64_unknown_linux_gnu` - `//third_party/v8:rusty_v8_release_pair_x86_64_unknown_linux_musl` - `//third_party/v8:rusty_v8_release_pair_aarch64_unknown_linux_musl` @@ -74,16 +74,19 @@ The same run also builds the matching sandbox pair targets: - `//third_party/v8:rusty_v8_sandbox_release_pair_aarch64_unknown_linux_gnu` - `//third_party/v8:rusty_v8_sandbox_release_pair_x86_64_unknown_linux_musl` - `//third_party/v8:rusty_v8_sandbox_release_pair_aarch64_unknown_linux_musl` -- `//third_party/v8:rusty_v8_sandbox_release_pair_x86_64_pc_windows_msvc` -- `//third_party/v8:rusty_v8_sandbox_release_pair_aarch64_pc_windows_msvc` -If a tagged run targets an existing GitHub release, publication amends only the -sandbox-profile files and leaves the current release-profile assets unchanged. -The upstream-shaped GNU, Darwin, and MSVC builds let GN fold custom libc++ into -the final archive the same way `rusty_v8` does for its own releases. Musl -sandbox archives still merge the matching static libc++ and libc++abi runtime -libraries after the Bazel build so Cargo consumers can link them with the `v8` -crate's default `use_custom_libcxx` feature. +The Bazel graph pins the same libc++, libc++abi, and llvm-libc source revisions +used by `rusty_v8 v147.4.0`, compiles published artifact targets with +`--config=rusty-v8-upstream-libcxx`, and folds the matching runtime objects into +the final static archive so Cargo consumers can link it with the `v8` crate's +default `use_custom_libcxx` feature. The config keeps the object files and the +bundled runtime on Chromium's `std::__Cr` ABI namespace instead of mixing those +objects with the toolchain libc++ default namespace. + +MSVC is not part of the Bazel-produced matrix yet. The repository's current +hermetic Windows C++ platform is `windows-gnullvm`/`x86_64-w64-windows-gnu`, so +it cannot truthfully reproduce upstream's `*-pc-windows-msvc` archives until we +add a real MSVC-targeting C++ toolchain to the Bazel graph. Cargo musl builds use `RUSTY_V8_ARCHIVE` plus a downloaded `RUSTY_V8_SRC_BINDING_PATH` to point at those `openai/codex` release assets diff --git a/third_party/v8/libcxx.BUILD.bazel b/third_party/v8/libcxx.BUILD.bazel new file mode 100644 index 0000000000..5550cfd0a2 --- /dev/null +++ b/third_party/v8/libcxx.BUILD.bazel @@ -0,0 +1,157 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@llvm//toolchain/runtimes:cc_runtime_library.bzl", "cc_runtime_stage0_library") + +package(default_visibility = ["//visibility:public"]) + +config_setting( + name = "is_linux", + constraint_values = ["@platforms//os:linux"], +) + +config_setting( + name = "is_windows", + constraint_values = ["@platforms//os:windows"], +) + +LIBCXX_SRCS = [ + "src/algorithm.cpp", + "src/any.cpp", + "src/atomic.cpp", + "src/barrier.cpp", + "src/bind.cpp", + "src/call_once.cpp", + "src/charconv.cpp", + "src/chrono.cpp", + "src/condition_variable.cpp", + "src/condition_variable_destructor.cpp", + "src/error_category.cpp", + "src/exception.cpp", + "src/filesystem/directory_iterator.cpp", + "src/filesystem/filesystem_error.cpp", + "src/filesystem/operations.cpp", + "src/filesystem/path.cpp", + "src/functional.cpp", + "src/future.cpp", + "src/hash.cpp", + "src/ios.cpp", + "src/ios.instantiations.cpp", + "src/iostream.cpp", + "src/locale.cpp", + "src/memory.cpp", + "src/mutex.cpp", + "src/mutex_destructor.cpp", + "src/new.cpp", + "src/new_handler.cpp", + "src/new_helpers.cpp", + "src/optional.cpp", + "src/random.cpp", + "src/random_shuffle.cpp", + "src/regex.cpp", + "src/ryu/d2fixed.cpp", + "src/ryu/d2s.cpp", + "src/ryu/f2s.cpp", + "src/shared_mutex.cpp", + "src/stdexcept.cpp", + "src/string.cpp", + "src/strstream.cpp", + "src/system_error.cpp", + "src/thread.cpp", + "src/typeinfo.cpp", + "src/valarray.cpp", + "src/variant.cpp", + "src/vector.cpp", + "src/verbose_abort.cpp", +] + +cc_library( + name = "headers", + hdrs = glob(["include/**"]), + includes = ["include"], + deps = ["@//third_party/v8/libcxx_config:headers"], +) + +cc_library( + name = "internal_headers", + hdrs = glob([ + "src/**/*.h", + "src/**/*.ipp", + ]), + includes = ["src"], +) + +cc_runtime_stage0_library( + name = "libcxx", + srcs = LIBCXX_SRCS + select({ + ":is_linux": [ + "src/filesystem/directory_entry.cpp", + "src/filesystem/filesystem_clock.cpp", + ], + "//conditions:default": [], + }) + select({ + ":is_windows": [ + "src/support/win32/locale_win32.cpp", + "src/support/win32/support.cpp", + "src/support/win32/thread_win32.cpp", + ], + "//conditions:default": [], + }), + copts = [ + "-fexceptions", + "-frtti", + "-fstrict-aliasing", + "-fvisibility=hidden", + "-fvisibility-inlines-hidden", + "-nostdinc++", + "-std=c++23", + "-Wno-nullability-completeness", + "-Wno-unused-parameter", + "-Wundef", + ] + select({ + ":is_windows": ["-Wno-macro-redefined"], + "//conditions:default": ["-fPIC"], + }), + defines = [ + "CR_LIBCXX_REVISION=7ab65651aed6802d2599dcb7a73b1f82d5179d05", + "LIBCXX_BUILDING_LIBCXXABI", + "LIBC_NAMESPACE=__llvm_libc_cr", + "_LIBCPP_BUILDING_LIBRARY", + "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS", + "_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE", + "_LIBCPP_INSTRUMENTED_WITH_ASAN=0", + "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS", + ] + select({ + "@llvm//platforms/config:musl": [ + # Chromium's checked-in __config_site uses this switch to enable + # libc++'s musl-specific configuration. + "ANDROID_HOST_MUSL", + ], + "//conditions:default": [], + }) + select({ + ":is_windows": [ + "NTDDI_VERSION=NTDDI_WIN7", + "WINVER=_WIN32_WINNT_WIN7", + "_WIN32_WINNT=_WIN32_WINNT_WIN7", + ], + "//conditions:default": [], + }), + includes = ["src"], + implementation_deps = [ + ":headers", + ":internal_headers", + "@rusty_v8_libcxxabi//:headers", + "@rusty_v8_llvm_libc//:headers", + ] + select({ + ":is_linux": [ + "@@llvm++kernel_headers+kernel_headers//:kernel_headers", + ], + "//conditions:default": [], + }) + select({ + "@llvm//platforms/config:gnu": [ + "@@llvm++glibc+glibc//:gnu_libc_headers", + ], + "@llvm//platforms/config:musl": [ + "@@llvm++musl+musl_libc//:musl_libc_headers", + ], + "//conditions:default": [], + }), +) diff --git a/third_party/v8/libcxx_config/BUILD.bazel b/third_party/v8/libcxx_config/BUILD.bazel new file mode 100644 index 0000000000..e4a3ee6a85 --- /dev/null +++ b/third_party/v8/libcxx_config/BUILD.bazel @@ -0,0 +1,12 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "headers", + hdrs = [ + "__assertion_handler", + "__config_site", + ], + includes = ["."], +) diff --git a/third_party/v8/libcxx_config/__assertion_handler b/third_party/v8/libcxx_config/__assertion_handler new file mode 100644 index 0000000000..1d1c2c98f2 --- /dev/null +++ b/third_party/v8/libcxx_config/__assertion_handler @@ -0,0 +1,27 @@ +// -*- C++ -*- + +#ifndef _LIBCPP___ASSERTION_HANDLER +#define _LIBCPP___ASSERTION_HANDLER + +#include <__config> +#include <__verbose_abort> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#if defined(OFFICIAL_BUILD) && !defined(DCHECK_ALWAYS_ON) + +[[noreturn]] inline _LIBCPP_HIDE_FROM_ABI void __libcpp_hardening_failure() { + __builtin_trap(); +} + +#define _LIBCPP_ASSERTION_HANDLER(message) ((void)message, __libcpp_hardening_failure()) + +#else + +#define _LIBCPP_ASSERTION_HANDLER(message) _LIBCPP_VERBOSE_ABORT("%s", message) + +#endif + +#endif // _LIBCPP___ASSERTION_HANDLER diff --git a/third_party/v8/libcxx_config/__config_site b/third_party/v8/libcxx_config/__config_site new file mode 100644 index 0000000000..1053f9fe45 --- /dev/null +++ b/third_party/v8/libcxx_config/__config_site @@ -0,0 +1,55 @@ +#ifndef _LIBCPP_CONFIG_SITE +#define _LIBCPP_CONFIG_SITE + +#define _LIBCPP_ABI_NAMESPACE __Cr +#define _LIBCPP_ABI_VERSION 2 + +#define _LIBCPP_ABI_FORCE_ITANIUM 0 +#define _LIBCPP_ABI_FORCE_MICROSOFT 0 +#define _LIBCPP_HAS_THREADS 1 +#define _LIBCPP_HAS_MONOTONIC_CLOCK 1 +#define _LIBCPP_HAS_TERMINAL 1 + +#ifdef ANDROID_HOST_MUSL +#define _LIBCPP_HAS_MUSL_LIBC 1 +#else +#define _LIBCPP_HAS_MUSL_LIBC 0 +#endif + +#ifdef _WIN32 +#define _LIBCPP_HAS_THREAD_API_PTHREAD 0 +#define _LIBCPP_HAS_THREAD_API_EXTERNAL 0 +#define _LIBCPP_HAS_THREAD_API_WIN32 1 +#else +#define _LIBCPP_HAS_THREAD_API_PTHREAD 1 +#define _LIBCPP_HAS_THREAD_API_EXTERNAL 0 +#define _LIBCPP_HAS_THREAD_API_WIN32 0 +#endif + +#define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0 +#define _LIBCPP_HAS_FILESYSTEM 1 +#define _LIBCPP_HAS_RANDOM_DEVICE 1 +#define _LIBCPP_HAS_LOCALIZATION 1 +#define _LIBCPP_HAS_UNICODE 1 +#define _LIBCPP_HAS_WIDE_CHARACTERS 1 +#define _LIBCPP_HAS_TIME_ZONE_DATABASE 1 + +#if defined(__APPLE__) +#define _LIBCPP_PSTL_BACKEND_LIBDISPATCH +#else +#define _LIBCPP_PSTL_BACKEND_STD_THREAD +#endif + +#define _LIBCPP_ASSERTION_SEMANTIC_DEFAULT \ + _LIBCPP_ASSERTION_SEMANTIC_HARDENING_DEPENDENT + +#define _LIBCPP_LIBC_PICOLIBC 0 +#define _LIBCPP_LIBC_NEWLIB 0 + +#define _LIBCPP_NO_AUTO_LINK +#define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES +#define _LIBCPP_NO_ABI_TAG +#define _LIBCPP_VERBOSE_ABORT(...) ::std::__libcpp_verbose_abort(__VA_ARGS__) +#define _LIBCPP_HAS_NO_INCOMPLETE_PSTL + +#endif // _LIBCPP_CONFIG_SITE diff --git a/third_party/v8/libcxxabi.BUILD.bazel b/third_party/v8/libcxxabi.BUILD.bazel new file mode 100644 index 0000000000..de4289b4dc --- /dev/null +++ b/third_party/v8/libcxxabi.BUILD.bazel @@ -0,0 +1,98 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load("@llvm//toolchain/runtimes:cc_runtime_library.bzl", "cc_runtime_stage0_library") + +package(default_visibility = ["//visibility:public"]) + +config_setting( + name = "is_linux", + constraint_values = ["@platforms//os:linux"], +) + +config_setting( + name = "is_windows", + constraint_values = ["@platforms//os:windows"], +) + +cc_library( + name = "headers", + hdrs = glob(["include/**"]), + includes = ["include"], +) + +cc_runtime_stage0_library( + name = "libcxxabi", + srcs = [ + "src/abort_message.cpp", + "src/cxa_aux_runtime.cpp", + "src/cxa_default_handlers.cpp", + "src/cxa_demangle.cpp", + "src/cxa_exception.cpp", + "src/cxa_exception_storage.cpp", + "src/cxa_guard.cpp", + "src/cxa_handlers.cpp", + "src/cxa_personality.cpp", + "src/cxa_vector.cpp", + "src/cxa_virtual.cpp", + "src/fallback_malloc.cpp", + "src/private_typeinfo.cpp", + "src/stdlib_exception.cpp", + "src/stdlib_stdexcept.cpp", + "src/stdlib_typeinfo.cpp", + ] + select({ + ":is_linux": ["src/cxa_thread_atexit.cpp"], + "//conditions:default": [], + }), + textual_hdrs = glob([ + "src/**/*.def", + "src/**/*.h", + "src/**/*.inc", + ]), + copts = [ + "-fexceptions", + "-frtti", + "-fstrict-aliasing", + "-fvisibility=hidden", + "-fvisibility-inlines-hidden", + "-nostdinc++", + "-std=c++23", + "-Wno-nullability-completeness", + "-Wno-unused-parameter", + "-Wundef", + ] + select({ + ":is_windows": ["-Wno-macro-redefined"], + "//conditions:default": ["-fPIC"], + }), + defines = [ + "LIBCXXABI_SILENT_TERMINATE", + "_LIBCPP_BUILDING_LIBRARY", + "_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS", + "_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE", + "_LIBCPP_INSTRUMENTED_WITH_ASAN=0", + "_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS", + ] + select({ + "@llvm//platforms/config:musl": [ + "ANDROID_HOST_MUSL", + ], + "//conditions:default": [], + }), + includes = ["src"], + implementation_deps = [ + ":headers", + "@rusty_v8_libcxx//:headers", + "@rusty_v8_libcxx//:internal_headers", + "@//third_party/v8/libcxx_config:headers", + ] + select({ + ":is_linux": [ + "@@llvm++kernel_headers+kernel_headers//:kernel_headers", + ], + "//conditions:default": [], + }) + select({ + "@llvm//platforms/config:gnu": [ + "@@llvm++glibc+glibc//:gnu_libc_headers", + ], + "@llvm//platforms/config:musl": [ + "@@llvm++musl+musl_libc//:musl_libc_headers", + ], + "//conditions:default": [], + }), +) diff --git a/third_party/v8/llvm_libc.BUILD.bazel b/third_party/v8/llvm_libc.BUILD.bazel new file mode 100644 index 0000000000..7940656fb8 --- /dev/null +++ b/third_party/v8/llvm_libc.BUILD.bazel @@ -0,0 +1,10 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "headers", + hdrs = glob(["**/*.h"]), + defines = ["LIBC_NAMESPACE=__llvm_libc_cr"], + includes = ["."], +)