devshell icon indicating copy to clipboard operation
devshell copied to clipboard

c language doesn't include gcov

Open mayl opened this issue 4 years ago • 7 comments

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 avatar Mar 03 '21 04:03 mayl

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!

mayl avatar Mar 04 '21 06:03 mayl

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 avatar Mar 04 '21 08:03 zimbatm

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

zimbatm avatar Mar 04 '21 08:03 zimbatm

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!

mayl avatar Mar 05 '21 02:03 mayl

I banged on it until it works: https://github.com/mayl/gcovDemo/pull/1

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

And related PR: https://github.com/numtide/devshell/pull/102

zimbatm avatar Mar 06 '21 17:03 zimbatm

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?

mayl avatar Mar 21 '21 02:03 mayl

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.

zimbatm avatar May 10 '21 09:05 zimbatm