Unable to build static binary for musl with C dependencies #622
Closed
uulm-janbaudisch
started this conversation in
General
Replies: 2 comments 2 replies
-
Hi @uulm-janbaudisch, I don't have a lot of experience with either musl or mimalloc so take this with a big grain of salt! I'm not entirely certain if mimalloc itself supports being built against musl directly (perhaps it assumes certain glibc symbols?). According to https://www.tweag.io/blog/2023-08-10-rust-static-link-with-mimalloc/ it sounds like it might need some patches to be compatible? |
Beta Was this translation helpful? Give feedback.
1 reply
-
So it seems the only this missing was TARGET_CC =
let
cc = pkgs.pkgsStatic.stdenv.cc;
in
"${cc}/bin/${cc.targetPrefix}cc"; |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to build a static executable for the
x86_64-unknown-linux-musl
target.Here is an example repo for this problem: https://github.com/uulm-janbaudisch/nix-rust-static
The following actions run shows the errors: https://github.com/uulm-janbaudisch/nix-rust-static/actions/runs/9208714825/job/25331530984
Flake
When not using dependencies that build C code, the approach from the documentation works fine.
When using a crate like mimalloc that builds C code this approach seems to not work for me.
In this case I get errors like the following:
These look like
glibc
internals. So I guess somehow for the build of the C code ofmimalloc
aglibc
gcc
is used.When using
pkgs.pkgsStatic
instead ofpkgs
, I get the following error:However, when entering a development shell for the dependencies (
nix develop .#deps-pkgsStatic
in case of the example), acargo build
invocation does work and indeed produces a statically linked binary.Am I missing some confiugration or setting up something wrong?
Beta Was this translation helpful? Give feedback.
All reactions