3 ms·
> Haskell was my favourite language for a decade. Now it’s Rust. Sigh... > Ten years in, I still don’t know how to make a statically linked executable with Ha
by ghostwriter 4y ago
> Haskell was my favourite language for a decade. Now it’s Rust.
Sigh...
> Ten years in, I still don’t know how to make a statically linked executable with Haskell.
0) I hope you're targeting Linux
1) Install host (system) GHC
2) Build a new GHC by using the host GHC and Musl Libc, and depending on license restrictions choose either bignum-native or GNU GMP (flags of https://hackage.haskell.org/package/ghc-bignum https://hackage.haskell.org/package/ghc-bignum). This is needed because the compiler will later inject some portions of the GHC components into user applications to support their awesome runtime system.
3) Use the newly built custom GHC to compile your projects with GHC's `-static` flag (needed for pure haskell libs) AND `--ghc-options='-optl-static -optl-pthread'` (needed for non-haskell stuff).
4) Profit
Note that on certain platforms it's not possible (without much of a low-level trouble) to statically link their libc implementations to the user applications. Apple in particular does everything to discourage developers from pursuing this goal[1][2].
[1] https://stackoverflow.com/a/5259427 https://stackoverflow.com/a/5259427
[2] https://michaelspangler.io/posts/statically-linking-on-macos.html https://michaelspangler.io/posts/statically-linking-on-macos...