Closed borsboom closed 6 months ago
I have also now uploaded a prerelease static musl build for stack-1.9.0.1
on https://github.com/nh2/stack/releases/tag/v1.6.5 and would appreciate testing.
As far as I remember,
system-ghc
picks it fromPATH
, so you could doPATH=/path/to/desired/ghc/bin:$PATH stack build
I don't understand what that means. I'm talking about the alpine ghc packages, see https://pkgs.alpinelinux.org/packages?name=ghc&branch=edge
Also, I think you can use stack's feature to configure custom compilers, so these might be two workarounds for now.
There is no custom compiler to install that works under alpine. GHC upstream doesn't provide one, stack doesn't and the distro only provides one arbitrary version, as already explained.
@hasufell I know that there's currently no ghc available on Alpine, I was just referring to
system-ghc you can have, not multiple at the same time
which sounded like "if there were multiple compilers available, it would be difficult to switch them using system-ghc
". But perhaps I misunderstood what you meant to say with that, and you meant something else?
I wasn't talking about the command system-ghc
.
@nh2 Of course there is ghc on Alpine: https://pkgs.alpinelinux.org/packages?name=ghc&branch=v3.8
I use it every day, but since stack cannot bootstrap on Alpine you have to use "system-ghc", which is the ghc version above. That's not like stack is meant to be used, so at the moment I rather use: cabal new-*
@mitchty (or anyone else watching this thread), I'd like to build bindists for alpine, where do I get started?
It looks like @redneb is building musl-based GHC bindists for recent GHC releases, and people seem to be able to install them on Alpine Linux using the standard ./configure --prefix=… && make install
that stack setup
uses. In theory, this may be all Stack needs to fully support Alpine Linux (plus a bit of logic to detect when running on a musl-based distro and choose a different bindist to download).
Any interested Alpine user out there who can give this a try? You'd use the setup-info configuration to point stack setup
to the right bindist.
edit: I see I linked to these a couple of years ago, but it doesn't look like anybody actually tried them (perhaps due to the following comment).
Update: I decided to try this myself. I added the following to my ~/.stack/config.yaml
:
setup-info:
ghc:
linux64-ncurses6:
8.6.5:
url: "https://github.com/redneb/ghc-alt-libc/releases/download/ghc-8.6.5-musl/ghc-8.6.5-x86_64-unknown-linux-musl.tar.xz"
And then ran stack setup
, which worked (once I apk add
ed the right prerequisites). I've been able to build a "hello world" program both as a dynamically linked and as a statically linked binary (using stack build --ghc-options='-optl-static -optl-pthread'
), and it seems to work. Next up: trying out building stack
itself statically linked.
Note for whomever implements detection of musl-based distributions: this node package appears to have decent libc detection logic that we could use as inspiration: https://github.com/lovell/detect-libc/blob/master/lib/detect-libc.js
Next up: trying out building
stack
itself statically linked.
This seems to have worked as well.
However, there is a problem that's exposed when I try to use the bindist with the upcoming stack-2.1 which does some extra sanity checking (I had been using stack-1.9.3 before): it fails to install a haddock
binary.
Downloaded ghc-ncurses6-8.6.5.
[…]
Installed GHC.
Found an invalid compiler at "/root/.stack/programs/x86_64-linux/ghc-ncurses6-8.6.5/bin/ghc-8.6.5": Control.Exception.Safe.throwString called with:
Could not find any of: ["/root/.stack/programs/x86_64-linux/ghc-ncurses6-8.6.5/bin/haddock-8.6.5","/root/.stack/programs/x86_64-linux/ghc-ncurses6-8.6.5/bin/haddock-ghc-8.6.5","/root/.stack/programs/x86_64-linux/ghc-ncurses6-8.6.5/bin/haddock","/root/.stack/programs/x86_64-linux/ghc-ncurses6-8.6.5/bin/haddock-ghc"]
Opened an issue on ghc-alt-libc for this here: https://github.com/redneb/ghc-alt-libc/issues/5
@redneb has very kindly, and quickly, uploaded new ghc 8.6.5 bindists that fix the haddock issue. I've tested them with stack-2.1 and they seem to work great (including stack haddock
). I've gone ahead and added stack setup
metadata for them in https://github.com/commercialhaskell/stackage-content/commit/f6eb573456c13457d75cb5cc8b3ddfe878147c90 with a new -musl
OS key suffix.
Now what's left is adding logic to stack setup
to detect when running on a musl-based distro and use the new -musl
OS key suffix to choose the bindist.
I have two remarks about this:
./configure --disable-ld-override --prefix=… && make install
. Without the --disable-ld-override
option, ghc will try to use ld.gold
as its linker, which in my tests causes it to segfault. This might not be needed for alpine because its binutils
package does not install ld.gold
, but it might cause problems in other musl based environments such as gentoo musl (which includes ld.gold
by default).libgmp
and libncursesw
do not match between gentoo and alpine. Of course this is a more general problem, even with glibc based builds.
- ghc will try to use
ld.gold
as its linker, which in my tests causes it to segfault
@redneb Is that filed somewhere? GHC should not segfault when using gold.
@redneb Is that filed somewhere? GHC should not segfault when using gold.
No I have not filed any bug for that, but I am not sure if this an issue with ghc. I am not sure if ld.gold
is officially supposed to work under musl; in the past I even had issues with the gcc
+ ld.gold
combination under musl, although admittedly, not any anymore.
@redneb I remember hearing/reading about some musl+gold problems, but I am quite sure that their respective authors want that these work well together.
So even if there's a segfault in gold
itself, it would be very useful to post it somewhere.
Is it perhaps https://sourceware.org/bugzilla/show_bug.cgi?id=23856 (which I filed from https://github.com/NixOS/nixpkgs/issues/49071#issuecomment-435663380)?
Is it perhaps https://sourceware.org/bugzilla/show_bug.cgi?id=23856 (which I filed from NixOS/nixpkgs#49071 (comment))?
This sounds awfully a lot like the issue I was seeing: the binaries I get from ghc
+ld.gold
segfault immediately when I run them. I created redneb/ghc-alt-libc#6 to track this issue.
(apologies to everyone for the off topic spam)
(apologies to everyone for the off topic spam)
I'm actually tempted to rename this issue to "Support musl-based Linux distributions" rather than Alpine Linux specifically, so it's not off topic in that case :)
Until GHC release team is releasing battle-tested musl-based bindists officially, I don't think we can "officially" support Alpine Linux anyway in Stack, so I'm not sure that part of the issue title should be a hold up either. But decent experimental support for musl-based distributions would be a huge step forward (in particular, being able to use it with an Alpine-based docker image that works with --docker
would make building statically linked Linux binaries really easy).
Anyone have any objections to me renaming the issue to "Support musl-based Linux distributions like Alpine Linux"?
Anyone have any objections to me renaming the issue to "Support musl-based Linux distributions like Alpine Linux"?
@borsboom Doesn't seem so, let's do it.
Hi, just wanted to confirm that this is still current exactly 4 years after ticket was initially opened.
I am having the same issue attempting to use "stack" for building "postgrest" on alpine 3.12 with currently available ghc on alpine.
alpine musl GHCs are already part of the official bindists: https://downloads.haskell.org/~ghc/8.10.1/
I am closing this issue given the passage of time and because Stack 2.15.3 does support Alpine Linux/x86_64 (tested via WSL).
@dysinger has had success building Stack on Alpine using GHC 8.0.1 from here: https://github.com/mitchty/alpine-linux-ghc-bootstrap. Once there is a Stackage LTS release that uses GHC 8, we can consider adding official support for Alpine Linux.