Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tools: teach about nix's include path #73345

Merged
merged 1 commit into from Nov 17, 2019
Merged

Conversation

Mic92
Copy link
Member

@Mic92 Mic92 commented Nov 13, 2019

By translating NIX_CFLAGS_COMPILE to CPATH,
all tools will now find c headers properly,
when run in a nix-shell.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @

@Mic92 Mic92 requested a review from dtzWill November 13, 2019 14:42

export clang=${clang}
substituteAll ${./wrapper} $out/bin/clangd
chmod +x $out/bin/clangd
for tool in \
clang-apply-replacements \
clang-check \
clang-format \
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we skip this one from being wrapped?

@Mic92
Copy link
Member Author

Mic92 commented Nov 13, 2019

Might be worth a backport

@Mic92 Mic92 force-pushed the fix-clang-tools branch 2 times, most recently from 1174555 to 5c23507 Compare November 13, 2019 14:59
@Mic92
Copy link
Member Author

Mic92 commented Nov 13, 2019

Tested with non-trivial C projects and clangd.
Also tested with C++.

local path
while (( $# )); do
case $1 in
-isystem|-I)
Copy link
Member

Choose a reason for hiding this comment

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

idirafter could also be used.

Copy link
Member Author

@Mic92 Mic92 Nov 13, 2019

Choose a reason for hiding this comment

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

I just noticed parsing of -I was wrong anyway, since there can be no space in between. Since we only use -isystem right now in stdenv, I just simplified the code of the wrapper rather than having a half broken implementation for -I. -Idirafter is also not used in nixpkgs.

By translating NIX_CFLAGS_COMPILE to CPATH,
all tools will now find c headers properly,
when run in a nix-shell.
@Mic92 Mic92 merged commit f3759a6 into NixOS:master Nov 17, 2019
@Mic92 Mic92 deleted the fix-clang-tools branch November 17, 2019 10:37
dtzWill pushed a commit to dtzWill/nixpkgs that referenced this pull request Nov 17, 2019
clang-tools: teach about nix's include path
(cherry picked from commit f3759a6)
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/clang-tooling-woes-on-nixos/2314/15

@tazjin
Copy link
Member

tazjin commented May 19, 2020

Do you think changing the order of CPATH and libcpp_includes in the CPLUS_INCLUDE_PATH is feasible and would work?

Did you ever get around to submitting a change like this? I'm running into what I suspect is the same error at the moment and am wondering how deep I should dig :)

@Mic92
Copy link
Member Author

Mic92 commented May 19, 2020

There is an alternative to @knedlsepp proposal: With https://github.com/NixOS/nixpkgs/pull/85189/files#diff-ae6d7fc8f1059168bd391972ef177c31R40 one could include the platforms native c++ headers. Don't know what the latest state of this is, but @Ericson2314 might know more.

@knedlsepp
Copy link
Member

knedlsepp commented May 20, 2020

I don't think I could ever get this working 100%. I only got a local project specific workaround that basically breaks the C-only backend but makes C++ work. :-\

@Vonfry
Copy link
Member

Vonfry commented Aug 18, 2020

Do you think changing the order of CPATH and libcpp_includes in the CPLUS_INCLUDE_PATH is feasible and would work?

I met the same problem recently. It is solved by changing the order of CPATH and libcpp_includes.

By the way, buildcpath seemed not to work for me, it also returns an empty string.

Would someone modify the wrap or make it working more genericly?

@Mic92
Copy link
Member Author

Mic92 commented Aug 18, 2020

Do you think changing the order of CPATH and libcpp_includes in the CPLUS_INCLUDE_PATH is feasible and would work?

I met the same problem recently. It is solved by changing the order of CPATH and libcpp_includes.

By the way, buildcpath seemed not to work for me, it also returns an empty string.

Would someone modify the wrap or make it working more genericly?

If it returns an empty string, you might be not in a nix-shell. Make sure that NIX_CFLAGS_COMPILE is not empty.

@Mic92
Copy link
Member Author

Mic92 commented Aug 18, 2020

@knedlsepp @tazjin This PR should fix your problems with math.h: https://github.com/NixOS/nixpkgs/pull/95733/files
At least in theory, I need to build/test it.

@Vonfry
Copy link
Member

Vonfry commented Aug 18, 2020

I retried it and find the reason. The wrap is always worked under bash, it is not a problem. The one is caused by glibc and libc++ is more important.

buildcpath can work in a bash shell by nix-shell -p bash, but it cannot work in zsh.

$1(${NIX_CFLAGS_COMPILE}) is splitted by space in bash, but not in zsh. So the case can match -isystem in bash not in zsh.

@Mic92
Copy link
Member Author

Mic92 commented Aug 18, 2020

I retried it and find the reason. The wrap is always worked under bash, it is not a problem. The one is caused by glibc and libc++ is more important.

buildcpath can work in a bash shell by nix-shell -p bash, but it cannot work in zsh.

$1(${NIX_CFLAGS_COMPILE}) is splitted by space in bash, but not in zsh. So the case can match -isystem in bash not in zsh.

In our wrapper it should be always bash. So that should be not a problem.

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

Successfully merging this pull request may close these issues.

None yet

7 participants