lukexi / halive

Live recompiler for Haskell
BSD 2-Clause "Simplified" License
263 stars 18 forks source link

stack build error in linux docker container #34

Closed theobat closed 4 years ago

theobat commented 5 years ago

Here's the issue I'm struggling with right now:

appuser@8be60e71ef81:~/user/halive$ stack build
Building all executables for `halive' once. After a successful build of all of them, only specified executables will be rebuilt.
halive-0.1.6: build (lib + exe)
Preprocessing library for halive-0.1.6..
Building library for halive-0.1.6..
[5 of 8] Compiling Halive.SubHalive ( src/Halive/SubHalive.hs, .stack-work/dist/x86_64-linux/Cabal-2.4.0.1/build/Halive/SubHalive.o )

/app/user/halive/src/Halive/SubHalive.hs:248:17: error: parse error on input ‘#’
    |
248 |                 #else
    |                 ^

--  While building package halive-0.1.6 using:
      /app/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.3 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.4.0.1 build lib:halive exe:halive --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

And my cpp :

appuser@8be60e71ef81:~/user/halive$ cpp --version
cpp (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
appuser@8be60e71ef81:~/user/halive$ stack --version
Version 1.9.3, Git revision 40cf7b37526b86d1676da82167ea8758a854953b (6211 commits) x86_64 hpack-0.31.1

It makes absolutely no sense to me (I unerstand the preprocessor is not doing its job correctly, but is it the cpp preprocessor, or the ghc one ?) if somebody's got any direction I'll take it ...

theobat commented 5 years ago

Also, I forgot to precise, but I tried both with stack install and git clone && stack build in the cloned repo

theobat commented 5 years ago

So it seems to be narrower than I first thought, if you remove the if lines near line 248 (like I did in my fork: https://github.com/theobat/halive/commit/6e67493a3b4a420bae302625747dade2719e9e21), it seems to compile without problems, but trying to run the binary yield another error:

/app/.local/bin/halive: error while loading shared libraries: libHShalive-0.1.6-9VMAdJSePEBBqGa1oiSZTr-ghc8.6.5.so: cannot open shared object file: No such file or directory

This might be because I used a more recent version of GHC than the one used in this repo.

theobat commented 5 years ago

Now it works, simply use --ghcOptions=" -fPIC -fasm" (see this), the issue is with dynamic linking.

The reason why this specific #else fails at the parsing stage is beyond my understanding (-yet). It needs a deeper knowledge of stack/the cpp extension/ghc itself ...

outkine commented 5 years ago

Running stack build halive --ghc-options="-fPIC -fasm" still fails for me:

halive> configure
halive> Configuring halive-0.1.6...
halive> build
halive> Preprocessing library for halive-0.1.6..
halive> Building library for halive-0.1.6..
halive> [1 of 8] Compiling Halive.Args
halive> [2 of 8] Compiling Halive.Concurrent
halive> [3 of 8] Compiling Halive.FileListener
halive> [4 of 8] Compiling Halive.FindPackageDBs
halive> [5 of 8] Compiling Halive.SubHalive
halive> 
halive> /tmp/stack2801/halive-0.1.6/src/Halive/SubHalive.hs:248:17: error: parse error on input ‘#’
halive>     |
halive> 248 |                 #else
halive>     |                 ^
halive> 

--  While building package halive-0.1.6 using:
      /home/anton/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_2.4.0.1_ghc-8.6.5 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1
theobat commented 5 years ago

Yeah I stopped using this and just made a dummy bash file which kills & restart the stack build process in my docker container... (which is obviously worse performance wise) The CPP pre-processor is a hack so I forsake fixing the repo (+ lack of time to do it properly)

outkine commented 5 years ago

After doing some research I came upon this reddit post, which presents two solutions: ghcid and yesod-bin. I managed to get yesod-bin to work perfectly for me using this example, although your use-case may be different.

turion commented 4 years ago

This very compilation error is also the reason that halive is marked as broken on nixpkgs:

nix-repl> :b haskellPackages.halive
builder for '/nix/store/mk13jiivs3a080zb085i8r7ld1y3rg7x-halive-0.1.6.drv' failed with exit code 1; last 10 log lines:
  [2 of 8] Compiling Halive.Concurrent ( src/Halive/Concurrent.hs, dist/build/Halive/Concurrent.o )
  [3 of 8] Compiling Halive.FileListener ( src/Halive/FileListener.hs, dist/build/Halive/FileListener.o )
  [4 of 8] Compiling Halive.FindPackageDBs ( src/Halive/FindPackageDBs.hs, dist/build/Halive/FindPackageDBs.o )
  [5 of 8] Compiling Halive.SubHalive ( src/Halive/SubHalive.hs, dist/build/Halive/SubHalive.o )

  src/Halive/SubHalive.hs:248:17: error: parse error on input ‘#’
      |
  248 |                 #else
      |                 ^
  [8 of 8] Compiling Halive.Utils     ( src/Halive/Utils.hs, dist/build/Halive/Utils.o )
[0 built (1 failed), 59 copied (702.4 MiB), 35.6 MiB DL]
error: build of '/nix/store/mk13jiivs3a080zb085i8r7ld1y3rg7x-halive-0.1.6.drv' failed
turion commented 4 years ago

The resolution is just a 3 line fix. The indentation of the CPP is simply wrong. PR impending.