Clang tooling woes 2

Hello. older related thread here

The other thread has some wrapper work-arounds but at the end also suggests maybe it got improved in nix?

I’m trying to get a basic llvm/cmake nix-shell going. It mostly works, but clang-tidy doesn’t know where stuff is.

[nix-shell:~/src/cpp/hello]$ cat shell.nix
with import <nixpkgs> {};
clangStdenv.mkDerivation {
name = "env";
nativeBuildInputs = [ cmake ];
}

[nix-shell:~/src/cpp/hello]$ $CXX src/Hello.cpp

[nix-shell:~/src/cpp/hello]$ clang-tidy src/Hello.cpp
1 error generated.
Error while processing /Users/travis/src/cpp/hello/src/Hello.cpp.
/Users/travis/src/cpp/hello/src/hello.cpp:1:10: error: 'iostream' file not found [clang-diagnostic-error]
#include <iostream>
        ^
Found compiler error(s).

I’m new at nix. What approach should I take?
If anyone has a a little llvm hello world shell.nix repo, that’d be cool.

I was getting mixed signals from discourse about whether to make a new thread or bump the old. Sorry if I chose wrong.

1 Like

(I think creating a new thread and linking to the old one is perfectly fine.)

I’m having problems with clang-tidy from nixpkgs too.

This is what I found so far:

  • The clang-tidy you’re running there is the unwrapped one. If you explicitly add clang-tools to the nativeBuildInputs list you get the wrapped one. (Maybe it’s a packaging bug that we add the unwrapped one implicitly. Why would we ever want that?)
  • With the wrapped clang-tidy in $PATH, it’ll find headers like <iostream>.
  • The next problem is cang-tidy barfs on #include <cmath>!

Searching for the #include <cmath> issue lead me to Build failure on clang/libc++ 4.0 · Issue #937 · Andersbakken/rtags · GitHub. But so far I’m unable to resolve that. I tried hacks like export NIX_CFLAGS_COMPILE="-isystem ${libcxx}/include/c++/v1 $NIX_CFLAGS_COMPILE", but it didn’t work.

1 Like

Relevant post (and its follow up response):

Some more interesting stuff: https://git.0xee.eu/0xee/nix-home/commit/080dd54b2ad0bc902db48f5a459daf0866117669 ← using that fixed it for me!

TODO: Submit PR :smile:

1 Like

Thanks! Using clang-tools is good enough for me for now.

I think clang-tidy was fixed in fix clangd wrapper · NixOS/nixpkgs@782cb7a · GitHub.