cabal extra-libraries check does not correctly propagate E2BIG error
I have a Haskell library that uses extra-libraries: glog.
When I try to build it I get:
Setup: Missing dependencies on foreign libraries:
* Missing C libraries: glog
This is a lie; the dependency exists.
The problem is that because in the eventual gcc invocation that Cabal creates to check whether the dependency really exists (I suspect it compiles a small C file to check if it can really use glog, similar to how autoconf does it), the amount of arguments passed to GCC turns out to be very long (further inflated by the fact that I use nix, but in general that's just a small constant factor difference).
Strace confirms:
strace -fye execve -s 100000000 -v runhaskell Setup.hs build 2>&1 | grep E2BIG
execve("cc1", [arguments here], [env vars here, "COLLECT_GCC_OPTIONS='-fno-stack-protector -L... 150KB of -L flags here'"] = -1 E2BIG (Argument list too long)
E2BIG (Argument list too long), in this case because COLLECT_GCC_OPTIONS is longer than 128 KB (32 * 4 KB pages, see here).
But cabal doesn't correctly propagate the E2BIG failure; instead of telling me that some internal invocaiton failed, it claims Missing dependencies on foreign libraries.
Related nix issue: https://github.com/NixOS/nixpkgs/issues/41340
I noticed that if I run with --verbose=3, I see in the output:
gcc returned
ExitFailure 1 with error message:
gcc: error trying to exec
'cc1':
execv: Argument list too long
but cabal continues nevertheless.
I think that this should be easy to fix: just check the exit code and tweak the error message. The relevant code is in Distribution.Simple.Configure.checkForeignDeps.
@23Skidoo Would this be a suitable patch? https://github.com/dminuoso/cabal/commit/76075c41f616aaf1d4e6f932bb56b845a1f67c12
Could we have this proposed patch please?
I lost another 2 hours just now debugging a failure because Cabal hides these errors.