I am developing a Haskell library that uses a FFI to Rust. The library works but I’m trying to simplify its use.
In its current form, a configure and a Makefile compile the Rust portion and set up the paths so pkg-config can find the library.
Is there a better way to package this library, so that a different module that wants to use it can just declare the dependency and the compile/configure can happen without manual intervention?
Once you have polyglot build system requirements, I’d recommend just using Nix and insisting your users use Nix or maintain their misc installation methods themselves. Yeah, there’s a learning curve etc but it keeps things sane.
I’ve been looking into Nix/Flake, as it seems it would do what I expect. But I have not been able to set it up on my library and have not been able to find an example of how to do it.
I managed to fix it and it compiles now. I needed to specify the pre-processor explicity in Setup.hs and then there were some file paths that needed to be corrected to ensure header files are found.
If I use it as a dependency from another Haskell project, it compiles as expected along the rest of the dependencies but the final executable fails during the Linker, unable to find the Rust bindings.
I’ve set the library as static and shared, any ideas on what could help get the linker find the library?
I’m trying to wrap my head around Nix but I’m brand new to it and I haven’t been able to get it to work yet.
It’s actually not working. The library compiles but trying to run the test suite fails, saying that it can’t find the lib*.so file that the Rust compiler generated.
What is the proper way to tell Cabal where to find custom *.so files that are part of the current library, not something else installed system-wide?
I’ve set those and it successfully compiles. The problem is that during execution, the lib*.so created by the Rust compiler can’t be found unless I use pkgconfig-depends in the cabal file.
Which leads me back to having a bash script that sets a PATH to find this file.
I think one option is to go back to a Makefile, and make a target that needs to be run with sudo so it can place the files in /usr/....
My hope was to be able to package this as a self-contained library like some of the C FFI libs so you can just put it on your build-depends and everything would get compiled on its own.
But even some of those C FFI libs also need you to go and install some lib*-dev on your box through the package manager anyway.
Is anyone aware of a guide to make this work for stack (and hpack)?
I was able to get cargo-cabal to work on cabal, but have had zero luck making it work with stack. (Including the option of manually copying the built .dylib files to the system folders (/usr/local/lib)
I get the cryptic error when I compile:
ghc-9.8.1: panic! (the 'impossible' happened)
GHC version 9.8.1:
Don't understand library name rust_interop
CallStack (from HasCallStack):
panic, called at compiler/GHC/Unit/Info.hs:226:15 in ghc-9.8.1-a76c:GHC.Unit.Info
I have this working using only cabal, a custom Setup.hs file and a configure script that sets the paths correctly.
I do remember seeing this error during my many, many trial-and-error cycles, if I remember correctly this went away when I removed the Rust library from all the ...-libs fields in the Cabal file, and use it only on the pkgconfig-depends field.