From 4dcc271070acc9fc66c6a279916077e9193d52f4 Mon Sep 17 00:00:00 2001 From: "bazel.build machine account" <15028808+bazel-io@users.noreply.github.com> Date: Thu, 7 Sep 2023 07:56:29 -0400 Subject: [PATCH] [6.4.0] Wrong include path to Clang 16 on Windows (#19430) Clang install on Windows started using just the major version number in the install path rather than the full version number. Fixes https://github.com/bazelbuild/bazel/issues/17863 Closes #19391. Commit https://github.com/bazelbuild/bazel/commit/0377badd52612a3c2185d3e392c53a95fd38890a PiperOrigin-RevId: 562480023 Change-Id: Iebd5d3cedff48739747fa8668d56ff8f1d9350b9 Co-authored-by: Orion Hodson --- tools/cpp/windows_cc_configure.bzl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/cpp/windows_cc_configure.bzl b/tools/cpp/windows_cc_configure.bzl index 5f526ecd1d8bc7..760a8435f99a65 100644 --- a/tools/cpp/windows_cc_configure.bzl +++ b/tools/cpp/windows_cc_configure.bzl @@ -565,6 +565,18 @@ def _get_clang_version(repository_ctx, clang_cl): auto_configure_fail("Failed to get clang version by running \"%s -v\"" % clang_cl) return first_line.split(" ")[-1] +def _get_clang_dir(repository_ctx, llvm_path, clang_version): + """Get the clang installation directory.""" + + # The clang_version string format is "X.X.X" + clang_dir = llvm_path + "\\lib\\clang\\" + clang_version + if repository_ctx.path(clang_dir).exists: + return clang_dir + + # Clang 16 changed the install path to use just the major number. + clang_major_version = clang_version.split(".")[0] + return llvm_path + "\\lib\\clang\\" + clang_major_version + def _get_msys_mingw_vars(repository_ctx): """Get the variables we need to populate the msys/mingw toolchains.""" tool_paths, tool_bin_path, inc_dir_msys = _get_escaped_windows_msys_starlark_content(repository_ctx) @@ -658,7 +670,7 @@ def _get_msvc_vars(repository_ctx, paths, target_arch = "x64", msvc_vars_x64 = N escaped_cxx_include_directories.append("\"%s\"" % path) if llvm_path: clang_version = _get_clang_version(repository_ctx, build_tools["CL"]) - clang_dir = llvm_path + "\\lib\\clang\\" + clang_version + clang_dir = _get_clang_dir(repository_ctx, llvm_path, clang_version) clang_include_path = (clang_dir + "\\include").replace("\\", "\\\\") escaped_cxx_include_directories.append("\"%s\"" % clang_include_path) clang_lib_path = (clang_dir + "\\lib\\windows").replace("\\", "\\\\") @@ -734,7 +746,7 @@ def _get_clang_cl_vars(repository_ctx, paths, msvc_vars, target_arch): llvm_lib_path = find_llvm_tool(repository_ctx, llvm_path, "llvm-lib.exe") clang_version = _get_clang_version(repository_ctx, clang_cl_path) - clang_dir = llvm_path + "\\lib\\clang\\" + clang_version + clang_dir = _get_clang_dir(repository_ctx, llvm_path, clang_version) clang_include_path = (clang_dir + "\\include").replace("\\", "\\\\") clang_lib_path = (clang_dir + "\\lib\\windows").replace("\\", "\\\\")