diff --git a/platforms/BUILD.bazel b/platforms/BUILD.bazel index d9c7140dc..3d78b56a8 100644 --- a/platforms/BUILD.bazel +++ b/platforms/BUILD.bazel @@ -45,3 +45,11 @@ platform( "@platforms//cpu:aarch64", ], ) + +platform( + name = "windows-x86_64", + constraint_values = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], +) diff --git a/toolchain/BUILD.llvm_repo_windows b/toolchain/BUILD.llvm_repo_windows new file mode 100644 index 000000000..baca19e4f --- /dev/null +++ b/toolchain/BUILD.llvm_repo_windows @@ -0,0 +1,170 @@ +# 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/*", +])) + +## LLVM toolchain files + +ALL_DLLS = glob(["bin/*.dll"]) + +filegroup( + name = "clang", + srcs = [ + "bin/clang.exe", + "bin/clang++.exe", + "bin/clang-cpp.exe", + "bin/clang-cl.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "clang-cl", + srcs = [ + "bin/clang-cl.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "llvm-ml", + srcs = [ + "bin/llvm-ml.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "ld", + # a set of 4 identical binaries? + srcs = ["bin/ld.lld.exe", "bin/ld64.lld.exe", "lld-link.exe", "lld.exe"] + ALL_DLLS, +) + +filegroup( + name = "lld-link", + srcs = [ + "bin/lld-link.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "llvm-lib", + srcs = [ + "bin/llvm-lib.exe", + ] + ALL_DLLS, +) + +filegroup( + name = "include", + srcs = glob([ + "include/**/c++/**", + "lib/clang/*/include/**", + ]), +) + +filegroup( + name = "all_includes", + srcs = glob(["include/**"]), +) + +filegroup( + name = "bin", + srcs = glob(["bin/**"]), +) + +filegroup( + name = "lib", + srcs = glob( + [ + "lib/**/*.lib", + ], + exclude = [ + "lib/LLVM*.lib", + "lib/clang*.lib", + "lib/lld*.lib", + ], + ), +) + +filegroup( + name = "dll", + srcs = ALL_DLLS, +) + +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 = "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, +) diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl index c1b0d9226..f5cc8b51e 100644 --- a/toolchain/cc_toolchain_config.bzl +++ b/toolchain/cc_toolchain_config.bzl @@ -89,6 +89,14 @@ def cc_toolchain_config( "clang", "glibc_unknown", ), + "windows-x86_64": ( + "clang-x86_64-windows", + "k8", + "msvc", + "clang", + "windows_x86_64", + "windows_x86_64", + ), }[target_os_arch_key] # Unfiltered compiler flags; these are placed at the end of the command diff --git a/toolchain/internal/common.bzl b/toolchain/internal/common.bzl index ff94bfb22..d3a7d631c 100644 --- a/toolchain/internal/common.bzl +++ b/toolchain/internal/common.bzl @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -SUPPORTED_TARGETS = [("linux", "x86_64"), ("linux", "aarch64"), ("darwin", "x86_64"), ("darwin", "aarch64")] +SUPPORTED_TARGETS = [("linux", "x86_64"), ("linux", "aarch64"), ("darwin", "x86_64"), ("darwin", "aarch64"), ("windows", "x86_64")] # Map of tool name to its symlinked name in the tools directory. # See tool_paths in toolchain/cc_toolchain_config.bzl. @@ -104,7 +104,7 @@ def os(rctx): name = rctx.attr.exec_os if name: - if name in ("linux", "darwin"): + if name in ("linux", "darwin", "windows"): return name else: fail("Unsupported value for exec_os: %s" % name) @@ -120,7 +120,7 @@ def os(rctx): def os_bzl(os): # Return the OS string as used in bazel platform constraints. - return {"darwin": "osx", "linux": "linux"}[os] + return {"darwin": "osx", "linux": "linux", "windows": "windows"}[os] def arch(rctx): arch = rctx.attr.exec_arch diff --git a/toolchain/internal/configure.bzl b/toolchain/internal/configure.bzl index 6e40059cf..6840d318a 100644 --- a/toolchain/internal/configure.bzl +++ b/toolchain/internal/configure.bzl @@ -61,9 +61,6 @@ def llvm_config_impl(rctx): _check_os_arch_keys(rctx.attr.cxx_builtin_include_directories) os = _os(rctx) - if os == "windows": - _empty_repository(rctx) - return arch = _arch(rctx) if not rctx.attr.toolchain_roots: @@ -311,6 +308,7 @@ def _cc_toolchain_str( "darwin-aarch64": "aarch64-apple-macosx", "linux-aarch64": "aarch64-unknown-linux-gnu", "linux-x86_64": "x86_64-unknown-linux-gnu", + "windows-x86_64": "x86_64-pc-windows-msvc", }[target_pair] cxx_builtin_include_directories = [ toolchain_path_prefix + "include/c++/v1", @@ -338,7 +336,7 @@ def _cc_toolchain_str( _join(sysroot_prefix, "/System/Library/Frameworks"), ]) else: - fail("Unreachable") + pass cxx_builtin_include_directories.extend(toolchain_info.additional_include_dirs_dict.get(target_pair, [])) @@ -545,7 +543,13 @@ cc_toolchain( major_llvm_version = major_llvm_version, ) +def _extension(os): + if os == "windows": + return ".exe" + return "" + def _convenience_targets_str(rctx, use_absolute_paths, llvm_dist_rel_path, llvm_dist_label_prefix, exec_dl_ext): + ext = _extension(_os(rctx)) if use_absolute_paths: llvm_dist_label_prefix = ":" filenames = [] @@ -553,7 +557,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: @@ -570,6 +574,7 @@ cc_import( tool_target_strs = [] for name in _aliased_tools: + name = name + ext template = """ native_binary( name = "{name}", diff --git a/toolchain/internal/release_name.bzl b/toolchain/internal/release_name.bzl index e3d4a540d..a56adabcc 100755 --- a/toolchain/internal/release_name.bzl +++ b/toolchain/internal/release_name.bzl @@ -46,6 +46,16 @@ def _darwin(llvm_version, arch): ) def _windows(llvm_version, arch): + major_llvm_version = _major_llvm_version(llvm_version) + if major_llvm_version >= 18 and arch.endswith("64"): + arch = "x86_64" + suffix = "pc-windows-msvc" + return "clang+llvm-{llvm_version}-{arch}-{suffix}.tar.xz".format( + llvm_version = llvm_version, + arch = arch, + suffix = suffix, + ) + if arch.endswith("64"): win_arch = "win64" else: diff --git a/toolchain/internal/repo.bzl b/toolchain/internal/repo.bzl index 27012db6f..3b2899d02 100644 --- a/toolchain/internal/repo.bzl +++ b/toolchain/internal/repo.bzl @@ -291,14 +291,17 @@ llvm_config_attrs.update({ def llvm_repo_impl(rctx): os = _os(rctx) if os == "windows": - rctx.file("BUILD.bazel", executable = False) - return None - - rctx.file( - "BUILD.bazel", - content = rctx.read(Label("//toolchain:BUILD.llvm_repo")), - executable = False, - ) + rctx.file( + "BUILD.bazel", + content = rctx.read(Label("//toolchain:BUILD.llvm_repo_windows")), + executable = False, + ) + else: + rctx.file( + "BUILD.bazel", + content = rctx.read(Label("//toolchain:BUILD.llvm_repo")), + executable = False, + ) updated_attrs = _download_llvm(rctx)