Skip to main content

ghc-musl Part 3: lsupg With Stack

I started experimenting with building fully static executables of lsupg using the images that I creating using the refactored Earthfile described in ghc-musl Part 2: Earthly. This blog entry describes my progress using Stack.

As described in Building Static Executables With Stack, I can currently use Stack to build fully static executables of lsupg using the GHC 8.10.7, GHC 9.0.2, and GHC 9.2.2 images created by the Stack team. I changed this configuration to use ghc-musl images instead, and it worked without issue.

The lsupg project can also compile using GHC 8.8.4, but I had never tried building a static executable using that version. I tried using fpco/stack-build:lts-16, and I got the following error, reformatted here to split long lines.

ghc: panic! (the 'impossible' happened)
  (GHC version 8.8.4 for x86_64-unknown-linux):
        Prelude.chr: bad argument: 2634022915

Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug

--  While building simple Setup.hs (scroll up to its section to see the error)
using:

/home/stackage/.stack/programs/x86_64-linux/ghc-8.8.4/bin/ghc-8.8.4
  -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages
  -package base -main-is StackSetupShim.mainOverride -package Cabal-3.0.1.0
  /home/tcard/.stack/setup-exe-src/setup-mPHDZzAJ.hs
  /home/tcard/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs
  -o /home/tcard/.stack/setup-exe-cache/x86_64-linux-dkda49f7ca9b2441
  80d3cfb1987cbc9743/tmp-Cabal-simple_mPHDZzAJ_3.0.1.0_ghc-8.8.4

    Process exited with code: ExitFailure 1

The error occurred while building Setup.hs. This file is not really necessary anymore, but I confirmed that this error occurred whether the file existed or not.

I then tried using ghc-musl and got the same error. (The only difference was the reported GHC version, for x86_64-alpine-linux instead of x86_64-unknown-linux.)

Next, I tried building the static executable using Stack within the container instead of using the --docker option. I manually started a new container with the project mounted, copied the project to a temporary directory, and ran the following command. It built without issue!

# stack build --system-ghc --stack-yaml stack-8.8.4.yaml --flag lsupg:static

Next, I tried moving my ~/.stack directory and initializing a clean one. I tried the build again, and it worked! Apparently, something in my ~/.stack directory was causing the issue. I moved the old ~/.stack directory back, removed ~/.stack/setup-exe-src, and tried again. It worked!

With the ~/.stack state issue resolved, it is now possible to build fully static executables with any of the four GHC versions supported by the project.