From b2f7dd342ccc0a9063f78251dd415a461ea1e839 Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Fri, 5 Dec 2025 16:10:12 +0100 Subject: [PATCH 01/12] Add support for Windows target and host --- platforms/BUILD.bazel | 16 ++ toolchain/BUILD.llvm_repo.tpl | 10 +- toolchain/BUILD.llvm_repo_windows.tpl | 228 +++++++++++++++++++++++++ toolchain/cc_toolchain_config.bzl | 235 +++++++++++++++++++------- toolchain/internal/common.bzl | 21 ++- toolchain/internal/configure.bzl | 53 ++++-- toolchain/internal/repo.bzl | 12 +- 7 files changed, 494 insertions(+), 81 deletions(-) create mode 100644 toolchain/BUILD.llvm_repo_windows.tpl diff --git a/platforms/BUILD.bazel b/platforms/BUILD.bazel index 2a11012fb..051cc538b 100644 --- a/platforms/BUILD.bazel +++ b/platforms/BUILD.bazel @@ -93,3 +93,19 @@ platform( "@platforms//cpu:wasm64", ], ) + +platform( + name = "windows-x86_64", + constraint_values = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], +) + +platform( + name = "windows-aarch64", + constraint_values = [ + "@platforms//os:windows", + "@platforms//cpu:aarch64", + ], +) diff --git a/toolchain/BUILD.llvm_repo.tpl b/toolchain/BUILD.llvm_repo.tpl index 5b04bd6af..230d29d20 100644 --- a/toolchain/BUILD.llvm_repo.tpl +++ b/toolchain/BUILD.llvm_repo.tpl @@ -30,9 +30,11 @@ exports_files(glob( filegroup( name = "clang", srcs = [ - "bin/clang", - "bin/clang++", - "bin/clang-cpp", + "bin/clang", + "bin/clang++", + "bin/clang-cpp", + "bin/clang-cl", + "bin/lld-link", ], ) @@ -42,6 +44,7 @@ filegroup( srcs = [ "bin/ld.lld", "bin/ld64.lld", + "bin/lld-link", ] + glob(["bin/wasm-ld"], allow_empty = True), ) @@ -185,6 +188,7 @@ filegroup( [ "lib/libclang.so", "lib/libclang.dylib", + "lib/libclang.lib", ], allow_empty = True, ), diff --git a/toolchain/BUILD.llvm_repo_windows.tpl b/toolchain/BUILD.llvm_repo_windows.tpl new file mode 100644 index 000000000..386b5b856 --- /dev/null +++ b/toolchain/BUILD.llvm_repo_windows.tpl @@ -0,0 +1,228 @@ +# Copyright 2021 The Bazel Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +package(default_visibility = ["//visibility:public"]) + +# Some targets may need to directly depend on these files. +exports_files(glob( + [ + "bin/*", + "lib/**", + "include/**", + "share/clang/*", + ], + allow_empty = True, +)) + +## LLVM toolchain files + +ALL_DLLS = glob(["bin/*.dll"], allow_empty=True) + +filegroup( + name = "clang", + srcs = [ + "bin/clang.exe", + "bin/clang++.exe", + "bin/clang-cpp.exe", + "bin/clang-cl.exe", + "bin/lld-link.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "ld", + # Not all distributions contain wasm-ld. + srcs = [ + "bin/ld.lld.exe", + "bin/ld64.lld.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "include", + srcs = glob( + [ + "include/**/c++/**", + "lib/clang/*/include/**", + ], + ), +) + +filegroup( + name = "all_includes", + srcs = glob( + ["include/**"], + allow_empty = True, + ), +) + +# This filegroup should only have source directories, not individual files. +# We rely on this assumption in system_module_map.bzl. +filegroup( + name = "cxx_builtin_include", + srcs = [ + "include/c++", + "lib/clang/{LLVM_VERSION}/include", + ], +) + +filegroup( + name = "extra_config_site", + srcs = glob(["include/*/c++/v1/__config_site"], allow_empty = True) +) + +filegroup( + name = "bin", + srcs = glob(["bin/**"]), +) + +filegroup( + name = "lib", + srcs = [ + # Include the .dylib files in the linker sandbox even though they will + # not be available at runtime to allow sanitizers to work locally. + # Any library linked from the toolchain to be released should be linked statically. + "lib/clang/{LLVM_VERSION}/lib", + ], +) + +filegroup( + name = "lib_legacy", + srcs = glob([ + # Include the .dylib files in the linker sandbox even though they will + # not be available at runtime to allow sanitizers to work locally. + # Any library linked from the toolchain to be released should be linked statically. + "lib/clang/{LLVM_VERSION}/lib/**", + "lib/**/libc++*.a", + "lib/**/libunwind.a", + ], allow_empty = True), +) + +filegroup( + name = "ar", + srcs = [ + "bin/llvm-ar.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "as", + srcs = [ + "bin/clang.exe", + "bin/llvm-as.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "nm", + srcs = [ + "bin/llvm-nm.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "llvm-lib", + srcs = [ + "bin/llvm-lib.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "objcopy", + srcs = [ + "bin/llvm-objcopy.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "objdump", + srcs = [ + "bin/llvm-objdump.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "profdata", + srcs = [ + "bin/llvm-profdata.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "dwp", + srcs = [ + "bin/llvm-dwp.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "ranlib", + srcs = [ + "bin/llvm-ranlib.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "readelf", + srcs = [ + "bin/llvm-readelf.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "strip", + srcs = [ + "bin/llvm-strip.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "symbolizer", + srcs = [ + "bin/llvm-symbolizer.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "clang-tidy", + srcs = [ + "bin/clang-tidy.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "clang-format", + srcs = [ + "bin/clang-format.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "git-clang-format", + srcs = [ + "bin/git-clang-format.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "libclang", + srcs = glob( + [ + "lib/libclang.so", + "lib/libclang.dylib", + "lib/libclang.lib", + ], + allow_empty = True, + ), +) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 3edc2986f..7a6bec8ef 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -17,6 +17,10 @@ load( "@rules_cc//cc/private/toolchain:unix_cc_toolchain_config.bzl", unix_cc_toolchain_config = "cc_toolchain_config", ) +load( + "@rules_cc//cc/private/toolchain:windows_cc_toolchain_config.bzl", + windows_cc_toolchain_config = "cc_toolchain_config", +) load( "//toolchain/internal:common.bzl", _check_os_arch_keys = "check_os_arch_keys", @@ -28,6 +32,14 @@ load( def _fmt_flags(flags, toolchain_path_prefix): return [f.format(toolchain_path_prefix = toolchain_path_prefix) for f in flags] +def _machine_arch(target_arch): + if target_arch == "x86_64": + return "X64" + elif target_arch == "aarch64": + return "ARM64" + else: + fail("Unsupported target architecture: {}".format(target_arch)) + # Macro for calling cc_toolchain_config from @bazel_tools with setting the # right paths and flags for the tools. def cc_toolchain_config( @@ -146,6 +158,22 @@ def cc_toolchain_config( "unknown", "unknown", ), + "windows-x86_64": ( + "clang-x86_64-windows", + "x64_windows", + "msvc", + "clang-cl", + "windows_x86_64", # TODO: is that correct? + "windows_x86_64", # TODO: is that correct? + ), + "windows-aarch64": ( + "clang-aarch64-windows", + "arm64_windows", + "msvc", + "clang-cl", + "windows_aarch64", # TODO: is that correct? + "windows_aarch64", # TODO: is that correct? + ), }[target_os_arch_key] # Unfiltered compiler flags; these are placed at the end of the command @@ -161,19 +189,36 @@ def cc_toolchain_config( "-D__TIME__=\"redacted\"", ] + sysroot_path = compiler_configuration["sysroot_path"] + # Default compiler flags: compile_flags = [ "--target=" + target_system_name, - # Security - "-U_FORTIFY_SOURCE", # https://github.com/google/sanitizers/issues/247 - "-fstack-protector", - "-fno-omit-frame-pointer", # Diagnostics "-fcolor-diagnostics", - "-Wall", - "-Wthread-safety", - "-Wself-assign", ] + if compiler == "clang-cl": + compile_flags.extend([ + "/Wall", + "/MT", + "/Brepro", + "/DWIN32", + "/D_WIN32", + "/D_WINDOWS", + "/clang:-fdebug-prefix-map={}=__bazel_toolchain_llvm_repo__/".format(toolchain_path_prefix), + "/clang-I{}/Include".format(sysroot_path), # TODO: is that needed now? + ]) + else: + compile_flags.extend([ + # Security + "-U_FORTIFY_SOURCE", # https://github.com/google/sanitizers/issues/247 + "-fstack-protector", + "-fno-omit-frame-pointer", + # Diagnostics + "-Wall", + "-Wthread-safety", + "-Wself-assign", + ]) dbg_compile_flags = ["-g", "-fstandalone-debug"] @@ -188,18 +233,29 @@ def cc_toolchain_config( "-fdata-sections", ] - link_flags = [ - "--target=" + target_system_name, - "-no-canonical-prefixes", - "-fuse-ld=lld", - ] + if compiler == "clang-cl": # TODO: we should actually check if the linker is `lld-link` instead + link_flags = [ + # The --target flag is for some uninvestigated yet reason required for Cargo build script to work on Windows ARM, otherwise it fails with: + # ERROR: C:/temp/k7ozco62/external/rules_rust++crate+fleet_crates__windows_aarch64_msvc-0.52.6/BUILD.bazel:75:19: + # error while validating output tree artifact external/rules_rust++crate+fleet_crates__windows_aarch64_msvc-0.52.6/_bs.cargo_runfiles: + # C:\temp\k7ozco62\execroot\_main\bazel-out\arm64_windows-fastbuild\bin\external\rules_rust++crate+fleet_crates__windows_aarch64_msvc-0.52.6\_bs.cargo_runfiles\rules_rust++crate+fleet_crates__windows_aarch64_msvc-0.52.6 + # ERROR: C:/temp/k7ozco62/external/rules_rust++crate+fleet_crates__windows_aarch64_msvc-0.52.6/BUILD.bazel:75:19: Running Cargo build script windows_aarch64_msvc failed: not all outputs were created or valid + "--target=" + target_system_name, + "/MACHINE:{}".format(_machine_arch(target_arch)), + ] + else: + link_flags = [ + "--target=" + target_system_name, + "-no-canonical-prefixes", + "-fuse-ld=lld", + ] if exec_os == "darwin": # These will get expanded by osx_cc_wrapper's `sanitize_option` link_flags.append("--ld-path=ld64.lld" if target_os == "darwin" else "--ld-path=ld.lld") stdlib = compiler_configuration["stdlib"] - if stdlib != "none": + if stdlib != "none" and compiler != "clang-cl": # TODO: we should actually check if the linker is `lld-link` instead link_flags.extend([ "-lm", ]) @@ -224,6 +280,11 @@ def cc_toolchain_config( elif target_arch in ["wasm32", "wasm64"]: # lld is invoked as wasm-ld for WebAssembly targets. use_libtool = False + elif compiler == "clang-cl": + link_flags.extend([ + "/LIBPATH:{}/Lib".format(sysroot_path), + ]) + use_libtool = False else: link_flags.extend([ "-Wl,--build-id=md5", @@ -235,14 +296,18 @@ def cc_toolchain_config( # Pre-installed libtool on macOS has -static as default, but llvm-libtool-darwin needs it # explicitly. cc_common.create_link_variables does not automatically add this either if # output_file arg to it is None. - archive_flags = ["-static"] if is_darwin_exec_and_target else [] + if is_darwin_exec_and_target: + archive_flags = ["-static"] + elif compiler == "clang-cl" and target_os == "windows": + archive_flags = ["/MACHINE:{}".format(_machine_arch(target_arch))] + else: + archive_flags = [] # Flags related to C++ standard. # The linker has no way of knowing if there are C++ objects; so we # always link C++ libraries. cxx_standard = compiler_configuration["cxx_standard"] conly_flags = compiler_configuration["conly_flags"] - sysroot_path = compiler_configuration["sysroot_path"] is_xcompile = not (exec_os == target_os and exec_arch == target_arch) @@ -273,6 +338,9 @@ def cc_toolchain_config( "-Bstatic", "-lunwind", ] + elif target_os == "windows": + # TODO: should we do something about that case for Windows? + pass else: # For single-platform builds, we can statically link the bundled # libraries. @@ -327,6 +395,12 @@ def cc_toolchain_config( link_flags.extend([ "-nostdlib", ]) + elif compiler == "clang-cl" and target_libc == "msvc": + cxx_flags = [ + "/std:" + cxx_standard, + "-fms-compatibility", + "-fms-extensions", + ] else: fail("Unknown value passed for stdlib: {stdlib}".format(stdlib = stdlib)) @@ -353,6 +427,10 @@ def cc_toolchain_config( ## NOTE: make variables are missing here; unix_cc_toolchain_config doesn't ## pass these to `create_cc_toolchain_config_info`. + binary_ext = "" + if exec_os == "windows": + binary_ext = ".exe" + # The requirements here come from # https://cs.opensource.google/bazel/bazel/+/master:src/main/starlark/builtins_bzl/common/cc/cc_toolchain_provider_helper.bzl;l=75;drc=f0150efd1cca473640269caaf92b5a23c288089d # https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java;l=1257;drc=6743d76f9ecde726d592e88d8914b9db007b1c43 @@ -360,18 +438,19 @@ def cc_toolchain_config( # https://github.com/bazelbuild/rules_cc/blob/fe41fc4ea219c9d3680ee536bba6681f3baf838e/cc/private/toolchain/unix_cc_toolchain_config.bzl#L1887 # NOTE: Ensure these are listed in toolchain_tools in toolchain/internal/common.bzl. tool_paths = { - "ar": tools_path_prefix + ("llvm-ar" if not use_libtool else "libtool"), - "cpp": tools_path_prefix + "clang-cpp", - "dwp": tools_path_prefix + "llvm-dwp", - "gcc": wrapper_bin_prefix + "cc_wrapper.sh", - "gcov": tools_path_prefix + "llvm-profdata", - "ld": tools_path_prefix + "ld.lld", - "llvm-cov": tools_path_prefix + "llvm-cov", - "llvm-profdata": tools_path_prefix + "llvm-profdata", - "nm": tools_path_prefix + "llvm-nm", - "objcopy": tools_path_prefix + "llvm-objcopy", - "objdump": tools_path_prefix + "llvm-objdump", - "strip": tools_path_prefix + "llvm-strip", + "ar": tools_path_prefix + ("llvm-ar" if not use_libtool else "libtool") + binary_ext, + "cpp": tools_path_prefix + "clang-cpp" + binary_ext, + "dwp": tools_path_prefix + "llvm-dwp" + binary_ext, + "gcc": tools_path_prefix + "clang-cl" + binary_ext if target_os == "windows" else wrapper_bin_prefix + "cc_wrapper.sh", + "gcov": tools_path_prefix + "llvm-profdata" + binary_ext, + "ld": tools_path_prefix + "lld-link" + binary_ext if target_os == "windows" else tools_path_prefix + "ld.lld" + binary_ext, + "llvm-lib": tools_path_prefix + "llvm-lib" + binary_ext, + "llvm-cov": tools_path_prefix + "llvm-cov" + binary_ext, + "llvm-profdata": tools_path_prefix + "llvm-profdata" + binary_ext, + "nm": tools_path_prefix + "llvm-nm" + binary_ext, + "objcopy": tools_path_prefix + "llvm-objcopy" + binary_ext, + "objdump": tools_path_prefix + "llvm-objdump" + binary_ext, + "strip": tools_path_prefix + "llvm-strip" + binary_ext, "parse_headers": wrapper_bin_prefix + "cc_wrapper.sh", } @@ -431,33 +510,75 @@ def cc_toolchain_config( if compiler_configuration["extra_unfiltered_compile_flags"] != None: unfiltered_compile_flags.extend(_fmt_flags(compiler_configuration["extra_unfiltered_compile_flags"], toolchain_path_prefix)) - # Source: https://cs.opensource.google/bazel/bazel/+/master:tools/cpp/unix_cc_toolchain_config.bzl - unix_cc_toolchain_config( - name = name, - cpu = target_cpu, - compiler = compiler, - toolchain_identifier = toolchain_identifier, - host_system_name = exec_arch, - target_system_name = target_system_name, - target_libc = target_libc, - abi_version = abi_version, - abi_libc_version = abi_libc_version, - cxx_builtin_include_directories = cxx_builtin_include_directories, - tool_paths = tool_paths, - compile_flags = compile_flags, - fastbuild_compile_flags = fastbuild_compile_flags, - dbg_compile_flags = dbg_compile_flags, - opt_compile_flags = opt_compile_flags, - conly_flags = conly_flags, - cxx_flags = cxx_flags, - link_flags = link_flags + select({str(Label("@toolchains_llvm//toolchain/config:use_libunwind")): libunwind_link_flags, "//conditions:default": []}) + - select({str(Label("@toolchains_llvm//toolchain/config:use_compiler_rt")): compiler_rt_link_flags, "//conditions:default": []}), - archive_flags = archive_flags, - link_libs = link_libs, - opt_link_flags = opt_link_flags, - unfiltered_compile_flags = unfiltered_compile_flags, - coverage_compile_flags = coverage_compile_flags, - coverage_link_flags = coverage_link_flags, - supports_start_end_lib = supports_start_end_lib, - builtin_sysroot = sysroot_path, - ) + if target_os == "windows" and compiler == "clang-cl" and target_libc == "msvc": + windows_cc_toolchain_config( + name = name, + cpu = target_cpu, + compiler = compiler, + toolchain_identifier = toolchain_identifier, + host_system_name = exec_arch, + target_system_name = target_system_name, + target_libc = target_libc, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + # msvc_env_tmp = "%{clang_cl_env_tmp_arm64}", # TODO + # msvc_env_path = "%{clang_cl_env_path_arm64}", # TODO + # TODO: should we support that? + # TODO: these relative path are not working here, but I don't know how to resolve a path that would work for everything + msvc_env_include = ";".join([ + "{}/Include".format(sysroot_path), # TODO: is that needed now? + ]), # TODO: should we depend also on cxx includes here? Like: + [i.replace("%workspace%/", "") for i in cxx_builtin_include_directories]), + # TODO: should we support that? + # msvc_env_lib = ";".join([ + # "{}/Lib".format(sysroot_path), + # ]), + msvc_cl_path = tool_paths["gcc"], + # msvc_ml_path = tool_paths["ml"], # TODO + msvc_link_path = tool_paths["ld"], + msvc_lib_path = tool_paths["llvm-lib"], + cxx_builtin_include_directories = cxx_builtin_include_directories, + tool_paths = tool_paths, + archiver_flags = archive_flags, + default_link_flags = link_flags, + default_compile_flags = compile_flags + unfiltered_compile_flags, + dbg_mode_debug_flag = " ".join(dbg_compile_flags), + fastbuild_mode_debug_flag = " ".join(fastbuild_compile_flags), + supports_parse_showincludes = False, + + # TODO: what to do with these? + # opt_compile_flags = opt_compile_flags, + # conly_flags = conly_flags, + # cxx_flags = cxx_flags, + # link_libs = link_libs, + ) + else: + # Source: https://cs.opensource.google/bazel/bazel/+/master:tools/cpp/unix_cc_toolchain_config.bzl + unix_cc_toolchain_config( + name = name, + cpu = target_cpu, + compiler = compiler, + toolchain_identifier = toolchain_identifier, + host_system_name = exec_arch, + target_system_name = target_system_name, + target_libc = target_libc, + abi_version = abi_version, + abi_libc_version = abi_libc_version, + cxx_builtin_include_directories = cxx_builtin_include_directories, + tool_paths = tool_paths, + compile_flags = compile_flags, + fastbuild_compile_flags = fastbuild_compile_flags, + dbg_compile_flags = dbg_compile_flags, + opt_compile_flags = opt_compile_flags, + conly_flags = conly_flags, + cxx_flags = cxx_flags, + link_flags = link_flags + select({str(Label("@toolchains_llvm//toolchain/config:use_libunwind")): libunwind_link_flags, "//conditions:default": []}) + + select({str(Label("@toolchains_llvm//toolchain/config:use_compiler_rt")): compiler_rt_link_flags, "//conditions:default": []}), + archive_flags = archive_flags, + link_libs = link_libs, + opt_link_flags = opt_link_flags, + unfiltered_compile_flags = unfiltered_compile_flags, + coverage_compile_flags = coverage_compile_flags, + coverage_link_flags = coverage_link_flags, + supports_start_end_lib = supports_start_end_lib, + builtin_sysroot = sysroot_path, + ) diff --git a/toolchain/internal/common.bzl b/toolchain/internal/common.bzl index 769cd8495..fd68c51ed 100644 --- a/toolchain/internal/common.bzl +++ b/toolchain/internal/common.bzl @@ -24,6 +24,8 @@ SUPPORTED_TARGETS = [ ("none", "x86_64"), ("wasip1", "wasm32"), ("wasip1", "wasm64"), + ("windows", "x86_64"), + ("windows", "aarch64"), ] # These are targets that can build without a sysroot. @@ -38,6 +40,8 @@ _toolchain_tools = { name: name for name in [ "clang-cpp", + "clang-cl", + "lld-link", "clang-format", "clang-tidy", "clangd", @@ -46,6 +50,7 @@ _toolchain_tools = { "llvm-dwp", "llvm-profdata", "llvm-cov", + "llvm-lib", "llvm-nm", "llvm-objcopy", "llvm-objdump", @@ -134,7 +139,7 @@ def os(rctx): name = rctx.attr.exec_os if name: - if name in ("linux", "darwin", "none"): + if name in ("linux", "darwin", "windows", "none"): return name else: fail("Unsupported value for exec_os: %s" % name) @@ -152,7 +157,7 @@ def os_from_rctx(rctx): def os_bzl(os): # Return the OS string as used in bazel platform constraints. - return {"darwin": "osx", "linux": "linux", "none": "none", "wasip1": "wasi"}[os] + return {"darwin": "osx", "linux": "linux", "windows": "windows", "none": "none", "wasip1": "wasi"}[os] def arch(rctx): arch = rctx.attr.exec_arch @@ -267,7 +272,15 @@ def attr_dict(attr): return dict(tuples) def toolchain_tools(os): - tools = dict(_toolchain_tools) - if os == "darwin": + if os == "windows": + tools = dict() + binary_ext = ".exe" + for bin, symlink in _toolchain_tools.items(): + tools.update({bin + binary_ext: symlink + binary_ext}) + elif os == "darwin": + tools = dict(_toolchain_tools) tools.update(_toolchain_tools_darwin) + else: + tools = dict(_toolchain_tools) + return tools diff --git a/toolchain/internal/configure.bzl b/toolchain/internal/configure.bzl index 45d20556d..541816082 100644 --- a/toolchain/internal/configure.bzl +++ b/toolchain/internal/configure.bzl @@ -72,9 +72,6 @@ def llvm_config_impl(rctx): _check_os_arch_keys(rctx.attr.extra_target_compatible_with) os = _os(rctx) - if os == "windows": - _empty_repository(rctx) - return None arch = _arch(rctx) if not rctx.attr.toolchain_roots: @@ -92,6 +89,25 @@ def llvm_config_impl(rctx): use_absolute_paths_llvm = rctx.attr.absolute_paths use_absolute_paths_sysroot = use_absolute_paths_llvm + if os == "windows": + # FIXME: this is a hack, it must be addressed + # + # Windows has an issue resolving symlinks in the execroot. + # So for now we force `absolute_paths = True` as a hack + # + # Here is an example of failure: + # ERROR: C:/users/titouan.bion/developer_windows/ultimate/fleet/native/launcher/BUILD.bazel:10:12: Compiling Rust bin fleet (15 files) failed: error reading file '@@toolchains_llvm++llvm+llvm_toolchain//:bin/llvm-nm.exe': + # + # Command to reproduce: + # $ bazelisk.exe clean --expunge + # $ bazelisk.exe build //fleet/native/launcher:fleet # FAILS with the above error + # $ dir C:/temp/k7ozco62/external/toolchains_llvm++llvm+llvm_toolchain/bin # shows `d----l` file modes on binaries + # $ bazelisk.exe query --output build //fleet/native/launcher:fleet # WORKS + # $ dir C:/temp/k7ozco62/external/toolchains_llvm++llvm+llvm_toolchain/bin # shows `d----l` file modes on binaries + # $ bazelisk.exe build //fleet/native/launcher:fleet # WORKS + # $ dir C:/temp/k7ozco62/external/toolchains_llvm++llvm+llvm_toolchain/bin # shows `-a----` file modes on binaries + use_absolute_paths_llvm = True + # Check if the toolchain root is a system path. system_llvm = False if _is_absolute_path(toolchain_root): @@ -193,7 +209,6 @@ def llvm_config_impl(rctx): extra_coverage_link_flags_dict = rctx.attr.extra_coverage_link_flags, extra_unfiltered_compile_flags_dict = rctx.attr.extra_unfiltered_compile_flags, ) - exec_dl_ext = "dylib" if os == "darwin" else "so" cc_toolchains_str, toolchain_labels_str = _cc_toolchains_str( rctx, workspace_name, @@ -206,7 +221,6 @@ def llvm_config_impl(rctx): use_absolute_paths_llvm, llvm_dist_rel_path, llvm_dist_label_prefix, - exec_dl_ext, ) # Convenience macro to register all generated toolchains. @@ -354,6 +368,8 @@ def _cc_toolchain_str( "wasm64": "wasm64-unknown-unknown", "wasip1-wasm32": "wasm32-wasip1", "wasip1-wasm64": "wasm64-wasip1", + "windows-x86_64": "x86_64-pc-windows-msvc", + "windows-aarch64": "aarch64-pc-windows-msvc", }[target_pair] cxx_builtin_include_directories = [ @@ -387,6 +403,12 @@ def _cc_toolchain_str( _join(sysroot_prefix, "/usr/include"), _join(sysroot_prefix, "/System/Library/Frameworks"), ]) + elif target_os == "windows": + if sysroot_prefix: + cxx_builtin_include_directories.extend([ + _join(sysroot_prefix, "/Include"), + ]) + pass elif target_os == "none" or target_os == "wasip1": if sysroot_prefix: cxx_builtin_include_directories.extend([ @@ -643,7 +665,18 @@ cc_toolchain( def _is_remote(rctx, exec_os, exec_arch): return not (_os_from_rctx(rctx) == exec_os and _arch_from_rctx(rctx) == exec_arch) -def _convenience_targets_str(rctx, use_absolute_paths, llvm_dist_rel_path, llvm_dist_label_prefix, exec_dl_ext): +def _convenience_targets_str(rctx, use_absolute_paths, llvm_dist_rel_path, llvm_dist_label_prefix): + ext = "" + exec_dl_ext = "" + os = _os(rctx) + if os == "windows": + ext = ".exe" + exec_dl_ext = "lib" + elif os == "darwin": + exec_dl_ext = "dylib" + else: + exec_dl_ext = "so" + if use_absolute_paths: llvm_dist_label_prefix = ":" filenames = [] @@ -651,7 +684,7 @@ def _convenience_targets_str(rctx, use_absolute_paths, llvm_dist_rel_path, llvm_ filename = "lib/{}.{}".format(libname, exec_dl_ext) filenames.append(filename) for toolname in _aliased_tools: - filename = "bin/{}".format(toolname) + filename = "bin/{}{}".format(toolname, ext) filenames.append(filename) for filename in filenames: @@ -671,9 +704,9 @@ cc_import( template = """ native_binary( name = "{name}", - out = "{name}", - src = "{{llvm_dist_label_prefix}}bin/{name}", -)""".format(name = name) + out = "{bin_name}", + src = "{{llvm_dist_label_prefix}}bin/{bin_name}", +)""".format(name = name, bin_name = name + ext) tool_target_strs.append(template) return "\n".join(lib_target_strs + tool_target_strs).format( diff --git a/toolchain/internal/repo.bzl b/toolchain/internal/repo.bzl index 99e2ee3d2..dcc827922 100644 --- a/toolchain/internal/repo.bzl +++ b/toolchain/internal/repo.bzl @@ -14,7 +14,6 @@ load( "//toolchain/internal:common.bzl", _attr_dict = "attr_dict", - _os = "os", _supported_os_arch_keys = "supported_os_arch_keys", ) load( @@ -418,17 +417,16 @@ llvm_config_attrs.update({ }) def llvm_repo_impl(rctx): - os = _os(rctx) - if os == "windows": - rctx.file("BUILD.bazel", executable = False) - return None - llvm_version = _required_llvm_version_rctx(rctx) major_llvm_version = int(llvm_version.split(".")[0]) + if rctx.os.name.startswith("windows"): + template_file_label = "//toolchain:BUILD.llvm_repo_windows.tpl" + else: + template_file_label = "//toolchain:BUILD.llvm_repo.tpl" rctx.file( "BUILD.bazel", - content = rctx.read(Label("//toolchain:BUILD.llvm_repo.tpl")).format( + content = rctx.read(Label(template_file_label)).format( # The versioning changed. LLVM_VERSION = major_llvm_version if major_llvm_version >= 16 else llvm_version, ), From ea004bd27fffbaf075afee39682cc7befb8f2129 Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Thu, 18 Dec 2025 19:23:20 +0100 Subject: [PATCH 02/12] Disable `cxx_builtin_include_directories` temporarily for Windows target --- toolchain/internal/configure.bzl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/toolchain/internal/configure.bzl b/toolchain/internal/configure.bzl index 541816082..22698dcd4 100644 --- a/toolchain/internal/configure.bzl +++ b/toolchain/internal/configure.bzl @@ -404,10 +404,19 @@ def _cc_toolchain_str( _join(sysroot_prefix, "/System/Library/Frameworks"), ]) elif target_os == "windows": - if sysroot_prefix: - cxx_builtin_include_directories.extend([ - _join(sysroot_prefix, "/Include"), - ]) + # TODO: getting this error otherwise: + # ERROR: C:/temp/k7ozco62/external/toolchains_llvm++llvm+llvm_toolchain/BUILD.bazel:764:13: in cc_toolchain rule @@toolchains_llvm++llvm+llvm_toolchain//:cc-clang-aarch64-windows: + # Traceback (most recent call last): + # File "/virtual_builtins_bzl/common/cc/cc_toolchain.bzl", line 133, column 45, in _cc_toolchain_impl + # File "/virtual_builtins_bzl/common/cc/cc_toolchain_provider_helper.bzl", line 238, column 64, in get_cc_toolchain_provider + # File "/virtual_builtins_bzl/common/cc/cc_toolchain_provider_helper.bzl", line 143, column 17, in _resolve_include_dir + # Error in fail: A %sysroot% prefix is only allowed if the default_sysroot option is set + # ERROR: C:/temp/k7ozco62/external/toolchains_llvm++llvm+llvm_toolchain/BUILD.bazel:764:13: Analysis of target '@@toolchains_llvm++llvm+llvm_toolchain//:cc-clang-aarch64-windows' (config: 40e6e70) failed + # + # if sysroot_prefix: + # cxx_builtin_include_directories.extend([ + # _join(sysroot_prefix, "/Include"), + # ]) pass elif target_os == "none" or target_os == "wasip1": if sysroot_prefix: From 14e160f586bc0933391464e94e544b98f0366220 Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Thu, 18 Dec 2025 20:04:31 +0100 Subject: [PATCH 03/12] Clean TODOs --- toolchain/cc_toolchain_config.bzl | 36 +++++++++++++++---------------- toolchain/internal/configure.bzl | 14 ++++-------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 7a6bec8ef..6d86ebadd 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -163,16 +163,16 @@ def cc_toolchain_config( "x64_windows", "msvc", "clang-cl", - "windows_x86_64", # TODO: is that correct? - "windows_x86_64", # TODO: is that correct? + "unknown", + "unknown", ), "windows-aarch64": ( "clang-aarch64-windows", "arm64_windows", "msvc", "clang-cl", - "windows_aarch64", # TODO: is that correct? - "windows_aarch64", # TODO: is that correct? + "unknown", + "unknown", ), }[target_os_arch_key] @@ -206,7 +206,7 @@ def cc_toolchain_config( "/D_WIN32", "/D_WINDOWS", "/clang:-fdebug-prefix-map={}=__bazel_toolchain_llvm_repo__/".format(toolchain_path_prefix), - "/clang-I{}/Include".format(sysroot_path), # TODO: is that needed now? + "/clang-I{}/Include".format(sysroot_path), ]) else: compile_flags.extend([ @@ -339,7 +339,6 @@ def cc_toolchain_config( "-lunwind", ] elif target_os == "windows": - # TODO: should we do something about that case for Windows? pass else: # For single-platform builds, we can statically link the bundled @@ -521,19 +520,13 @@ def cc_toolchain_config( target_libc = target_libc, abi_version = abi_version, abi_libc_version = abi_libc_version, - # msvc_env_tmp = "%{clang_cl_env_tmp_arm64}", # TODO - # msvc_env_path = "%{clang_cl_env_path_arm64}", # TODO - # TODO: should we support that? - # TODO: these relative path are not working here, but I don't know how to resolve a path that would work for everything msvc_env_include = ";".join([ - "{}/Include".format(sysroot_path), # TODO: is that needed now? - ]), # TODO: should we depend also on cxx includes here? Like: + [i.replace("%workspace%/", "") for i in cxx_builtin_include_directories]), - # TODO: should we support that? + "{}/Include".format(sysroot_path), + ]), # msvc_env_lib = ";".join([ # "{}/Lib".format(sysroot_path), # ]), msvc_cl_path = tool_paths["gcc"], - # msvc_ml_path = tool_paths["ml"], # TODO msvc_link_path = tool_paths["ld"], msvc_lib_path = tool_paths["llvm-lib"], cxx_builtin_include_directories = cxx_builtin_include_directories, @@ -545,11 +538,16 @@ def cc_toolchain_config( fastbuild_mode_debug_flag = " ".join(fastbuild_compile_flags), supports_parse_showincludes = False, - # TODO: what to do with these? - # opt_compile_flags = opt_compile_flags, - # conly_flags = conly_flags, - # cxx_flags = cxx_flags, - # link_libs = link_libs, + # The following attributes are not yet supported (we had no need for it): + # msvc_env_tmp = + # msvc_env_path = + # msvc_ml_path = + # + # The following variables are not used on Windows toolchains: + # - opt_compile_flags + # - conly_flags + # - cxx_flags + # - link_libs ) else: # Source: https://cs.opensource.google/bazel/bazel/+/master:tools/cpp/unix_cc_toolchain_config.bzl diff --git a/toolchain/internal/configure.bzl b/toolchain/internal/configure.bzl index 22698dcd4..ee049906c 100644 --- a/toolchain/internal/configure.bzl +++ b/toolchain/internal/configure.bzl @@ -90,10 +90,7 @@ def llvm_config_impl(rctx): use_absolute_paths_sysroot = use_absolute_paths_llvm if os == "windows": - # FIXME: this is a hack, it must be addressed - # - # Windows has an issue resolving symlinks in the execroot. - # So for now we force `absolute_paths = True` as a hack + # TODO: Windows has an issue resolving symlinks in the execroot, so for now we force `absolute_paths = True` as a hack # # Here is an example of failure: # ERROR: C:/users/titouan.bion/developer_windows/ultimate/fleet/native/launcher/BUILD.bazel:10:12: Compiling Rust bin fleet (15 files) failed: error reading file '@@toolchains_llvm++llvm+llvm_toolchain//:bin/llvm-nm.exe': @@ -106,6 +103,7 @@ def llvm_config_impl(rctx): # $ dir C:/temp/k7ozco62/external/toolchains_llvm++llvm+llvm_toolchain/bin # shows `d----l` file modes on binaries # $ bazelisk.exe build //fleet/native/launcher:fleet # WORKS # $ dir C:/temp/k7ozco62/external/toolchains_llvm++llvm+llvm_toolchain/bin # shows `-a----` file modes on binaries + # use_absolute_paths_llvm = True # Check if the toolchain root is a system path. @@ -404,12 +402,8 @@ def _cc_toolchain_str( _join(sysroot_prefix, "/System/Library/Frameworks"), ]) elif target_os == "windows": - # TODO: getting this error otherwise: - # ERROR: C:/temp/k7ozco62/external/toolchains_llvm++llvm+llvm_toolchain/BUILD.bazel:764:13: in cc_toolchain rule @@toolchains_llvm++llvm+llvm_toolchain//:cc-clang-aarch64-windows: - # Traceback (most recent call last): - # File "/virtual_builtins_bzl/common/cc/cc_toolchain.bzl", line 133, column 45, in _cc_toolchain_impl - # File "/virtual_builtins_bzl/common/cc/cc_toolchain_provider_helper.bzl", line 238, column 64, in get_cc_toolchain_provider - # File "/virtual_builtins_bzl/common/cc/cc_toolchain_provider_helper.bzl", line 143, column 17, in _resolve_include_dir + # TODO: when uncommented, we are getting: + # # Error in fail: A %sysroot% prefix is only allowed if the default_sysroot option is set # ERROR: C:/temp/k7ozco62/external/toolchains_llvm++llvm+llvm_toolchain/BUILD.bazel:764:13: Analysis of target '@@toolchains_llvm++llvm+llvm_toolchain//:cc-clang-aarch64-windows' (config: 40e6e70) failed # From b03daa2c3c8721055d547ec92dc3f8836bf5388d Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Thu, 18 Dec 2025 20:04:31 +0100 Subject: [PATCH 04/12] Clarify TODOs Deleting redundant keep only to be discussed. --- toolchain/cc_toolchain_config.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 6d86ebadd..6a3c118b0 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -233,7 +233,7 @@ def cc_toolchain_config( "-fdata-sections", ] - if compiler == "clang-cl": # TODO: we should actually check if the linker is `lld-link` instead + if compiler == "clang-cl": # TODO: technically it should be a check if the linker is `lld-link` instead, but we don't declare such value link_flags = [ # The --target flag is for some uninvestigated yet reason required for Cargo build script to work on Windows ARM, otherwise it fails with: # ERROR: C:/temp/k7ozco62/external/rules_rust++crate+fleet_crates__windows_aarch64_msvc-0.52.6/BUILD.bazel:75:19: @@ -255,7 +255,7 @@ def cc_toolchain_config( link_flags.append("--ld-path=ld64.lld" if target_os == "darwin" else "--ld-path=ld.lld") stdlib = compiler_configuration["stdlib"] - if stdlib != "none" and compiler != "clang-cl": # TODO: we should actually check if the linker is `lld-link` instead + if stdlib != "none" and compiler != "clang-cl": # TODO: technically it should be a check if the linker is `lld-link` instead, but we don't declare such value link_flags.extend([ "-lm", ]) From 7e4b81a5ff75943a60fe0d490c1c4e03570e62f2 Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Sun, 21 Dec 2025 23:47:30 +0100 Subject: [PATCH 05/12] Ensure backward compatibility with custom-build LLVM toolchains --- toolchain/BUILD.llvm_repo.tpl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/toolchain/BUILD.llvm_repo.tpl b/toolchain/BUILD.llvm_repo.tpl index 230d29d20..9ed0fee8c 100644 --- a/toolchain/BUILD.llvm_repo.tpl +++ b/toolchain/BUILD.llvm_repo.tpl @@ -44,8 +44,10 @@ filegroup( srcs = [ "bin/ld.lld", "bin/ld64.lld", + ] + glob([ + "bin/wasm-ld", "bin/lld-link", - ] + glob(["bin/wasm-ld"], allow_empty = True), + ], allow_empty = True), ) filegroup( From c16ca8a7cdfe796165f6ed0039f4f560738a848e Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Sun, 21 Dec 2025 23:53:12 +0100 Subject: [PATCH 06/12] Use a more idiomatic key mutation (review comment) --- toolchain/internal/common.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchain/internal/common.bzl b/toolchain/internal/common.bzl index fd68c51ed..397b0bbbc 100644 --- a/toolchain/internal/common.bzl +++ b/toolchain/internal/common.bzl @@ -276,7 +276,7 @@ def toolchain_tools(os): tools = dict() binary_ext = ".exe" for bin, symlink in _toolchain_tools.items(): - tools.update({bin + binary_ext: symlink + binary_ext}) + tools[bin + binary_ext] = symlink + binary_ext elif os == "darwin": tools = dict(_toolchain_tools) tools.update(_toolchain_tools_darwin) From a864350b3d7c4c2dc7b387d12c226f4de8e2d493 Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Sun, 21 Dec 2025 23:58:06 +0100 Subject: [PATCH 07/12] Remove UNIX specific libraires from Windows repo toolchain (review comment) --- toolchain/BUILD.llvm_repo_windows.tpl | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/toolchain/BUILD.llvm_repo_windows.tpl b/toolchain/BUILD.llvm_repo_windows.tpl index 386b5b856..038c77cb6 100644 --- a/toolchain/BUILD.llvm_repo_windows.tpl +++ b/toolchain/BUILD.llvm_repo_windows.tpl @@ -104,8 +104,6 @@ filegroup( # not be available at runtime to allow sanitizers to work locally. # Any library linked from the toolchain to be released should be linked statically. "lib/clang/{LLVM_VERSION}/lib/**", - "lib/**/libc++*.a", - "lib/**/libunwind.a", ], allow_empty = True), ) @@ -217,12 +215,5 @@ filegroup( filegroup( name = "libclang", - srcs = glob( - [ - "lib/libclang.so", - "lib/libclang.dylib", - "lib/libclang.lib", - ], - allow_empty = True, - ), + srcs = ["lib/libclang.lib"], ) From 7dcecbc61ee80c9d7caf2a7fc55cb646d932bf0d Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Mon, 22 Dec 2025 00:04:35 +0100 Subject: [PATCH 08/12] Remove Windows libclang, never relevant --- toolchain/BUILD.llvm_repo.tpl | 1 - 1 file changed, 1 deletion(-) diff --git a/toolchain/BUILD.llvm_repo.tpl b/toolchain/BUILD.llvm_repo.tpl index 9ed0fee8c..255e35905 100644 --- a/toolchain/BUILD.llvm_repo.tpl +++ b/toolchain/BUILD.llvm_repo.tpl @@ -190,7 +190,6 @@ filegroup( [ "lib/libclang.so", "lib/libclang.dylib", - "lib/libclang.lib", ], allow_empty = True, ), From f8e038e44d9529e5c760eed350a76759b6ce473c Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Mon, 22 Dec 2025 00:04:45 +0100 Subject: [PATCH 09/12] Fix comments --- toolchain/BUILD.llvm_repo_windows.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchain/BUILD.llvm_repo_windows.tpl b/toolchain/BUILD.llvm_repo_windows.tpl index 038c77cb6..ea067c550 100644 --- a/toolchain/BUILD.llvm_repo_windows.tpl +++ b/toolchain/BUILD.llvm_repo_windows.tpl @@ -90,7 +90,7 @@ filegroup( filegroup( name = "lib", srcs = [ - # Include the .dylib files in the linker sandbox even though they will + # Include the .lib files in the linker sandbox even though they will # not be available at runtime to allow sanitizers to work locally. # Any library linked from the toolchain to be released should be linked statically. "lib/clang/{LLVM_VERSION}/lib", @@ -100,7 +100,7 @@ filegroup( filegroup( name = "lib_legacy", srcs = glob([ - # Include the .dylib files in the linker sandbox even though they will + # Include the .lib files in the linker sandbox even though they will # not be available at runtime to allow sanitizers to work locally. # Any library linked from the toolchain to be released should be linked statically. "lib/clang/{LLVM_VERSION}/lib/**", From 944bd4caaf9e5e8eae849ee3d27c935c16f4108a Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Mon, 22 Dec 2025 00:15:56 +0100 Subject: [PATCH 10/12] Fix cross-compilation `gcc` tool call on Windows --- toolchain/cc_toolchain_config.bzl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index 6a3c118b0..ca1c64338 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -430,6 +430,13 @@ def cc_toolchain_config( if exec_os == "windows": binary_ext = ".exe" + if target_os == "windows": + gcc_tool = tools_path_prefix + "clang-cl" + binary_ext + elif exec_os == "windows": + gcc_tool = tools_path_prefix + "clang" + binary_ext + else: + gcc_tool = wrapper_bin_prefix + "cc_wrapper.sh" + # The requirements here come from # https://cs.opensource.google/bazel/bazel/+/master:src/main/starlark/builtins_bzl/common/cc/cc_toolchain_provider_helper.bzl;l=75;drc=f0150efd1cca473640269caaf92b5a23c288089d # https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/rules/cpp/CcModule.java;l=1257;drc=6743d76f9ecde726d592e88d8914b9db007b1c43 @@ -440,7 +447,7 @@ def cc_toolchain_config( "ar": tools_path_prefix + ("llvm-ar" if not use_libtool else "libtool") + binary_ext, "cpp": tools_path_prefix + "clang-cpp" + binary_ext, "dwp": tools_path_prefix + "llvm-dwp" + binary_ext, - "gcc": tools_path_prefix + "clang-cl" + binary_ext if target_os == "windows" else wrapper_bin_prefix + "cc_wrapper.sh", + "gcc": gcc_tool, "gcov": tools_path_prefix + "llvm-profdata" + binary_ext, "ld": tools_path_prefix + "lld-link" + binary_ext if target_os == "windows" else tools_path_prefix + "ld.lld" + binary_ext, "llvm-lib": tools_path_prefix + "llvm-lib" + binary_ext, From 96cdedd9f4be889ddd63bd7fc77df5f7a29cb568 Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Mon, 22 Dec 2025 16:29:28 +0100 Subject: [PATCH 11/12] Fix backward compatibility with eventual custom LLVM toolchains --- toolchain/BUILD.llvm_repo.tpl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/toolchain/BUILD.llvm_repo.tpl b/toolchain/BUILD.llvm_repo.tpl index 255e35905..fa4f2545b 100644 --- a/toolchain/BUILD.llvm_repo.tpl +++ b/toolchain/BUILD.llvm_repo.tpl @@ -33,9 +33,10 @@ filegroup( "bin/clang", "bin/clang++", "bin/clang-cpp", + ] + glob([ "bin/clang-cl", "bin/lld-link", - ], + ], allow_empty = True), ) filegroup( From e68cd8f262217b8c9753bc15a852b2088b6f25ab Mon Sep 17 00:00:00 2001 From: Titouan Bion Date: Mon, 22 Dec 2025 16:44:52 +0100 Subject: [PATCH 12/12] Drop support for `lib_legacy` on Windows hosts --- toolchain/BUILD.llvm_repo_windows.tpl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/toolchain/BUILD.llvm_repo_windows.tpl b/toolchain/BUILD.llvm_repo_windows.tpl index ea067c550..10a862eed 100644 --- a/toolchain/BUILD.llvm_repo_windows.tpl +++ b/toolchain/BUILD.llvm_repo_windows.tpl @@ -99,12 +99,7 @@ filegroup( filegroup( name = "lib_legacy", - srcs = glob([ - # Include the .lib files in the linker sandbox even though they will - # not be available at runtime to allow sanitizers to work locally. - # Any library linked from the toolchain to be released should be linked statically. - "lib/clang/{LLVM_VERSION}/lib/**", - ], allow_empty = True), + srcs = [], # no reported Windows exec usage on older version of Bazel ) filegroup(