[SOLVED] Building [servant-server] on Alpine Linux fails with linker error

I hope someone has already done this before, because this is kind of out of my comfort zone:

I’m trying to build an Alpine Linux docker image to build our code on, and I thought I’d try the ghc-musl images.
So far so good, but now I’m at the point where it’s trying to build wai-app-static because of servant-server, and I get the following error:

wai-app-static > Preprocessing executable 'warp' for wai-app-static-3.1.8..
wai-app-static > Building executable 'warp' for wai-app-static-3.1.8..
wai-app-static > [1 of 1] Compiling Main
wai-app-static > Linking .stack-work/dist/aarch64-linux/ghc-9.2.8/build/warp/warp ...
wai-app-static > /usr/lib/gcc/aarch64-alpine-linux-musl/bin/ld: /root/.stack/snapshots/aarch64-linux/90c4bf6db80e5043083a5d99a748e5c0d2deda42eb9b8614d67e82e4ae4536f7/9.2.8/lib/aarch64-linux-ghc-9.2.8/simple-sendfile-0.2.31-L8f2VR7YUNWHGWBIC85RU7/libHSsimple-sendfile-0.2.31-L8f2VR7YUNWHGWBIC85RU7.a(Linux.o): in function `simplezmsendfilezm0zi2zi31zmL8f2VR7YUNWHGWBIC85RU7_NetworkziSendfileziLinux_zdwsendfileloop_info':
wai-app-static > (.text+0x784): undefined reference to `sendfile64'                     
wai-app-static > collect2: error: ld returned 1 exit status                             
wai-app-static > `gcc' failed in phase `Linker'. (Exit code: 1)

I can’t seem to find a (C?) library that has this function, or have any idea how I would get around this issue. I hope someone else has already had this issue, since building servant is a pretty common thing.


EDIT: Added extra lines at the top of the example; it seems it fails because it tries to build the warp executable from the wai-app-static .cabal file. :thinking: Is there a way to ignore the executable? --skip wai-app-static:exe:warp doesn’t seem to work

(I’m building with stack --resolver lts-20.26 build --only-dependencies --ghc-options="-j" --system-ghc --skip wai-app-static:exe:warp)

@benz0li Do you maybe know how to make this work?

*I’ve also apk add gcompat, but that doesn’t seem to work either.

@Vlix Is there a public repository where I can see what you are trying to do [using GHC musl]?

If so,

  1. open an issue in your own public repository first
  2. then open an issue at Issues · benz0li/ghc-musl · GitHub

E.g.

  1. Fix linux static build by pinning ghc-musl container version by paulcadman · Pull Request #3132 · anoma/juvix · GitHub
  2. `Error loading shared library -lncursesw` using latest linux/amd64 9.8.2 tag · Issue #10 · benz0li/ghc-musl · GitHub

@Vlix IMHO you won’t get much help here, as my images are deemed to be unofficiall and untested.

Maybe helpful: GHC 9.4.5 x86_64, linker error during static build with stack · Issue #1 · benz0li/ghc-musl · GitHub ff

Unfortunately no, I’m using our company’s code base for this.

This just happens when trying to build servant-server on the ghc-musl:9.2.8-linux-arm64v8 image using the 3.20 repositories (we need libpq-dev-16), so it should be easy to reproduce.

Ah, I found the solution:

Stackage LTS 20.26 (GHC 9.2.8) has simple-sendfile-0.2.31, which causes this issue under the hood. So I’ve set our stack.yaml to use simple-sendfile-0.2.32, which doesn’t use the sendfile64 symbol anymore.
Now it builds again :slight_smile:

2 Likes