NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.03k stars 14.03k forks source link

Can no longer build GHC with Musl #57238

Closed albertov closed 5 years ago

albertov commented 5 years ago

GHC can no longer be built with the Musl libc because the ghc822Binary compiler needed to bootstrap no longer passes the install test. This prevents fully static executables from being produced with this tool chain.

I've git bisected and 0450d28a (cc @dtzWill) was the commit that introduced the regression. To reproduce:

$ NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/0450d28a.tar.gz nix-build '<nixpkgs>' -A pkgsMusl.haskell.compiler.ghc822Binary --no-out-link
(....)
running install tests
[1 of 1] Compiling Main             ( main.hs, main.o )
Linking main ...
/nix/store/wvj2kzhypkkwqx6qjcghm60bz6pqlqzz-binutils-2.31.1/bin/ld: /nix/store/f0061cv30fk6d2lxrivakbwqk0fqvlgp-ghc-8.2.2-binary/lib/ghc-8.2.2/rts/libHSrts.a(Hpc.o): in function `startupHpc':

/home/ben/bin-dist-8.2.2-Linux/ghc/rts/Hpc.c:214:0: error:
     undefined reference to `__strdup'
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)
builder for '/nix/store/i3s9a1zpma6pscf6xdi91r4h0hvyy87a-ghc-8.2.2-binary.drv' failed with exit code 1
error: build of '/nix/store/i3s9a1zpma6pscf6xdi91r4h0hvyy87a-ghc-8.2.2-binary.drv' failed

The previous commit, b262be32, works:

NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/b262be32.tar.gz nix-build '<nixpkgs>' -A pkgsMusl.haskell.compiler.ghc822Binary --no-out-link
(...)
running install tests
[1 of 1] Compiling Main             ( main.hs, main.o )
Linking main ...
compilation ok
/nix/store/pxd37xckl30yfky2rbj3a7bhz9fgvjkl-ghc-8.2.2-binary
nomeata commented 5 years ago

@albertov, I just noticed that you are trying build a completely static system with

$ nix-build '<nixpkgs>' -A pkgsMusl.haskell.compiler.ghc822Binary --no-out-link

instead of cross-compiling using musl, where you would use, say, nix-build -A pkgsCross.musl64.hello. The latter would not try to build a static GHC, but use the normal GHC to build static executables.

Is that what you intended?

albertov commented 5 years ago

@nomeata yes this is intended. I was trying to upgrade an existing project which builds static haskell exes to 19.03 which failed on this step. Just posted the failing derivation to ease reproduction. It should be possible to reproduce by trying to build any haskell executable through the pksMusl attribute (static or dynamic)

nomeata commented 5 years ago

Ok, just checking (and to let possible readers know that they can also get static Haskell executables through pkgsCross.musl64)

albertov commented 5 years ago

I should also mention that I managed to fix my build by overriding musl to undo the changes done in the failing commit, namely, downgrading musl from 1.1.21 to 1.1.20. with the previos musl version i can build static musl haskell exes with 19.03 and unstable. So it seems like for some reason the ghc binary needed to bootstrap the musl ghc breaks with newest musl.