I've done some reading around the internet for statically linking Rust binaries with a Haskell project, and I have come up with a working example (heavily based on this blog post: https://github.com/jssblck/haskellrustlink.
It works, but has a couple things that are non-ideal:
- It requires fully qualified paths in
extra-lib-dirs. - It builds and runs successfully, but the language server shows an error in the
Extmodule: "Loading static libraries is not supported in this configuration. Try using a dynamic library instead".
The main reason the first point is a problem is that the main project I'm trying to make work needs to compile for Windows, macOS, and Linux, so installing the Rust .a somewhere global isn't ideal because it'll need to be different for Windows (although it's not the end of the world). The second point is more just annoying.
Does anyone know of a way to work around these problems in a reasonably portable manner?
Versions:
; cabal -V
cabal-install version 3.6.2.0
compiled using version 3.6.2.0 of the Cabal library
; ghc -V
The Glorious Glasgow Haskell Compilation System, version 9.0.2
; rustc -V
rustc 1.63.0 (4b91a6ea7 2022-08-08)
; cargo -V
cargo 1.63.0 (fd9c4297c 2022-07-01)