File
Blob: patches/v8/0034-Remove-V8-MODULE.bazel-llvm-toolchain-and-libcxx-rep.patch
| 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Workerd Maintainers <workers-dev@cloudflare.com> |
| 3 | Date: Wed, 4 Mar 2026 12:37:49 -0800 |
| 4 | Subject: Remove V8 MODULE.bazel llvm toolchain and libcxx repo rules |
| 5 | |
| 6 | These reference third_party/ sources that are not present in the GitHub |
| 7 | tarball. Workerd provides its own toolchain, so these are not needed. |
| 8 | |
| 9 | diff --git a/MODULE.bazel b/MODULE.bazel |
| 10 | index 7d7ba53b579605a6f469fe01ddf699d1284110e3..7ddd8259e790ebbfce0bfbb08e08ed4130592f9b 100644 |
| 11 | --- a/MODULE.bazel |
| 12 | +++ b/MODULE.bazel |
| 13 | @@ -22,167 +22,7 @@ pip.parse( |
| 14 | ) |
| 15 | use_repo(pip, "v8_python_deps") |
| 16 | |
| 17 | -# Define the local LLVM toolchain repository |
| 18 | -llvm_toolchain_repository = use_repo_rule("//bazel/toolchain:llvm_repository.bzl", "llvm_toolchain_repository") |
| 19 | |
| 20 | -llvm_toolchain_repository( |
| 21 | - name = "llvm_toolchain", |
| 22 | - path = "third_party/llvm-build/Release+Asserts", |
| 23 | - config_file_content = """ |
| 24 | -load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", "feature", "flag_group", "flag_set", "tool_path") |
| 25 | - |
| 26 | -def _impl(ctx): |
| 27 | - tool_paths = [ |
| 28 | - tool_path(name = "gcc", path = "bin/clang"), |
| 29 | - tool_path(name = "ld", path = "bin/lld"), |
| 30 | - tool_path(name = "ar", path = "bin/llvm-ar"), |
| 31 | - tool_path(name = "cpp", path = "bin/clang++"), |
| 32 | - tool_path(name = "gcov", path = "/bin/false"), |
| 33 | - tool_path(name = "nm", path = "bin/llvm-nm"), |
| 34 | - tool_path(name = "objdump", path = "bin/llvm-objdump"), |
| 35 | - tool_path(name = "strip", path = "bin/llvm-strip"), |
| 36 | - ] |
| 37 | - |
| 38 | - features = [ |
| 39 | - feature( |
| 40 | - name = "default_compile_flags", |
| 41 | - enabled = True, |
| 42 | - flag_sets = [ |
| 43 | - flag_set( |
| 44 | - actions = [ |
| 45 | - "c-compile", |
| 46 | - "c++-compile", |
| 47 | - "c++-header-parsing", |
| 48 | - "c++-module-compile", |
| 49 | - "c++-module-codegen", |
| 50 | - "linkstamp-compile", |
| 51 | - "assemble", |
| 52 | - "preprocess-assemble", |
| 53 | - ], |
| 54 | - flag_groups = [ |
| 55 | - flag_group( |
| 56 | - flags = [ |
| 57 | - "--sysroot={WORKSPACE_ROOT}/build/linux/debian_bullseye_amd64-sysroot", |
| 58 | - "-nostdinc++", |
| 59 | - "-isystem", |
| 60 | - "{WORKSPACE_ROOT}/buildtools/third_party/libc++", |
| 61 | - "-isystem", |
| 62 | - "{WORKSPACE_ROOT}/third_party/libc++/src/include", |
| 63 | - "-isystem", |
| 64 | - "{WORKSPACE_ROOT}/third_party/libc++abi/src/include", |
| 65 | - "-isystem", |
| 66 | - "{WORKSPACE_ROOT}/third_party/libc++/src/src", |
| 67 | - "-isystem", |
| 68 | - "{WORKSPACE_ROOT}/third_party/llvm-libc/src", |
| 69 | - "-D_LIBCPP_HARDENING_MODE_DEFAULT=_LIBCPP_HARDENING_MODE_NONE", |
| 70 | - "-DLIBC_NAMESPACE=__llvm_libc_cr", |
| 71 | - ], |
| 72 | - ), |
| 73 | - ], |
| 74 | - ), |
| 75 | - ], |
| 76 | - ), |
| 77 | - feature( |
| 78 | - name = "default_linker_flags", |
| 79 | - enabled = True, |
| 80 | - flag_sets = [ |
| 81 | - flag_set( |
| 82 | - actions = [ |
| 83 | - "c++-link-executable", |
| 84 | - "c++-link-dynamic-library", |
| 85 | - "c++-link-nodeps-dynamic-library", |
| 86 | - ], |
| 87 | - flag_groups = [ |
| 88 | - flag_group( |
| 89 | - flags = [ |
| 90 | - "--sysroot={WORKSPACE_ROOT}/build/linux/debian_bullseye_amd64-sysroot", |
| 91 | - "-fuse-ld=lld", |
| 92 | - "-lm", |
| 93 | - "-lpthread", |
| 94 | - ], |
| 95 | - ), |
| 96 | - ], |
| 97 | - ), |
| 98 | - ], |
| 99 | - ), |
| 100 | - ] |
| 101 | - |
| 102 | - return cc_common.create_cc_toolchain_config_info( |
| 103 | - ctx = ctx, |
| 104 | - features = features, |
| 105 | - cxx_builtin_include_directories = [ |
| 106 | - "{WORKSPACE_ROOT}/buildtools/third_party/libc++", |
| 107 | - "{WORKSPACE_ROOT}/third_party/libc++/src/include", |
| 108 | - "{WORKSPACE_ROOT}/third_party/libc++abi/src/include", |
| 109 | - "{WORKSPACE_ROOT}/third_party/libc++/src/src", |
| 110 | - "{WORKSPACE_ROOT}/third_party/llvm-libc/src", |
| 111 | - "{WORKSPACE_ROOT}/third_party/llvm-build/Release+Asserts/lib/clang/22/include", |
| 112 | - "{WORKSPACE_ROOT}/third_party/llvm-build/Release+Asserts/lib/clang/23/include", |
| 113 | - "{WORKSPACE_ROOT}/build/linux/debian_bullseye_amd64-sysroot/usr/include", |
| 114 | - "{WORKSPACE_ROOT}/build/linux/debian_bullseye_amd64-sysroot/usr/local/include", |
| 115 | - ], |
| 116 | - toolchain_identifier = "local_clang", |
| 117 | - host_system_name = "local", |
| 118 | - target_system_name = "local", |
| 119 | - target_cpu = "k8", |
| 120 | - target_libc = "unknown", |
| 121 | - compiler = "clang", |
| 122 | - abi_version = "unknown", |
| 123 | - abi_libc_version = "unknown", |
| 124 | - tool_paths = tool_paths, |
| 125 | - ) |
| 126 | - |
| 127 | -cc_toolchain_config = rule( |
| 128 | - implementation = _impl, |
| 129 | - attrs = {}, |
| 130 | - provides = [CcToolchainConfigInfo], |
| 131 | -) |
| 132 | -""", |
| 133 | - build_file_content = """ |
| 134 | -load(":cc_toolchain_config.bzl", "cc_toolchain_config") |
| 135 | - |
| 136 | -package(default_visibility = ["//visibility:public"]) |
| 137 | - |
| 138 | -filegroup( |
| 139 | - name = "all_files", |
| 140 | - srcs = glob(["**/*"]), |
| 141 | -) |
| 142 | - |
| 143 | -filegroup(name = "empty") |
| 144 | - |
| 145 | -cc_toolchain_config(name = "k8_toolchain_config") |
| 146 | - |
| 147 | -cc_toolchain( |
| 148 | - name = "k8_toolchain", |
| 149 | - all_files = ":all_files", |
| 150 | - ar_files = ":all_files", |
| 151 | - compiler_files = ":all_files", |
| 152 | - dwp_files = ":empty", |
| 153 | - linker_files = ":all_files", |
| 154 | - objcopy_files = ":all_files", |
| 155 | - strip_files = ":all_files", |
| 156 | - supports_param_files = 0, |
| 157 | - toolchain_config = ":k8_toolchain_config", |
| 158 | - toolchain_identifier = "local_clang", |
| 159 | -) |
| 160 | - |
| 161 | -toolchain( |
| 162 | - name = "cc_toolchain_k8", |
| 163 | - exec_compatible_with = [ |
| 164 | - "@platforms//cpu:x86_64", |
| 165 | - "@platforms//os:linux", |
| 166 | - ], |
| 167 | - target_compatible_with = [ |
| 168 | - "@platforms//cpu:x86_64", |
| 169 | - "@platforms//os:linux", |
| 170 | - ], |
| 171 | - toolchain = ":k8_toolchain", |
| 172 | - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", |
| 173 | -) |
| 174 | -""", |
| 175 | -) |
| 176 | - |
| 177 | -register_toolchains("@llvm_toolchain//:cc_toolchain_k8") |
| 178 | |
| 179 | # Define local repository for libc++ from third_party sources |
| 180 | libcxx_repository = use_repo_rule("//bazel/toolchain:libcxx_repository.bzl", "libcxx_repository") |
| 181 | diff --git a/bazel/toolchain/libcxx_repository.bzl b/bazel/toolchain/libcxx_repository.bzl |
| 182 | index a7d5f11053dd333c5bec614c27168a0effb7b4aa..ed367ef64871133867e9eccb07c6482a4de08ceb 100644 |
| 183 | --- a/bazel/toolchain/libcxx_repository.bzl |
| 184 | +++ b/bazel/toolchain/libcxx_repository.bzl |
| 185 | @@ -1,99 +1,17 @@ |
| 186 | -"""Repository rule for building libc++ from third_party sources.""" |
| 187 | +"""Stub repository rule: workerd uses the system/toolchain libc++, so @libcxx |
| 188 | +is an empty shim that satisfies the dep in bazel/defs.bzl without pulling in |
| 189 | +any third_party sources.""" |
| 190 | |
| 191 | def _libcxx_repository_impl(ctx): |
| 192 | - # Find the workspace root |
| 193 | - workspace_root = ctx.path(Label("@//:BUILD.bazel")).dirname |
| 194 | - |
| 195 | - # Symlink the source directories |
| 196 | - ctx.symlink(workspace_root.get_child("third_party").get_child("libc++"), "libc++") |
| 197 | - ctx.symlink(workspace_root.get_child("third_party").get_child("libc++abi"), "libc++abi") |
| 198 | - ctx.symlink(workspace_root.get_child("third_party").get_child("llvm-libc"), "llvm-libc") |
| 199 | - ctx.symlink(workspace_root.get_child("buildtools").get_child("third_party").get_child("libc++"), "buildtools_libc++") |
| 200 | - |
| 201 | - # Get the external repository path for include flags |
| 202 | - # In bzlmod, repo names may have prefixes, so we need to determine the actual path |
| 203 | - repo_path = "external/" + ctx.name |
| 204 | - |
| 205 | - # Create the BUILD file |
| 206 | - # NOTE: We don't use 'includes' attribute here because it creates relative paths |
| 207 | - # that conflict with the toolchain's absolute paths, breaking #include_next. |
| 208 | - # The toolchain provides the libc++ include paths via -isystem flags. |
| 209 | - build_content = ''' |
| 210 | + ctx.file("BUILD.bazel", """ |
| 211 | package(default_visibility = ["//visibility:public"]) |
| 212 | |
| 213 | -LIBCXX_COPTS = [ |
| 214 | - "-std=c++23", |
| 215 | - "-fPIC", |
| 216 | - "-fstrict-aliasing", |
| 217 | - "-fexceptions", |
| 218 | - "-frtti", |
| 219 | - "-D_LIBCPP_BUILDING_LIBRARY", |
| 220 | - "-D_LIBCPP_HARDENING_MODE_DEFAULT=_LIBCPP_HARDENING_MODE_NONE", |
| 221 | - "-DLIBC_NAMESPACE=__llvm_libc_cr", |
| 222 | -] |
| 223 | - |
| 224 | -cc_library( |
| 225 | - name = "libc++abi", |
| 226 | - srcs = glob([ |
| 227 | - "libc++abi/src/src/*.cpp", |
| 228 | - "libc++abi/src/src/*.h", |
| 229 | - "libc++abi/src/src/demangle/*.h", |
| 230 | - ], exclude = [ |
| 231 | - # Exclude files not needed for Linux build |
| 232 | - "libc++abi/src/src/cxa_noexception.cpp", |
| 233 | - "libc++abi/src/src/stdlib_new_delete.cpp", |
| 234 | - ]), |
| 235 | - hdrs = glob([ |
| 236 | - "libc++abi/src/include/**/*.h", |
| 237 | - "libc++/src/include/**/*", |
| 238 | - "libc++/src/src/include/*.h", |
| 239 | - "libc++abi/src/src/demangle/*.def", |
| 240 | - "buildtools_libc++/__config_site", |
| 241 | - "buildtools_libc++/__assertion_handler", |
| 242 | - "llvm-libc/src/**/*.h", |
| 243 | - ]), |
| 244 | - copts = LIBCXX_COPTS + [ |
| 245 | - "-DLIBCXXABI_SILENT_TERMINATE", |
| 246 | - "-iquote", "{REPO_PATH}/libc++abi/src/src", |
| 247 | - "-iquote", "{REPO_PATH}/libc++abi/src/src/demangle", |
| 248 | - ], |
| 249 | - linkstatic = True, |
| 250 | -) |
| 251 | - |
| 252 | -cc_library( |
| 253 | - name = "libc++", |
| 254 | - srcs = glob([ |
| 255 | - "libc++/src/src/*.cpp", |
| 256 | - "libc++/src/src/*.h", |
| 257 | - "libc++/src/src/filesystem/*.cpp", |
| 258 | - "libc++/src/src/filesystem/*.h", |
| 259 | - "libc++/src/src/ryu/*.cpp", |
| 260 | - "libc++/src/src/include/*.h", |
| 261 | - "libc++/src/src/include/ryu/*.h", |
| 262 | - ]) + glob(["libc++/src/src/support/**/*.ipp"], allow_empty = True), |
| 263 | - hdrs = glob([ |
| 264 | - "libc++/src/include/**/*", |
| 265 | - "buildtools_libc++/__config_site", |
| 266 | - "buildtools_libc++/__assertion_handler", |
| 267 | - "llvm-libc/src/**/*.h", |
| 268 | - ]), |
| 269 | - copts = LIBCXX_COPTS + [ |
| 270 | - "-DLIBCXX_BUILDING_LIBCXXABI", |
| 271 | - "-iquote", "{REPO_PATH}/libc++/src/src", |
| 272 | - "-iquote", "{REPO_PATH}/libc++/src/src/filesystem", |
| 273 | - ], |
| 274 | - linkopts = [ |
| 275 | - "-lpthread", |
| 276 | - "-lm", |
| 277 | - ], |
| 278 | - deps = [":libc++abi"], |
| 279 | - linkstatic = True, |
| 280 | -) |
| 281 | -'''.format(REPO_PATH=repo_path) |
| 282 | - ctx.file("BUILD.bazel", build_content) |
| 283 | +# Empty stub – the real libc++ is provided by the toolchain. |
| 284 | +cc_library(name = "libc++") |
| 285 | +cc_library(name = "libc++abi") |
| 286 | +""") |
| 287 | |
| 288 | libcxx_repository = repository_rule( |
| 289 | implementation = _libcxx_repository_impl, |
| 290 | local = True, |
| 291 | - configure = True, |
| 292 | ) |