Skip to content

llvmPackages.clang-tools: add support for -cxx-isystem - #462747

Merged
reckenrode merged 1 commit into
NixOS:stagingfrom
reckenrode:push-oypkqxwyotkn
Nov 18, 2025
Merged

reckenrode merged 1 commit into
NixOS:stagingfrom
reckenrode:push-oypkqxwyotkn

Conversation

@reckenrode

Copy link
Copy Markdown
Contributor

This is necessary after #445095, which moved libc++ to -cxx-isystem to improve compatibility with build systems that invoke clang to compile C++ code.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 101-500 This PR causes between 101 and 500 packages to rebuild on Darwin. 10.rebuild-linux: 1001-2500 This PR causes many rebuilds on Linux and should target the staging branches. 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related labels Nov 18, 2025
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.
@reckenrode
reckenrode marked this pull request as draft November 18, 2025 01:35
@reckenrode
reckenrode changed the base branch from master to staging November 18, 2025 01:35
@nixpkgs-ci nixpkgs-ci Bot closed this Nov 18, 2025
@reckenrode
reckenrode marked this pull request as ready for review November 18, 2025 01:35
@nixpkgs-ci nixpkgs-ci Bot reopened this Nov 18, 2025
@reckenrode

Copy link
Copy Markdown
Contributor Author

Targeting to staging due to the number of rebuilds.

@nixpkgs-ci nixpkgs-ci Bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Nov 18, 2025
@reckenrode
reckenrode added this pull request to the merge queue Nov 18, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 18, 2025
@wolfgangwalther
wolfgangwalther added this pull request to the merge queue Nov 18, 2025
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 18, 2025
@wolfgangwalther
wolfgangwalther added this pull request to the merge queue Nov 18, 2025
@GrahamDennis

Copy link
Copy Markdown
Contributor

Does this PR Does this PR need to land on master?

@reckenrode

Copy link
Copy Markdown
Contributor Author

@hzeller

hzeller commented Dec 20, 2025 •

Copy link
Copy Markdown
Contributor

Since this is a crucial component to have clangd work, unchanged unstable and master are not very usable for weeks now to do c++ development. So (at least for me), it is a somewhat critical problem that can be fixed with an unlikely-to-cause-trouble patch.
Would it be possible to cherrypick this change to master, or would that mess up the merge cycle ?

@reckenrode

reckenrode commented Dec 20, 2025 •

Copy link
Copy Markdown
Contributor Author

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.

@mattkang

Copy link
Copy Markdown
Contributor

I just want to second that this has made unstable unusable for me. This is required for any real C++ dev. How much longer until it hits master?

@hzeller

hzeller commented Dec 21, 2025

Copy link
Copy Markdown
Contributor

for my personal projects, I created an overlay, putting that in a file in ~/.config/nixpkgs/overlays/clang-tools-patch.nix

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}
)

nix-shell will look in that directory and apply overlays found.

So using clang-tools now nix-shell -p llvmPackages_21.clang-tools will use the patched version.

getchoo added a commit to PrismLauncher/PrismLauncher that referenced this pull request Dec 22, 2025
Trial97 pushed a commit to Trial97/PrismLauncher that referenced this pull request Dec 25, 2025
@Mic92

Mic92 commented Dec 30, 2025

Copy link
Copy Markdown
Member

Also now added in master #475078
Is a 25.11 backport needed?

@evysgarden

evysgarden commented Jan 1, 2026 •

Copy link
Copy Markdown

A backport to 25.11 would be very appreciated since clangd is unusable for cpp on 25.11 otherwise

@nixos-discourse

Copy link
Copy Markdown

@reckenrode

Copy link
Copy Markdown
Contributor Author

The backport PR was #462884. The fix should already be in release-25.11.

ryanofsky added a commit to ryanofsky/libmultiprocess that referenced this pull request Jan 13, 2026
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.
@yshui yshui mentioned this pull request Jan 28, 2026
1 of 13 tasks
ryanofsky added a commit to ryanofsky/libmultiprocess that referenced this pull request Aug 6, 2026
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]>
ryanofsky added a commit to ryanofsky/libmultiprocess that referenced this pull request Aug 6, 2026
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]>
nullfail pushed a commit to nullfail/bitcoin that referenced this pull request Aug 27, 2026
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.
ryanofsky added a commit to ryanofsky/libmultiprocess that referenced this pull request Sep 11, 2026
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]>
ryanofsky added a commit to ryanofsky/libmultiprocess that referenced this pull request Dec 1, 2026
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.
ryanofsky added a commit to ryanofsky/libmultiprocess that referenced this pull request Dec 1, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related 8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 101-500 This PR causes between 101 and 500 packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 1001-2500 This PR causes many rebuilds on Linux and should target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants