haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.62k stars 691 forks source link

Before testing if libraries link, do a vanilla run to check if the compiler is misconfigured #4395

Open ezyang opened 7 years ago

ezyang commented 7 years ago

@angerman was reporting on IRC that Cabal couldn't find iconv, but everything seemed like it was in order. When he posted -v3 logs, the true error came to light:

/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/14587779232007237709.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/8235644401115438165 '-D__GLASGOW_HASKELL__=803' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' -Idist-install/build/autogen -I/Users/angerman/tmp/libiconv-1.15/include -Iinclude -I. -I/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes/dist-derivedconstants/header -liconv -L/Users/angerman/tmp/libiconv-1.15/lib/.libs -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/integer-simple/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/ghc-prim/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -Wall -fno-stack-protector -Wno-unknown-pragmas
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang
returned ExitFailure 1 with error message:
clang: error: invalid linker name in argument '-fuse-ld=gold'
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/178448449274243042.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/1148079871137522503 -liconv -L/Users/angerman/tmp/libiconv-1.15/lib/.libs -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/integer-simple/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/ghc-prim/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -Wall -fno-stack-protector -Wno-unknown-pragmas
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang
returned ExitFailure 1 with error message:
clang: error: invalid linker name in argument '-fuse-ld=gold'
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/144128232716531729.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/823378840143542612 -liconv -L/Users/angerman/tmp/libiconv-1.15/lib/.libs -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/integer-simple/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/libraries/ghc-prim/dist-install/build -L/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -Wall -fno-stack-protector -Wno-unknown-pragmas
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang
returned ExitFailure 1 with error message:
clang: error: invalid linker name in argument '-fuse-ld=gold'
/Users/angerman/Projects/Haskell/ghc-ios-scripts/aarch64-linux-android-clang -fno-stack-protector '-fuse-ld=gold' -Wl,-z,noexecstack /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/8965443031474833169.c -o /var/folders/fv/xqjrpfj516n5xq_m_ljpsjx00000gn/T/12648177091998097157 -c '-D__GLASGOW_HASKELL__=803' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' -Idist-install/build/autogen -I/Users/angerman/tmp/libiconv-1.15/include -Iinclude -I. -I/Users/angerman/Projects/Haskell/obsidian/ghc/rts/dist/build -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes -I/Users/angerman/Projects/Haskell/obsidian/ghc/includes/dist-derivedconstants/header -Wall -fno-stack-protector -Wno-unknown-pragmas
ghc-cabal: Missing dependency on a foreign library:
* Missing C library: iconv
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
make[1]: *** [libraries/base/dist-install/package-data.mk] Error 1
make: *** [all] Error 2

The failure of clang had nothing to do with linking iconv: rather, it was failing because of clang: error: invalid linker name in argument '-fuse-ld=gold'.

The way to solve this problem is, before we test if any of the libraries fail the linker, FIRST check if we can build a vanilla C file at all. If we can't, that means that there's something wrong with the options: output the error message verbatim.

There's a few other lessons too:

  1. Even after the failure, Cabal goes off and tries to compile the headers. This caused me to take more time to diagnose the problem, because the true "failure" was further up the scrollback. We should error more quickly.

  2. The error message should suggest running at higher verbosity to see the error message the compiler output, or just unconditionally report the actual error that caused the problem. None of this cloak and dagger "I ran something but I'm not going to tell you what I did, neener-neener."

Also, can we finally get keep-tmp-files for Cabal? This thing where the temporary files disappear before I can look at them is really annoying.

23Skidoo commented 7 years ago

keep-tmp-files

I thought we had it: https://github.com/haskell/cabal/blob/master/Cabal/Distribution/Simple/Utils.hs#L1333 Is it broken?

ezyang commented 7 years ago

Doesn't do you much good if you don't plumb it where necessary ;)

withTempFile :: FilePath    -- ^ Temp dir to create the file in
                -> String   -- ^ File name template. See 'openTempFile'.
                -> (FilePath -> Handle -> IO a) -> IO a
withTempFile tmpDir template action =
  withTempFileEx defaultTempFileOptions tmpDir template action
23Skidoo commented 7 years ago

That's a backwards compat shim for Custom setups. I suppose we could deprecate it.

v0d1ch commented 4 years ago

Is this task still a thing? If so I can try to tackle it @ezyang

ezyang commented 4 years ago

It probably is. Try running Cabal with a completely broken compiler setup and it should probably repro.