hadrian
hadrian copied to clipboard
OSX: gmp.h file not found
On OSX, running bash hadrian/build.stack.sh --configure -j --flavour=quickest inplace/bin/ghc-stage2
:
Error when running Shake build system:
* inplace/bin/ghc-stage2
* inplace/lib/bin/ghc-stage2
* _build/stage1/libraries/integer-gmp/HSinteger-gmp-1.0.1.0.o
* _build/stage1/libraries/integer-gmp/c/cbits/wrappers.o
user error (Development.Shake.cmd, system command failed
Command: inplace/bin/ghc-stage1 -Wall -hisuf hi -osuf o -hcsuf hc -static -hide-all-packages -no-user-package-db '-this-unit-id integer-gmp-1.0.1.0' '-package-id ghc-prim-0.5.2.0' -i -i_build/stage1/libraries/integer-gmp -i_build/stage1/libraries/integer-gmp/build/autogen -ilibraries/integer-gmp/src/ -Iincludes -I_build/generated -I_build/stage1/libraries/integer-gmp -Ilibraries/integer-gmp/include -I/Users/user/ghc/_build/stage1/rts -I/Users/user/ghc/includes -I/Users/user/ghc/_build/generated -I_build/generated -optc-I_build/generated -optP-include -optP_build/stage1/libraries/integer-gmp/build/autogen/cabal_macros.h -optc-fno-stack-protector -odir _build/stage1/libraries/integer-gmp -hidir _build/stage1/libraries/integer-gmp -stubdir _build/stage1/libraries/integer-gmp -optc-std=c99 -optc-Wall -optc-fno-stack-protector -optc-Iincludes -optc-I_build/generated -optc-I_build/stage1/libraries/integer-gmp -optc-Ilibraries/integer-gmp/include -optc-I/Users/user/ghc/_build/stage1/rts -optc-I/Users/user/ghc/includes -optc-I/Users/user/ghc/_build/generated -Werror -Wnoncanonical-monad-instances -optc-Wno-unknown-pragmas -c libraries/integer-gmp/cbits/wrappers.c -o _build/stage1/libraries/integer-gmp/c/cbits/wrappers.o -O0 -H64m -this-unit-id integer-gmp -Wall -XHaskell2010 -Wno-deprecated-flags
Exit code: 1
Stderr:
libraries/integer-gmp/cbits/wrappers.c:25:10: error:
fatal error: 'gmp.h' file not found
|
25 | #include <gmp.h>
| ^
#include <gmp.h>
^
1 error generated.
`gcc' failed in phase `C Compiler'. (Exit code: 1)
)
There exists a _build/stage1/gmp/include/gmp.h
.
And it seems --with-intree-gmp
gets passed to integer-gmp
's ./configure
: libraries/integer-gmp//config.status
has CFLAGS=-I_build/stage1/gmp/include
and it has:
ac_cs_config="'--with-compiler=ghc' 'CFLAGS=-fno-stack-protector -I/Users/user/ghc/_build/generated' 'CPPFLAGS=-I_build/generated' '--with-cc=/usr/bin/gcc' '--disable
-option-checking' '--with-intree-gmp' 'CFLAGS=-I_build/stage1/gmp/include' 'CC=/usr/bin/gcc'"
But maybe it doesn't find the dir and it should do that with some ../
in front? Just guessing.
If I pass -I/Users/user/ghc/_build/stage1/gmp/include
to that long ghc
invocation, then it compiles fine.
Maybe the more likely reason is that in
ac_cs_config="'--with-compiler=ghc' 'CFLAGS=-fno-stack-protector -I/Users/user/ghc/_build/generated' [...] 'CFLAGS=-I_build/stage1/gmp/include' [...]"
the CFLAGS=
appears twice and only the first one applies? Because the -I/Users/user/ghc/_build/generated -I_build/generated
appears in the ghc
invocation.
I have temporarily put in this hack, which allowed me to build ghc-stage2
with Hadrian on OSX:
diff --git a/hadrian/src/Settings/Builders/Ghc.hs b/hadrian/src/Settings/Builders/Ghc.hs
index af78b74..deb3a7a 100644
--- a/hadrian/src/Settings/Builders/Ghc.hs
+++ b/hadrian/src/Settings/Builders/Ghc.hs
@@ -145,5 +145,6 @@ includeGhcArgs = do
, cIncludeArgs
, arg $ "-I" ++ root -/- generatedDir
, arg $ "-optc-I" ++ root -/- generatedDir
+ , arg $ "-I" ++ root -/- "stage1/gmp/include"
, (not $ nonCabalContext context) ?
pure [ "-optP-include", "-optP" ++ autogen -/- "cabal_macros.h" ] ]
Apart from this issue, the experience building GHC on OSX was great with Hadrian by the way. I installed
- brew from its website
-
brew install autoconf automake
- Stack from its website
- Python 3 from the python.org bindist
then did a
-
git clone --recursive https://git.haskell.org/ghc.git && cd ghc
and built GHC with
-
bash hadrian/build.stack.sh --configure -j --flavour=quickest inplace/bin/ghc-stage2
Very very nice.
I think I have some libgmp patch on my reloc PR. Not absolutely sure that it fixes what you saw though. However if it did and you have the time to extract it into a separate PR against master please do so.
@nh2 Thank you for the report!
the CFLAGS= appears twice and only the first one applies?
Hmm, this looks suspicious. Perhaps, we need to collapse both CFLAGS
into one to fix this. I can't reproduce this locally, so hard to guess.
We could temporarily merge your fix, but we should get rid of the hard-coded path -- I believe we should use gmpBuildPath
and gmpLibraryH
, see:
https://github.com/snowleopard/hadrian/blob/master/src/Rules/Gmp.hs#L25-L31
Furthermore, I think this fix should go somewhere here instead, because it is integer-gmp
-specific:
https://github.com/snowleopard/hadrian/blob/master/src/Settings/Packages/IntegerGmp.hs#L18
@nh2 If you could rework your fix as suggested above, could you please send a PR?
Apart from this issue, the experience building GHC on OSX was great with Hadrian by the way.
Awesome, great to hear!
@nh2 here's what I've been talking about (it's all in #445) commits: https://github.com/snowleopard/hadrian/pull/445/commits/7b37f157fa6eda081fccfcf63f1fcb844d0dd3b5, https://github.com/snowleopard/hadrian/pull/445/commits/d732756c4535e2d908fb21a9f42cbd505697d2e7 There's also some accompanying discussion from https://github.com/snowleopard/hadrian/pull/445#issuecomment-343347743 onwards.