Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide statically-linked cabal-install releases #4941

Closed
TerrorJack opened this issue Dec 8, 2017 · 29 comments
Closed

Provide statically-linked cabal-install releases #4941

TerrorJack opened this issue Dec 8, 2017 · 29 comments
Assignees
Labels

Comments

@TerrorJack
Copy link
Collaborator

Current binary releases of cabal-install are not statically linked, thus depending on glibc, which makes them unusable on musl-based distros like Alpine Linux. It'd be nice if statically-linked binary releases (at least for x64 Linux) can be provided for cabal-install-2.0.0.1 and future versions.

@23Skidoo
Copy link
Member

23Skidoo commented Dec 8, 2017

Yep, makes sense. I'll try to do that for the next release. Can you point me to some resources on how to build statically-linked Haskell binaries? I know of https://www.fpcomplete.com/blog/2016/10/static-compilation-with-stack.

@23Skidoo 23Skidoo self-assigned this Dec 8, 2017
@23Skidoo 23Skidoo added this to the 2.2 milestone Dec 8, 2017
@TerrorJack
Copy link
Collaborator Author

@23Skidoo I built a static cabal for my own project, simply by adding a ld-options: -static line to cabal-install.cabal and building it in an Alpine image. No extra flags/hacks is needed.

For your convenience, you may use docker pull terrorjack/meikyu:ghc-8.2.2 to get the image I use myself, it has ghc, stack and cabal pre-installed. Or take a look at the master branch of https://github.com/TerrorJack/meikyu for the relatively simple build script for the image.

@23Skidoo
Copy link
Member

23Skidoo commented Dec 8, 2017

@TerrorJack Is there a similar 32-bit image?

@TerrorJack
Copy link
Collaborator Author

@23Skidoo Nope. The hard lifting is done by @mitchty who provides ghc packages on Alpine (which are used to bootstrap later ghc releases), yet there's only x86_64 and armhf versions available as of now.

@erebe
Copy link

erebe commented Dec 8, 2017

Same as @TerrorJack, I use this dockerfile https://github.com/erebe/wstunnel/blob/master/Dockerfile based from stock alpine images to build static binary. (thanks to @mitchty)

The blog post from fpcomplete is outdated, as @TerrorJack said only adding ld-options: -static in the cabal file of the project do the tricks.

I was planning to do a blog post to explain how to do it properly in order to avoid the hack explained in the fpcomplete blog post, but I was hoping for this issue #4925 to be resolved before doing it

@23Skidoo
Copy link
Member

23Skidoo commented Dec 8, 2017

@TerrorJack @erebe @mitchty Is it possible to use a 32-bit binary GHC distribution from https://www.haskell.org/ghc/download_ghc_8_0_2.html#linux_i386 with a 32-bit Alpine Docker image or do I need to build GHC myself?

@TerrorJack
Copy link
Collaborator Author

@23Skidoo You need to build it yourself, and since there's no ghc binary package for i386, you need to cross-compile it in a glibc based distro.

@23Skidoo
Copy link
Member

23Skidoo commented Dec 8, 2017

