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

Binaries installed using cargo-binstall will not execute on NixOX #1329

Closed
NobodyXu opened this issue Aug 25, 2023 · 4 comments · Fixed by #1343
Closed

Binaries installed using cargo-binstall will not execute on NixOX #1329

NobodyXu opened this issue Aug 25, 2023 · 4 comments · Fixed by #1343

Comments

@NobodyXu
Copy link
Member

NobodyXu commented Aug 25, 2023

Binaries installed using cargo-binstall will not execute on NixOS, because they have an interpreter path that points to:

interpreter /lib64/ld-linux-x86-64.so.2

but for locally-built executables, the interpreter path is to the ld in the Nix store:

eliza@noctis:~ $ file /home/eliza/.cargo/bin/cargo-binstall
/home/eliza/.cargo/bin/cargo-binstall: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/ibp4camsx1mlllwzh32yyqcq2r2xsy1a-glibc-2.37-8/lib/ld-linux-x86-64.so.2, for GNU/Linux 3.10.0, with debug_info, not stripped

Originally posted by @hawkw in #19 (comment)

@NobodyXu
Copy link
Member Author

Solution:

We can modify crates/detect-targets to disable gnu if the interpreter does not exist or is not executable.

Originally posted on #19 (comment)

@passcod
Copy link
Member

passcod commented Aug 25, 2023

@hawkw What's the nix way here, can we rewrite glibc binaries to point to the right thing or call some kind of nix helper on install that does that? If musl works that's great, but if we can go one further and also support gnu that might be even better?

@NobodyXu
Copy link
Member Author

NobodyXu commented Aug 27, 2023

We might also want to add a glibc version check and another an environment override for targets

#19 (comment)

@NobodyXu
Copy link
Member Author

@passcod I suppose people can have a x86_64-nixos-linux-gnu which is built for nixos?

We also have x86_64-alpine-linux-musl, so it's not completely new.

NobodyXu added a commit that referenced this issue Sep 2, 2023
Fixed #1329

 - Refactor: Create `linux::detect_alternative_targets` to reuse code
   from other targets
 - Run `/lib/ld-linux-{cpu_arch}.so.1 --version` for checking glibc
   support instead of running `ldd --version` since it could be non-std
   glibc installation and does not provide
   `/lib/ld-linux-{cpu_arch}.so.1`
 - Check for non-std glibc and add fallback target
   `{cpu_arch}-{distro_name}-linux-gnu{abi}`
 - Add `{cpu_arch}-{distro_name}-linux-musl{abi}` fallback for musl
   libc, specially for Alpine since it has a
   `/lib/ld-musl-{cpu_arch}.so.1`
 - For unknown libc flavor, check for the target provided before
   fallback to musl

Signed-off-by: Jiahao XU <[email protected]>
github-merge-queue bot pushed a commit that referenced this issue Sep 2, 2023
* feat `detect-targets`: Improve support of non-std glibc/musl

Fixed #1329

 - Refactor: Create `linux::detect_alternative_targets` to reuse code
   from other targets
 - Run `/lib/ld-linux-{cpu_arch}.so.1 --version` for checking glibc
   support instead of running `ldd --version` since it could be non-std
   glibc installation and does not provide
   `/lib/ld-linux-{cpu_arch}.so.1`
 - Check for non-std glibc and add fallback target
   `{cpu_arch}-{distro_name}-linux-gnu{abi}`
 - Add `{cpu_arch}-{distro_name}-linux-musl{abi}` fallback for musl
   libc, specially for Alpine since it has a
   `/lib/ld-musl-{cpu_arch}.so.1`
 - For unknown libc flavor, check for the target provided before
   fallback to musl

Signed-off-by: Jiahao XU <[email protected]>

* feat `detect-targets`: Support glibc on musl target

Signed-off-by: Jiahao XU <[email protected]>

* feat `detect-targets`: Unify `Libc::{Gnu, Musl}` checks

since we can't really tell if we are on gnu or musl

Signed-off-by: Jiahao XU <[email protected]>

---------

Signed-off-by: Jiahao XU <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants