cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Cabal does not try `clang` as a name for gcc

Open lf- opened this issue 3 years ago • 1 comments

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, ghc versions - 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.

lf- avatar Sep 17 '22 03:09 lf-

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.

Mikolaj avatar Sep 21 '22 13:09 Mikolaj