Open wolfgangwalther opened 9 months ago
Once we can make this work, let's not forget Raspberry PI as a target: #3080 and #3086
Remove all Template Haskell from PostgREST and its dependencies. This is not easy, because a few transitive dependencies use TH and for example the whole hasql ecosystem depends on them. We also use it ourselves for the Paths_ module, although that could probably be worked around.
I have been working on this a while ago. All Template Haskell is removed by now, except for hasql and swagger2. hasql is already updated upstream, we just need to update to the new version. To remove swagger2, we will need to do #1698.
All Template Haskell is removed by now, except for hasql and swagger2. hasql is already updated upstream, we just need to update to the new version. To remove swagger2, we will need to do #1698.
The last time I tried updating to the new hasql version, I think the result was that we'd need to update to at least GHC 9.6 for the nix build. But the static build is currently broken for GHC 9.6 in nixpkgs - because of Template Haskell.
So it seems like we will need to solve the OpenAPI / swagger2 stuff first, before we can go ahead.
We have been building a static executable for x64-linux for quite a while now. From this, the minimal docker image is created.
It would be really cool, if we could build the static executable on other platforms, too - and then create a multi-layer docker image, which provides minimal image size for different platforms.
One way to do this would be to run a nix environment on linux x64 and build the static executable for other platforms via cross-compiling.
This issue collects the current state of affairs.
I have been building GHC 9.4.8 as a cross-compiler for aarch64 successfully. However, when compiling PostgREST and its dependencies a major challenge comes up quickly: Template Haskell.
Template Haskell is a challenge, because it needs to be run during compilation. Because the cross-compiler compiles for the target platform, the compiled TH code can't be executed on the build platform. GHC will then fail like this:
There are a few different possible approaches how to deal with that:
Paths_
module, although that could probably be worked around.ghc-iserv
executable. This is basically a wrapper around theGHCi
library - so it allows to execute compiled code. For a GHC cross-compiler, this executable is built for the target platform. This can therefore be run withqemu
and passed to-fexternal-interpreter
. This should make Template Haskell just work. I tried this with GHC 9.4.8 and was able to make it work - but at some point hit a compiler bug in GHC 9.4.8 when cross-compiling to aarch64. My understanding is, that this bug was fixed in GHC 9.6 and 9.8 - but not in the 9.4 series. Therefore, I tried upgrading to GHC 9.6 / 9.8, but couldn't make that work, yet. GHC 9.6 doesn't build forpkgsStatic
in nixpkgs, yet - and GHC 9.8 does build forpkgsStatic
, but fails with the same TH-related error message as mentioned above, but already forpkgsStatic
(no cross-platform-compiling involved, yet). This is tracked in https://github.com/NixOS/nixpkgs/issues/275304.The last approach is the most promising in principle and is also tracked in https://github.com/NixOS/nixpkgs/issues/248979 upstream.