Skip to content

Fix clang version parsing on Windows.#626

Open
polasek wants to merge 2 commits intobazelbuild:mainfrom
polasek:jan/fix-clang-version-parsing
Open

Fix clang version parsing on Windows.#626
polasek wants to merge 2 commits intobazelbuild:mainfrom
polasek:jan/fix-clang-version-parsing

Conversation

@polasek
Copy link

@polasek polasek commented Mar 11, 2026

The official Windows release of Clang 22 changed the output format of -v.

$ clang -v
clang version 22.1.1 (https://github.com/llvm/llvm-project fef02d48c08db859ef83f84232ed78bd9d1c323a)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

This makes version parsing fail, and in turn leads to failed compilation for basically any C++ code as the version is used for cxx_builtin_include_directories. Without the change in this PR, I get

cxx_builtin_include_directories = [
    ...
    "C:\\Program Files\\LLVM\\lib\\clang\\fef02d48c08db859ef83f84232ed78bd9d1c323a)\\include"
],

instead of "C:\\Program Files\\LLVM\\lib\\clang\\22\\include" in the autoconfigured toolchain.

Compiling

#include <iostream>
int main() { return 0; }

then fails with:

ERROR: C:/users/jan/code/rules_cc_clang_cl_llvm22_repro/BUILD:3:8: Compiling main.cc failed: absolute path inclusion(s) found in rule '//:test':
the source file 'main.cc' includes the following non-builtin files with absolute paths (if these are builtin files, make sure these paths are in your toolchain):
  'C:/Program Files/LLVM/lib/clang/22/include/yvals_core.h'
  'C:/Program Files/LLVM/lib/clang/22/include/vadefs.h'
  'C:/Program Files/LLVM/lib/clang/22/include/yvals_core.h'
...

I didn't find any tests for this or any easy way of adding them but please let me know if I missed something.

version_start = first_line.find("clang version ")
if version_start == -1:
auto_configure_fail("Failed to get clang version: unknown version string format: \"%s\"" % first_line)
return first_line[version_start + len("clang version "):].split(" ")[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a shared variable rather than duplicating "clang version ".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@armandomontanez armandomontanez added type: bug Something that should be working isn't working P2 We'll consider working on this in future. (Assignee optional) platform: windows category: toolchains labels Mar 11, 2026
Copy link
Collaborator

@armandomontanez armandomontanez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

This will merge per the merge process pending additional approvals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: toolchains P2 We'll consider working on this in future. (Assignee optional) platform: windows type: bug Something that should be working isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants