How do I get GHC for CentOS 7 aarch64?
The problem:
- Our project needs GHC 9.0.2, and we need to build it on CentOS 7 aarch64
- Upgrading the OS is not an option, and ideally we would make it easy to distribute to all our devs (i.e. just distribute the GHC binary-dist, without also needing to distribute newer glibc's)
- The GHC 9.0.2 aarch64 binary links to glibc 2.27, but CentOS 7 has glibc 2.17
- CentOS 7 provides GHC 7.6 via yum
What we've tried:
- Use GHC 7.6 to build 7.8 (and build our way up)
- Building 7.8 immediately gives "Unknown arch aarch64"
- Install GHC 8.0 in Ubuntu bionic (which is also glibc 2.17) to build 8.4 (and build our way up), then copy the binary-dist into CentOS 7
- This gave us errors like
/tmp/ghc31887_0/ghc_3.hc:22:6: error: error: ‘ghczmprim_GHCziTypes_Module_static_info’ undeclared here (not in a function) (W_)&ghczmprim_GHCziTypes_Module_static_info, ((W_)&ghc_GhcPrelude_zdtrModule2_closure+1), ((W_)&ghc_GhcPrelude_zdtrModule1_closure+1), 0x3UL ^ /tmp/ghc31887_0/ghc_3.hc:22:1: error: error: initializer element is not constant (W_)&ghczmprim_GHCziTypes_Module_static_info, ((W_)&ghc_GhcPrelude_zdtrModule2_closure+1), ((W_)&ghc_GhcPrelude_zdtrModule1_closure+1), 0x3UL ^ /tmp/ghc31887_0/ghc_3.hc:22:1: error: error: (near initialization for ‘ghc_GhcPrelude_zdtrModule_closure[0]’) `gcc' failed in phase `C Compiler'. (Exit code: 1) <<ghc: 108215128 bytes, 48 GCs, 5744830/10695440 avg/max bytes residency (4 samples), 32M in use, 0.001 INIT (0.001 elapsed), 0.068 MUT (0.093 elapsed), 0.040 GC (0.040 elapsed) :ghc>> make[1]: *** [compiler/ghc.mk:446: compiler/stage1/build/GhcPrelude.o] Error 1 make: *** [Makefile:125: all] Error 2
- This gave us errors like
- Use GHC 9.0 from Nix and rebuild GHC 9.0
- The rebuilt GHC 9.0 still links to Nix libc
- We don't want to force all devs to install Nix just for this
- Build glibc 2.27 on CentOS7, and installing GHC 9.0 from the aarch64 bindist using the new glibc
- This involved rebuilding gcc + glibc
- Got failures invoking
ghc-cabal-bindist
linked to the new glibc
I know about this doc: https://gitlab.haskell.org/ghc/ghc/-/wikis/building/cross-compiling. I could try building on a new CentOS Stream aarch64 system and cross compile to an older glibc, but I'm not sure how to link the older glibc. I could also try building on CentOS 7 x86_64 and cross compile to aarch64, but I don't know how to do this. The doc just says "get a C compiler that can generate code for the target platform", but I'm not sure how to get such a compiler.
Reddit thread: https://www.reddit.com/r/haskell/comments/123wz5x/help_building_ghc_for_centos_7_aarch64/