Repository navigation
llvmPackages.clang-tools: add support for -cxx-isystem - #462747
Conversation
This is necessary after NixOS#445095, which moved libc++ to -cxx-isystem to improve compatibility with build systems that invoke `clang` to compile C++ code.
3cd4168 to
d46fa26
Compare
|
Targeting to staging due to the number of rebuilds. |
|
Does this PR Does this PR need to land on master? |
|
It’s currently going through staging-next. |
|
Since this is a crucial component to have |
|
It has to go through staging due to the number of rebuilds it would cause. If you really need the fix, you can try using the staging-next branch. Note that some of the packages you use may not have been built yet. |
|
I just want to second that this has made |
|
for my personal projects, I created an overlay, putting that in a file in with content # Locally applying PR 462747, which modifies the wrapper, that ends up named
# clangd in the final package. So patch that `clangd` script with that change.
# The patch contains a path to the wrapper, but we apply it directly to the
# clangd script where it ends up in.
##
# Define a transformation, then apply it to all llvm versions of interest.
final: prev:
let
# Transformations for each version
patchClangTools = llvmPkgSet: llvmPkgSet.overrideScope (lfinal: lprev: {
clang-tools = lprev.clang-tools.overrideAttrs (oldAttrs: {
postInstall = (oldAttrs.postInstall or "") + ''
echo "Applying PR 462747 patch to the generated clangd wrapper..."
patch -i ${prev.fetchpatch {
url = "https://github.com/NixOS/nixpkgs/pull/462747.diff";
hash = "sha256-WDP/WJAflkYw8YQDgXK3q9G7/Z6BXTu7QpNGAKjO3co=";
}} $out/bin/clangd
'';
});
});
# ... all the llvm version we'd like to apply this to
llvm_versions = [ "17" "18" "19" "20" "21" ];
in
prev.lib.genAttrs (map (v: "llvmPackages_${v}") llvm_versions) (name:
patchClangTools prev.${name}
)
So using clang-tools now |
This makes `clangd` work again, thanks to NixOS/nixpkgs#462747 • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/c6245e83d836d0433170a16eb185cefe0572f8b8' (2025-12-18) → 'https://releases.nixos.org/nixos/25.11/nixos-25.11.2222.b3aad468604d/nixexprs.tar.xz?lastModified=1766201043&narHash=sha256-v9nbQe0BgwBx%2BKcxRf6i2kbS8EwKjBFRjAawA91B/OE%3D&rev=b3aad468604d3e488d627c0b43984eb60e75e782' (2025-12-20) Signed-off-by: Seth Flynn <[email protected]>
This makes `clangd` work again, thanks to NixOS/nixpkgs#462747 • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/c6245e83d836d0433170a16eb185cefe0572f8b8' (2025-12-18) → 'https://releases.nixos.org/nixos/25.11/nixos-25.11.2222.b3aad468604d/nixexprs.tar.xz?lastModified=1766201043&narHash=sha256-v9nbQe0BgwBx%2BKcxRf6i2kbS8EwKjBFRjAawA91B/OE%3D&rev=b3aad468604d3e488d627c0b43984eb60e75e782' (2025-12-20) Signed-off-by: Seth Flynn <[email protected]> (cherry picked from commit 5ee3381)
|
Also now added in master #475078 |
|
A backport to 25.11 would be very appreciated since clangd is unusable for cpp on 25.11 otherwise |
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
|
The backport PR was #462884. The fix should already be in release-25.11. |
Without this change, building with -DMP_ENABLE_IWYU=ON and newer versions of nixpkgs (after 2025-11-12) fails with mysterious errors that look like: make[2]: *** [CMakeFiles/mputil.dir/build.make:79: CMakeFiles/mputil.dir/src/mp/util.cpp.o] Error 1 with no other error messages. The are no messages because cmake -E __run_co_compile hides the output from IWYU and does not display anything itself. The actual problem is missing include directories on the compiler command line, and the fix here is to extend a workaround previously added for clang-tidy to be used for IWYU as well. Breakage seems to have been caused by NixOS/nixpkgs@76a8ffa from NixOS/nixpkgs#445095, which I found by bisecting with --first-parent to a change between the following merge commit: https://github.com/NixOS/nixpkgs/commits/de21549a840be528ef4763dd7dca2006caf9c11f (bad) https://github.com/NixOS/nixpkgs/commits/c4d1151093af5d483d1900d9214a65e68bc21560 (good) If you check out the bad commit above (or any later commit) and revert NixOS/nixpkgs@76a8ffa the problem disappears. I suspect the problem happens because cmake is not handling -cxx-isystem properly, but did not debug further. The later change NixOS/nixpkgs#462747 which followed up on NixOS/nixpkgs#445095 did not seem to have any effect on this issue in my testing.
The workaround was added in 977d721 so clang-tidy could find headers that nix compiler wrappers inject internally, but the nixpkgs bug motivating it has since been fixed upstream (NixOS/nixpkgs#462747). IWYU is now the tool that still needs it, due to a separate nixpkgs bug where the include-what-you-use wrapper script drops the -cxx-isystem flags newer compiler wrappers use for C++ standard library paths. Update the comment to describe the current situation and mark the workaround as removable once the remaining bug is fixed. Co-Authored-By: Claude Fable 5 <[email protected]>
The workaround was added in 977d721 so clang-tidy could find headers that nix compiler wrappers inject internally. Its comment has since become inaccurate and misleading: - It names clang-tidy as the tool that needs the workaround, but clang-tidy no longer does: the nixpkgs clang-tools wrapper was fixed upstream (NixOS/nixpkgs#462747). IWYU is the tool that needs it now. - It says the tool "ignores $NIX_CFLAGS_COMPILE." In fact the nixpkgs analysis-tool wrappers do read $NIX_CFLAGS_COMPILE and re-add its paths. - It says the missing headers are capnp (dependency) headers. That is backwards: dependency headers are passed via -isystem in $NIX_CFLAGS_COMPILE and are found. The headers that go missing are the C++ standard library headers (e.g. <cstddef>), because the include-what-you-use wrapper drops the -cxx-isystem flags those use. - It pins the whole mechanism on $NIX_CFLAGS_COMPILE, omitting that standard library paths are injected through the compiler wrapper's own flag files, and it neither explains why the tools normally cope nor that the workaround only compensates for a temporary wrapper bug. Rewrite the comment to describe the nix header-injection mechanism from first principles, identify IWYU's dropped -cxx-isystem flags as the specific reason the workaround is still needed, and note that it is removable once that wrapper bug is fixed upstream. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Without this change, building with -DMP_ENABLE_IWYU=ON and newer versions of nixpkgs (after 2025-11-12) fails with mysterious errors that look like: make[2]: *** [CMakeFiles/mputil.dir/build.make:79: CMakeFiles/mputil.dir/src/mp/util.cpp.o] Error 1 with no other error messages. The are no messages because cmake -E __run_co_compile hides the output from IWYU and does not display anything itself. The actual problem is missing include directories on the compiler command line, and the fix here is to extend a workaround previously added for clang-tidy to be used for IWYU as well. Breakage seems to have been caused by NixOS/nixpkgs@76a8ffa from NixOS/nixpkgs#445095, which I found by bisecting with --first-parent to a change between the following merge commit: https://github.com/NixOS/nixpkgs/commits/de21549a840be528ef4763dd7dca2006caf9c11f (bad) https://github.com/NixOS/nixpkgs/commits/c4d1151093af5d483d1900d9214a65e68bc21560 (good) If you check out the bad commit above (or any later commit) and revert NixOS/nixpkgs@76a8ffa the problem disappears. I suspect the problem happens because cmake is not handling -cxx-isystem properly, but did not debug further. The later change NixOS/nixpkgs#462747 which followed up on NixOS/nixpkgs#445095 did not seem to have any effect on this issue in my testing.
The workaround was added in 977d721 so clang-tidy could find headers that nix compiler wrappers inject internally. Its comment has since become inaccurate and misleading: - It names clang-tidy as the tool that needs the workaround, but clang-tidy no longer does: the nixpkgs clang-tools wrapper was fixed upstream (NixOS/nixpkgs#462747). IWYU is the tool that needs it now. - It says the tool "ignores $NIX_CFLAGS_COMPILE." In fact the nixpkgs analysis-tool wrappers do read $NIX_CFLAGS_COMPILE and re-add its paths. - It says the missing headers are capnp (dependency) headers. That is backwards: dependency headers are passed via -isystem in $NIX_CFLAGS_COMPILE and are found. The headers that go missing are the C++ standard library headers (e.g. <cstddef>), because the include-what-you-use wrapper drops the -cxx-isystem flags those use. - It pins the whole mechanism on $NIX_CFLAGS_COMPILE, omitting that standard library paths are injected through the compiler wrapper's own flag files, and it neither explains why the tools normally cope nor that the workaround only compensates for a temporary wrapper bug. Rewrite the comment to describe the nix header-injection mechanism from first principles, identify IWYU's dropped -cxx-isystem flags as the specific reason the workaround is still needed, and note that it is removable once that wrapper bug is fixed upstream. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The workaround was added in 977d721 so clang-tidy could find headers that nix compiler wrappers inject internally. Its comment has since become inaccurate and misleading: - It names clang-tidy as the tool that needs the workaround, but clang-tidy no longer does: the nixpkgs clang-tools wrapper was fixed upstream (NixOS/nixpkgs#462747). IWYU is the tool that needs it now. - It says the tool "ignores $NIX_CFLAGS_COMPILE." In fact the nixpkgs analysis-tool wrappers do read $NIX_CFLAGS_COMPILE and re-add its paths. - It says the missing headers are capnp (dependency) headers. That is backwards: dependency headers are passed via -isystem in $NIX_CFLAGS_COMPILE and are found. The headers that go missing are the C++ standard library headers (e.g. <cstddef>), because the include-what-you-use wrapper drops the -cxx-isystem flags those use. - It pins the whole mechanism on $NIX_CFLAGS_COMPILE, omitting that standard library paths are injected through the compiler wrapper's own flag files, and it neither explains why the tools normally cope nor that the workaround only compensates for a temporary wrapper bug. Rewrite the comment to describe the nix header-injection mechanism from first principles, identify IWYU's dropped -cxx-isystem flags as the specific reason the workaround is still needed, and note that it is removable once that wrapper bug is fixed upstream. This change was written with Claude Opus 4.8.
clang-tidy no longer needs the CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES workaround. The nixpkgs clang-tools wrapper adds the C++ standard library paths since NixOS/nixpkgs#462747, and the previous commit makes that wrapper, rather than the unwrapped clang-tidy from the clang package, the one found on PATH. Applying the workaround only when it is needed keeps the clang-tidy build closer to a normal one: compile commands no longer carry the compiler's implicit include directories as explicit -isystem flags. This change was written with Claude Opus 5.5.
This is necessary after #445095, which moved libc++ to -cxx-isystem to improve compatibility with build systems that invoke
clangto compile C++ code.Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.