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

c language doesn't include gcov #100

Open
mayl opened this issue Mar 3, 2021 · 7 comments
Open

c language doesn't include gcov #100

mayl opened this issue Mar 3, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@mayl
Copy link

mayl commented Mar 3, 2021

I have a devshell.toml like below:

[language.c]
compiler = "pkgs.gcc"

When I enter the nix-shell I have gcc available from the nix store, but not gcov

[devshell]$ which gcc
/nix/store/2x4vcmasjgjs28arlgvx352y64h5y4z1-devshell-dir/bin/gcc
[devshell]$ which gcov
/usr/bin/gcov

I expect to have gcov available because when I run nix-shell -p gcc both are available:

$ which gcc
/nix/store/r4l53b461b2lyclxn1pdj0n4hvbxl2l6-gcc-wrapper-9.3.0/bin/gcc
$ which gcov
/nix/store/7rnys4pl8v7sb72ljbhzr3wjfly339rg-gcc-9.3.0/bin/gcov

My current workaround is to add "gcc-unwrapped" to the list of packages.

@mayl
Copy link
Author

mayl commented Mar 4, 2021

Actually, my workaround doesn't seem to work. gcov and gcc are available, but don't seem to work (meson says "gcc can't compile programs").

Appreciate any thoughts on how to get gcov coverage working in a devshell!

@zimbatm
Copy link
Member

zimbatm commented Mar 4, 2021

Ah yes, the language.c is still very early stage and needs more testing! devshell doesn't build on top of the stdenv so we have to re-instantiate a bunch of things ourselves. But the advantage is that we also get more control.

Are you able to share your project so I can give it a try?

@zimbatm
Copy link
Member

zimbatm commented Mar 4, 2021

If you have a Matrix client we can also talk about it in this room: https://matrix.to/#/#devshell:numtide.com

@mayl
Copy link
Author

mayl commented Mar 5, 2021

I can't share my actual project, but I put together a minimal repo that mirrors what I'm doing in a simplified case that you can try.

nix-shell --pure uses devshell. nix-shell --pure nixshell.nix sets up an equivalent environment using nixpkgs.mkShell In the devshell if you cd into coverageTest and run the run_coverage_test script (or just setup and run a coverage build yourself manually with meson) it fails because gcov is not found. If you delete the build directory and do the same from the standard nixpkgs.mkShell, gcov is in the path and the coverage report succeeds.

I don't have a matrix client currently, but I'll look into setting one up and maybe catching you in that room sometime. Thanks for looking into this!

@zimbatm zimbatm added the bug Something isn't working label Mar 6, 2021
@zimbatm
Copy link
Member

zimbatm commented Mar 6, 2021

I banged on it until it works: mayl/gcovDemo#1

Would you mind adding a C dependency like "libz" as well to exercise this out more?

And related PR: #102

@mayl
Copy link
Author

mayl commented Mar 21, 2021

Hey @zimbatm, sorry for the delay on my end for this.

Including glibc along with gcc-unwrapped seems to work for my simple project which includes Cpputest. I'll look to add something to the demo you can look at as well.

Reflecting on this some more, I wonder if this is an upstream nixpkgs issue as much as it is a devshell issue? At the very least it seems inconsistent that clang would include llvm-cov if gcc doesn't include gcov. Is the fact that the gcc expression from nixpkgs does not provide gcov intentional, or is it an oversight?

@zimbatm
Copy link
Member

zimbatm commented May 10, 2021

I think it's because gcc is being used in the stdenv too much. The wrapped gcc makes a bunch of assumptions that are not valid outside. That's also why gcov is missing, it's probably not useful for building packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants