-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
ghc: support musl-native! #43369
ghc: support musl-native! #43369
Conversation
These prebuilt binaries need to be used with glibc, it doesn't matter what we're using otherwise. This may seem a bit strange but has the huge advantage of not needing to create/host/download musl-specific variants, and instead continue to use the official ones from upstream.
Fixes conftest failure that I believe ends up using the wrong dynamic linker.
cc @nh2 as this is very relevant for https://github.com/nh2/static-haskell-nix (and anyone interested in using haskell w/musl). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Thanks! Merging optimistically and to facilitate testing, feedback appreciated even so :). |
Aw bummer the glibc drop-in doesn't quite work on aarch64, might need to be hit with a heftier hammer 😇 . |
@dtzWill I don't quite get how I'm supposed to use it. to
and build I get
That is the assertion https://github.com/dtzWill/nixpkgs/blob/e065779af185b07566b9bbc4d2fc2ea70fdf3856/pkgs/development/compilers/ghc/8.2.1-binary.nix#L6-L7 |
@nh2:
|
@dtzWill Ah, OK! Thanks for these explanations, I really need those. I'm fine with Haskell and linkers but I'm still quite new to how nixpkgs actually does cross-compilation things and what functions are available, so definitely point out when I'm doing things that are more complicated than they should be. I'm hitting one problem: On your old commit, I did
this now fails with |
As mentioned on IRC and such, but posting here for anyone else; I poked at your repository, here's the sort of thing I ended up with (including answer to your It's a start! |
Wow awesome, thanks a lot! I'll check that out. |
@dtzWill This looks ultra promising, with your PR on my project the binary size of the static exe also seems to have gone way down: Before (https://github.com/nh2/static-haskell-nix/tree/9f5351aefda0ddc3c1e8482b4acfbb8077323485):
After (your PR):
Pretty fantastic size reduction! I don't know what's the reason; I tried to compare the binaries but unfortunately they are stripped (see also #43506) so I can't easily compare the symbols present, so I have to rebuild the old one again in a non-stripped fashion which will have to wait until tomorrow because I GC'd the musl-GHC. |
OK I have investigated this difference now: I have built the mini
Totally awesome! I don't know yet why this difference exists, maybe you can tell me @dtzWill. |
I have now also built the same excutable with
When building all dependencies with
(all these exes are stripped) But with our way, it's only 2.7 MB! So it seems we have found a way that makes executables significantly smaller than the current standard way of building Haskell (4x smaller in this case)! |
@nh2 first of this is pretty great! I'm a bit confused about your symbol listings though. The first few lines of
Maybe I don't understand Also, your Your stack builds I assume are non-muslc? You might want to do a symbol comparison with those as well to see why |
@angerman This is because of the primitive post-processing that I'm doing to get of the package IDs as mentioned above, simply removing everything before the first underscore. That turns e.g.
into
The scotty app ( So I suspect that it's because I don't use any If I use this diff: main = scotty 3000 $ do
get "/:word" $ do
- beam <- param "word"
+ beam <- jsonData
html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"] then I get some aeson functions, but still only those that are actually needed (131 in this case):
That is true but to get |
@nh2 can you upload the binaries somewhere? |
These have debugging symbols ( |
What do I need to test this on Arch Linux? Earlier this year I used Nix for Haskell dev for about a month, but eventually went back to stack. I'm releasing a binary app soon, and am very much interested in this drastic code size reduction. |
@fosskers Right now you have to build with musl. Try adding your executable here: https://github.com/nh2/static-haskell-nix/blob/627a8c5f86719531e1b1237aec4f5f85982cbd6c/survey/default.nix Instructions on https://github.com/nh2/static-haskell-nix/tree/627a8c5f86719531e1b1237aec4f5f85982cbd6c#building-arbitrary-packages |
@dtzWill I suspect the approach of using both We now get segfaults with this approach: #118731 Why does/did this approach make sense? Isn't it generally disallowed to use the musl and glibc in the same binary, e.g. here: Or should |
@dtzWill I suspect that your approach here exploitet some accidental ABI compatibility between musl and glibc, and that with the change linked in #118731 (commit in musl But you know these topics much better than me, so some review of this suspicion would be appreciated :) |
\o/
Examples:
pkgsMusl.bench
(=pkgsMusl.haskellPackages.bench
),pkgsMusl.shellcheck
, ...This makes it possible to:
and avoids the need for cross-compilation and
potential issues that entails.
Many packages now build and seem to work,
although a few do not and have not been investigated.
The failures I did look at appear to be the sort that
are rather plausibly caused by using musl vs glibc.
(details in date/timezone, string formatting, locale usage, etc.)
For anyone interested in testing this, consider using the 'allvm' cachix to save time,
it has a number of GHC variants and ghc843 packages available.
Oh and any needed dependencies not available on cachix.nixos.org,
not sure how signiicant this is (but I believe includes LLVM at least).
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)