Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

OSX: gmp.h file not found #493

Open
nh2 opened this issue Jan 8, 2018 · 7 comments
Open

OSX: gmp.h file not found #493

nh2 opened this issue Jan 8, 2018 · 7 comments

Comments

@nh2
Copy link

nh2 commented Jan 8, 2018

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.

@nh2
Copy link
Author

nh2 commented Jan 8, 2018

If I pass -I/Users/user/ghc/_build/stage1/gmp/include to that long ghc invocation, then it compiles fine.

@nh2
Copy link
Author

nh2 commented Jan 8, 2018

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.

@nh2
Copy link
Author

nh2 commented Jan 8, 2018

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" ] ]

@nh2
Copy link
Author

nh2 commented Jan 8, 2018

Apart from this issue, the experience building GHC on OSX was great with Hadrian by the way. I installed

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.

@angerman
Copy link
Collaborator

angerman commented Jan 8, 2018

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.

@snowleopard
Copy link
Owner

@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!

@snowleopard snowleopard added the bug label Jan 8, 2018
@angerman
Copy link
Collaborator

angerman commented Jan 9, 2018

@nh2 here's what I've been talking about (it's all in #445) commits: 7b37f15, d732756
There's also some accompanying discussion from #445 (comment) onwards.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants