Skip to content

cmake: only apply nix include dirs workaround inside nix - #401

Merged
ryanofsky merged 1 commit into
bitcoin-core:masterfrom
ViniciusCestarii:iwyu-libcxx-non-nix
Dec 1, 2026
Merged

ryanofsky merged 1 commit into
bitcoin-core:masterfrom
ViniciusCestarii:iwyu-libcxx-non-nix

Conversation

@ViniciusCestarii

Copy link
Copy Markdown
Contributor

Building with IWYU and libc++ on Linux machine fails with:

In file included from /usr/bin/../include/c++/v1/cwchar:116:
/usr/bin/../include/c++/v1/cwctype:61:5: error: <cwctype> tried including <wctype.h> but didn't find libc++'s <wctype.h> header.           This usually means that your header search paths are not configured properly.           The header search paths should contain the C++ Standard Library headers before           any C Standard Library, and you are probably using compiler flags that make that           not be the case.
   61 | #   error <cwctype> tried including <wctype.h> but didn't find libc++'s <wctype.h> header. \
      |     ^

With MP_ENABLE_IWYU or MP_ENABLE_CLANG_TIDY, the Nix include-dirs workaround passes the compiler's implicit include dirs as explicit -isystem flags, so /usr/include lands ahead of libc++'s headers and this causes it to fail.

Apply Nix workaround only when NIX_CFLAGS_COMPILE is set so it doesn't affect unrelated builds.

@DrahtBot

DrahtBot commented Nov 20, 2026 •

Copy link
Copy Markdown

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK ryanofsky

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

@hebasto

hebasto commented Nov 20, 2026

Copy link
Copy Markdown
Member

Failure in https://github.com/bitcoin-core/libmultiprocess/actions/runs/44653065356/job/136012484932?pr=401 is not related to this PR change. See bitcoin/bitcoin#36913.

@hebasto

hebasto commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Building with IWYU and libc++ on Linux machine fails with...

Could you share details about your build platform? (OS, CMake version, compiler version, etc)

@ryanofsky ryanofsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Code review ACK 9be2beb. I added this workaround in #184 for clang-tidy in Nix shells, and it should have been limited to Nix from the start: outside Nix there are no NIX_CFLAGS_COMPILE paths to recover, so all it does is turn the compiler's built-in include directories into explicit -isystem flags, which can put /usr/include ahead of the C++ standard library headers the tool uses. The build • macos job runs clang-tidy outside Nix and still passes with the workaround turned off, which confirms it isn't needed there.

This also fits with #333, which rewrites the comment on this workaround to explain that Nix compiler wrappers inject these include paths themselves, and that clang-tidy no longer needs the workaround after NixOS/nixpkgs#462747, so only the nixpkgs IWYU wrapper still does. The two PRs merge cleanly with each other.

It would still be good to have the platform details hebasto asked for, since it's not obvious why the compiler's own libc++ include directory, which should also be in the implicit list ahead of /usr/include, didn't take precedence. My guess is IWYU was built against a different LLVM version than clang++.

@ryanofsky
ryanofsky merged commit 24fe0da into bitcoin-core:master Dec 1, 2026
13 of 14 checks passed
@ViniciusCestarii

Copy link
Copy Markdown
Contributor Author

Ops I think I missed last Hebasto comment, but answering now:

OS: Arch Linux 7.2.14-arch1-1
cmake version: 4.4.5
clang version: 23.1.4
include-what-you-use version: include-what-you-use 0.26 (git:01a091d) based on clang version 23.1.4

cmake command:

cmake -B build-libc++ -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-stdlib=libc++" -DMP_ENABLE_IWYU=ON --fresh
cmake --build build-libc++ -j 18

clang and IWYU are built on the same LLVM version (23.1.4), so a version mismatch isn't the cause.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants