Packaging a library with a separate shared object

Hi folks! I'm working on packaging Qtah (my Qt bindings) for upload to Hackage. This is somewhat complicated, as I have some C++ glue code that I build into a shared library that the Haskell library needs. Currently, my build hooks are as follows, in: https://gitlab.com/khumba/qtah/blob/packaging/qtah/Setup.hs - postConf: Generate Haskell code in src/ and C++ code in cpp/. - preBuild: Add cpp/ to HookedBuildInfo.extraLibDirs because the build phase needs this needs this. - buildHook: Run make to build the C++ code into libqtah.so before the Haskell code builds. - copyHook and instHook: Copy libqtah.so into InstallDirs.libdir (~/.cabal/lib/.../qtah-*/). This installs successfully, but ultimately doesn't work because the Haskell libHSqtah*.so that gets built can't find libqtah.so. The installation directory ~/cabal/lib/.../qtah-*/ isn't on libHSqtah*.so's RUNPATH (which makes sense, it's not known at link time). I could create a separate package for the C++ bits, but I'd rather not do that unless necessary (there's already a qtah-generator package as well). I can't see how I can avoid doing this though. Are there any Cabal experts that could point me in the right direction, or confirm that I'll need to split the package? Many thanks, Bryan

On 2016-06-30 07:03 PM, Bryan Gardiner wrote:
I'm working on packaging Qtah (my Qt bindings) for upload to Hackage. This is somewhat complicated, as I have some C++ glue code that I build into a shared library that the Haskell library needs.
Currently, my build hooks are as follows, in: https://gitlab.com/khumba/qtah/blob/packaging/qtah/Setup.hs
- postConf: Generate Haskell code in src/ and C++ code in cpp/.
- preBuild: Add cpp/ to HookedBuildInfo.extraLibDirs because the build phase needs this needs this.
- buildHook: Run make to build the C++ code into libqtah.so before the Haskell code builds.
- copyHook and instHook: Copy libqtah.so into InstallDirs.libdir (~/.cabal/lib/.../qtah-*/).
This installs successfully, but ultimately doesn't work because the Haskell libHSqtah*.so that gets built can't find libqtah.so. The installation directory ~/cabal/lib/.../qtah-*/ isn't on libHSqtah*.so's RUNPATH (which makes sense, it's not known at link time).
I don't know how to write custom Setup.hs, so I don't know how to do the following, but the theory is: When creating libHSqtah*.so, the linker needs to be told: -Wl,-rpath,xxx Replace xxx by InstallDirs.libdir. This is how to set RUNPATH (or is it RPATH?).

On Mon, 4 Jul 2016 21:39:14 -0400
"Albert Y. C. Lai"
On 2016-06-30 07:03 PM, Bryan Gardiner wrote:
I'm working on packaging Qtah (my Qt bindings) for upload to Hackage. This is somewhat complicated, as I have some C++ glue code that I build into a shared library that the Haskell library needs.
Currently, my build hooks are as follows, in: https://gitlab.com/khumba/qtah/blob/packaging/qtah/Setup.hs
- postConf: Generate Haskell code in src/ and C++ code in cpp/.
- preBuild: Add cpp/ to HookedBuildInfo.extraLibDirs because the build phase needs this needs this.
- buildHook: Run make to build the C++ code into libqtah.so before the Haskell code builds.
- copyHook and instHook: Copy libqtah.so into InstallDirs.libdir (~/.cabal/lib/.../qtah-*/).
This installs successfully, but ultimately doesn't work because the Haskell libHSqtah*.so that gets built can't find libqtah.so. The installation directory ~/cabal/lib/.../qtah-*/ isn't on libHSqtah*.so's RUNPATH (which makes sense, it's not known at link time).
I don't know how to write custom Setup.hs, so I don't know how to do the following, but the theory is:
When creating libHSqtah*.so, the linker needs to be told: -Wl,-rpath,xxx Replace xxx by InstallDirs.libdir. This is how to set RUNPATH (or is it RPATH?).
And since installing happens after building, this will in fact require two packages. Okay, thanks Albert. (RUNPATH appears to be the new and preferred way since it doesn't shadow LD_LIBRARY_PATH, and "-Wl,-rpath=xxx,--enable-new-dtags" looks like the magic string...) I went ahead and did the split, and things are working with some small catches: executables must be linked dynamically because the necessary RUNPATH isn't set on a statically-linked executable, and I can't seem to inject the libdir into "cabal test" via HookedBuildInfo the same way I can with "cabal build". But overall it works! Thanks, Bryan
participants (2)
-
Albert Y. C. Lai
-
Bryan Gardiner