[Haskell-cafe] very hard to build darcs with win32 ghc-6.8.2!

Tim Newsham newsham at lava.net
Wed Jun 4 16:26:33 EDT 2008

I built darcs for win32 recently and it was much more difficult than
it should be.  Probably most of the blame goes to ghc-6.8.2 binary
release for win32.  Half of the effort is getting the zlib prereq

Previously to build zlib for win32 ghc I did the following:

However, now, the gcc binary for ghc-6.8.2 does not work as well as
I would like which requires a bit more effort:

- It did not automatically add mingw headers during compilation, and
   to fix this I had to force some extra flags.  I built a shell script

   export PATH
   /c$GHC/gcc -I $GHC/include -I $GHC/include/mingw \
              -I $GHC/gcc-lib/include -L $GHC/gcc-lib "$@"

- During linking it did not find crt2.o and adding it to PATH and
   -L did not help, so I just copied wholesale all of
   /c/ghc/ghc-6.8.2/gcc-lib into my zlib source directory.

- At this point I was able to build with:
   CC=./xcc ./configure --prefix=/c/ghc/ghc-6.8.2 \
   make install

Why is the gcc in ghc's directory so non-functional?

Ok, so with zlib (the C library) installed, the zlib haskell package
installs properly.  Dependency resolved.

Next, to build darcs I had to configure it without libcurl support
(or alternately spend time chasing down that dep, pass for now). 
Using cygwin I ran "./configure" which falsely uses the cygwin gcc
for configuration checks, but since gcc is never used directly during
the compilation process, that doesn't matter that much.  I could have
tried the "xcc" trick here again, but didn't bother.  I ran into
two problems during the build:

- -Werror is specified in the GNUMakefile and there are many warnings.
   I just removed -Werror for now.

- During linking it was not able to resolve "SleepEx" from
   src/win32/System/Posix.hs.  I could not figure out what is going
   on here.  I tried adding "-lkernel32" and "-L /ghc/ghc-6.8.2/gcc-lib
   -Lkernel32" to the Makefile and it still did not work even though
   /ghc/ghc-6.8.2/gcc-lib/libkernel32.a has SleepEx at 8 defined(!)
   Finally I bit the bullet and hacked around this by noticing that
   mingw headers have _sleep() defined.  I replaced the code in Posix.hs

   foreign import ccall "_sleep" c_sleep :: CULong -> IO ()

   sleep :: Integer -> IO CInt
   sleep n = c_sleep (fromIntegral n) >> return (toEnum $ fromIntegral n)

At this point darcs builds and the binary seems to work (so far).
I don't know the implication of my sleep hack (which doesn't return
the actual time slept).

Here's a small test program which uses FFI to SleepEx which I was
not able to get working with win32 ghc-6.8.2.

{-# OPTIONS -fglasgow-exts -fffi #-}
module Main where
import Foreign.C.Types

foreign import ccall "SleepEx" c_SleepEx :: CUInt -> CInt -> IO CInt

main = do
     putStrLn "start"
     n <- c_SleepEx (2*1000) 1
     print n

So, what is going on with ghc-6.8.2?  Why is the gcc so hard to use
now?  Why can't I get FFI working with standard win32 functions?
Why aren't there prebuilt win32 darcs binaries anymore?

Tim Newsham

More information about the Haskell-Cafe mailing list