:-(

@mitchty
Copy link

mitchty commented Dec 8, 2017

I have it on my list to finish getting ghc ported/cross-compiled to the rest of alpine's archictectures, i386 would probably be the easiest of them.

What kind of timeframe were you looking at?

@23Skidoo
Copy link
Member

23Skidoo commented Dec 9, 2017

@mitchty That's great to hear! Thank you for working on this. I think that the next major release of cabal-install will be out at the end of January.

@mitchty
Copy link

mitchty commented Dec 10, 2017

@23Skidoo okie dokie, i'll poke around at the cross compiling again, cross compiling ghc is... not the most intuitive thing to do to be honest. And getting x86 as an arch has been asked by at least a few people, but just wasn't a priority for the initial port.

But compared to arm it shouldn't be too crazy. If I get it up and running I should be able to build alpine linux ghc bindists that you could use until apk packages are ready/built (or after for that matter).

@23Skidoo
Copy link
Member

@mitchty Thanks a lot!

@Ericson2314
Copy link
Collaborator

Ericson2314 commented Jan 27, 2018

We could probably cross compile for musl via nix very shortly.

CC @bgamari @dtzWill @kmicklas @taktoa

@23Skidoo
Copy link
Member

@mitchty Any updates? The 2.2 cabal-install release will be out in ~2 weeks, would be cool to have statically-linked 32-bit binaries for it as well.

@Ericson2314
Copy link
Collaborator

Musl cross landed (on staging) in nixpkgs. I can look into this now.

@23Skidoo
Copy link
Member

23Skidoo commented Mar 28, 2018

@Ericson2314 Are you still interested in this? Would be nice if you (or someone) could produce static cabal-install Linux binaries for 2.2.0.0.

@Ericson2314
Copy link
Collaborator

Yeah I'm still interested. It depends on NixOS/nixpkgs#37598 being resolved, but I can assist with that.

@23Skidoo
Copy link
Member

Great.

@nh2
Copy link
Member

nh2 commented Jul 19, 2018

Nix now makes it possible to build fully statically linked cabal-install builds.

This is based upon, among others, @Ericson2314's work mentioned just above.

I have completed such a build here

@23Skidoo 23Skidoo modified the milestones: 2.2, 2.4 Aug 29, 2018
@23Skidoo 23Skidoo modified the milestones: 2.4, 2.4.1 Sep 17, 2018
@hvr
Copy link
Member

hvr commented Oct 2, 2018

Quick note: It's not enough to naively think one can build statically linked executables and things will just work, as library routines like gethostbyname(3) and friends will not pick up the system wide name resolution configuration and/or NSS plugins and all that jazz. It's doable to make statically linked executables of cabal but it requires a bit more work to do it properly.

@23Skidoo
Copy link
Member

23Skidoo commented Oct 2, 2018

We can mark statically-linked cabal-install binaries "experimental" initially, maybe someone will then come up with a patch to fix the gethostbyname issue and other statically-linked-only problems.

@hvr
Copy link
Member

hvr commented Oct 3, 2018

@23Skidoo offering statically linked cabal-install binaries with a "use at your own risk" disclaimer pointing out the potential problems sounds good to me.

@nh2
Copy link
Member

nh2 commented Oct 3, 2018

gethostbyname(3) and friends will not pick up the system wide name resolution configuration

@hvr What do you mean by that? musl libc reads resolv.conf, like anything else does.

Correspondingly I'm also not quite sure what

a patch to fix the gethostbyname issue

would look like in @23Skidoo's comment.

and/or NSS plugins and all that jazz

Yes, NSS is a glibc specific feature. Probably not relevant unless somebody wants to resolve resolve .local domains with cabal, and doens't use localhost dnsmasq (most Linux distributions seem to do that these days).

@jkachmar
Copy link

Based on some discussion in haskell/ghcup#68 it sounds like this should be closed, given that http://downloads.haskell.org/cabal/cabal-install-2.4.1.0/cabal-install-2.4.1.0-x86_64-alpine-linux-musl.tar.xz is now available.

@nh2
Copy link
Member

nh2 commented Feb 13, 2019

that http://downloads.haskell.org/cabal/cabal-install-2.4.1.0/cabal-install-2.4.1.0-x86_64-alpine-linux-musl.tar.xz is now available.

That executable is not statically linked:

% file cabal
tmp/cabal: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, stripped
% ldd cabal
	linux-vdso.so.1 =>  (0x00007ffc4edda000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc80b0da000)
	libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fc80ae5a000)
	libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fc80ac52000)
	libc.musl-x86_64.so.1 => not found
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc80a888000)
	/lib/ld-musl-x86_64.so.1 => /lib64/ld-linux-x86-64.so.2 (0x00007fc80b2f4000)

@23Skidoo 23Skidoo modified the milestones: 2.4.1.0, 2.4.2.0 Apr 26, 2019
@phadej phadej modified the milestones: 2.4.2.0, 3.4 Nov 27, 2019
@ulysses4ever ulysses4ever removed this from the Considered for 3.4 milestone Aug 13, 2022
@ulysses4ever
Copy link
Collaborator

@nh2 I see some steady improvements in static-haskell-nix. I understand that it should in theory be possible now to build a statically-linked cabal-install. Are there any guidelines / blog posts describing how a Haskell software can benefit from static-haskell-nix? In particular, Cabal is using GitLab CI for making releases this day (see .gitlab-ci.yml in this repo). Would it be hard to integrate static binaries into this workflow? (The workflow is a bit involved, though, as per this wiki page.)

@Mikolaj
Copy link
Member

Mikolaj commented Aug 15, 2022

IIRC, the Alpine binaries on gitlab are statically linked, but they are not totally static. IIRC, they require pthreads that makes HEAD GHC fail on my ancient Ubuntu (cabal probably uses an older version of the pthreads so it doesn't fail). Unless I'm misdiagnosing why the binaries from HEAD GHC snapshots fail for me.

@ulysses4ever
Copy link
Collaborator

ulysses4ever commented Aug 16, 2022

At least,

❯ wget https://downloads.haskell.org/~cabal/cabal-install-3.8.1.0/cabal-install-3.8.1.0-x86_64-linux-alpine.tar.xz
...
❯ tar -xf cabal-install-3.8.1.0-x86_64-linux-alpine.tar.xz
...
❯ ldd cabal
	not a dynamic executable

ldd was used above (#4941 (comment)) to show that it's not static. So, that argument no longer applies. I propose we close this as completed and wait for a more detailed account of what's wrong with the curent alpine binary (if anything).

@Mikolaj
Copy link
Member

Mikolaj commented Aug 16, 2022

Yeah, I hope alpine is fine for most users. Thank you for the gardening. :) Closing.

@Mikolaj Mikolaj closed this as completed Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests