6

I want to create a Haskell Stack package that includes another Haskell Stack package as an extra-dep. The problematic thing is that the package that i'm trying to include is a binding to some C code, using Haskell's FFI.

If I just stack unpack and stack build that package (HasCacBDD) it works just fine, but when I include it as an extra-dep Stack complains about a missing library.

Looking at the Setup.hs of that original package, I see that it basically creates an static library called libHasCacBDD.a and puts it in the correct folder inside the .stack-work path for it to be linked. This library is precisely the one that is giving me an error when I include it in my own project.

Looking carefully at the .stack-work folder of my own project, I see that the mentioned libHasCacBDD.a is indeed inside the directory hidden in some place. So fortunately, the library is being built correctly but my project cannot find it.

The official Haskell Stack documentation says something about what to do in that case, but I think it is not specific enough to give me a satisfactory answer.

What I need to do is to specify the path where the libHasCacBDD.a library is being stored as a extra-lib-dirs option. Nevertheless, I do not how to do that in a platform independent way (if i hardcode the path in my computer, it will just work in it and what's the point of doing a package in that case).

I created an issue on Github with more information about the particulars.

Any suggestions?

Seanny123
  • 8,776
  • 13
  • 68
  • 124

1 Answers1

0

I've handled this in the past with a Makefile that finds the local directory, and wraps my usual stack commands with arguments to use it.

LIB_DIR :=$(shell dirname $(shell find $(shell stack path --local-install-root) -name libHasCacBDD.a))
ARGS = --extra-lib-dirs ${LIB_DIR}

test:
    stack ${ARGS} test --fast -j4

Ugly, but it works.

ETA: The first line invokes the shell three times:

  • stack path to find out where packages are being installed
  • find to locate the specific file you need
  • dirname to get the directory

The remaining lines pass that directory to stack as an extra library directory. Doing this every time make is called avoids putting the path in a file, where it needs to be updated when the compiler or package version change.

bergey
  • 3,041
  • 11
  • 17
  • Thank you very much for your comment, that seems to be useful to be able to move the file once it has been built. I think this solution would not solve the problem because the error i get is when building the project, and it would not build anyway right? Unless i called it inbetween some operation of the build process. I get the feeling that the only way i'm going to be able to do it is inside the ```Setup.hs``` file, as a hook somewhere. Still, the code you provided to me would certainly be useful, i would just need to call it inside the Setup.hs file. – Javier Diego-Fernández Jul 11 '18 at 18:57
  • I think you said that `libHasCacBDD.a` is being built correctly, and put somewhere under your `.stack-work`. Does adding the path to `extra-lib-dirs` work? The code I gave locates the file, to help address your concerns about platform portability. – bergey Jul 12 '18 at 01:23