Cabal does not try `clang` as a name for gcc
Describe the bug
We had a bug at work where our project would not build in a pure nix-shell on macOS, since the Nix stdenv uses clang on macOS. However, it worked properly in an impure nix shell. We observed that macOS has /usr/bin/gcc which is a symlink to clang, leading to this working properly inside the impure shell.
We solved it by generating a cabal project file with Nix that looked like this:
program-locations
gcc-location: ${stdenv.cc}/bin/cc
To Reproduce
Build a package with nix-shell --pure on macOS, with a c-sources option in the cabal file:
c-sources:
test.c
Please use version-prefixed commands (e.g. v2-build or v1-build) to avoid ambiguity.
Expected behavior
The package should build as Nix discovers the clang in the environment.
System information
- Operating system - macOS 12.4
cabal,ghcversions - cabal 3.8.1.0, ghc 9.2.4
Additional context I am surprised this happened at all; generally Nix hardcodes the compiler path. I did not manage to cause it on linux.
Does it work fine in GHC without cabal? E.g., if you try to compile a small program with ghc --make Foo.hs? I suspect it's normally not the job of cabal to find programs for GHC, though cabal can be used to override whatever GHC finds normally, which is how you constructed your workaround.