tmcdonell / cuda

Haskell FFI bindings to CUDA
Other
76 stars 36 forks source link

GHCi only works with Stack with a custom cabal.buildinfo file. #52

Open TravisWhitaker opened 7 years ago

TravisWhitaker commented 7 years ago

When building with cabal or Stack on Windows 10 with GHC 8.2.1, stack ghci and cabal repl both yield:

ghc.EXE:  | C:\Users\Travis\sources\cuda\.stack-work\dist\e53504d9\build\cbits\stubs.o: unknown symbol `cudaConfigureCall'
linking extra libraries/objects failed

Using the generated cabal.buildinfo.generated, which looks like this on my machine:

buildable: True
cc-options: "-DCUDA_INSTALL_PATH=\"C:\\\\Program Files\\\\NVIDIA GPU Computing Toolkit\\\\CUDA\\\\v8.0\""
            "-DCUDA_LIBRARY_PATH=\"C:\\\\Program Files\\\\NVIDIA GPU Computing Toolkit\\\\CUDA\\\\v8.0\\\\lib/x64\""
            "-IC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\include"
ld-options: "-LC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\lib/x64"
extra-libraries:
    cudart
    cuda
extra-ghci-libraries: cudart64_80
                      nvcuda
extra-lib-dirs: "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v8.0\\lib/x64"
x-extra-c2hs-options: --cppopts=-E --cppopts=-m64 --cppopts=-DUSE_EMPTY_CASE

Strangely, simply copying cuda.buildinfo.generated to cuda.buildinfo, without rebuilding or reconfiguring, allows stack repl to work. I haven't managed to cause a similar effect with any combination of cabal repl, cabal configure, or cabal clean.

stack ghci doesn't seem to work by calling Setup.hs; I verified this by simply adding a putStr before defaultMainWithHooks. I also added prints to getHookedBuildInfo, so I have no idea by what code path Stack is able to read the cuda.buildinfo file (and fail to read the cuda.buildinfo.generated file!).

In practice I doubt anyone is using this library alone in GHCi, but this behavior is very strange and might be some Cabal and/or Stack bug. I'm curious if anyone can manage to reproduce this.

tmcdonell commented 7 years ago

So I got a windows box set up, but was unable to reproduce this...

Maybe it doesn't work when running in the same directory? I don't think this will ever work quite right though because most of the files are c2hs files which need to be run through the preprocessor, and ghci isn't going to do that for you whenever you update them...