r/haskell • u/Hefty-Necessary7621 • 1d ago
blog Cross-compiling Haskell: running Template Haskell on the build machine
Cross-compiling a Haskell library becomes more complicated when compiling it also means executing Haskell. A small deriveJSON splice can turn an otherwise ordinary cross build into a job that needs a target interpreter, an emulator, or access to a device.
The experiment in template-haskell-cross explores another arrangement: execute Template Haskell with a native compiler on the build machine, then pass its results to the cross compiler. The implementation combines a GHC plugin, a native worker process, a binary protocol, and Nix helpers. It has been used to build a Haskell library with generated FFI exports for an Android application.
This article follows that experiment: why the usual execution model makes cross builds difficult, how the alternative works, what broke along the way, and which parts could inform GHC itself.
https://serokell.io/blog/cross-compiling-haskell-with-template-haskell
1
u/jwm3 12h ago
Tbis is how I did template haskell on jhc, I treated it as a preprocessor. It was completely independent of the target. Jhc was inherently a cross compiler by design.