zig icon indicating copy to clipboard operation
zig copied to clipboard

Zig NativeTargetInfo's hardcoded /usr/bin/env is not Nix-friendly

Open mitchellh opened this issue 2 years ago • 3 comments

Zig Version

0.11.0-dev.1836+28364166e (but it doesn't matter)

Steps to Reproduce and Observed Behavior

The Zig package on Nix requires this patch: https://github.com/NixOS/nixpkgs/blame/e6e389917a8c778be636e67a67ec958f511cc55d/pkgs/development/compilers/zig/0.10.nix#L48-L51

If I use a precompiled zig without that patch, then the dynamic linker used for built binaries is wrong, which leads to GLIBC mismatches (see https://github.com/mitchellh/zig-overlay/issues/21).

Expected Behavior

It should use the correct dynamic linker, see the patch.

I'm not sure what the right generic answer to this is. An environment variable to override the path to env (or any binary to inspect) would work, but is clunky. Detecting NixOS is also an option, in which case you could inspect a different binary. I just wanted to get a tracking issue up because I couldn't find one.

mitchellh avatar May 29 '23 18:05 mitchellh

TBH I'm still in favor of using getconf GNU_LIBC_VERSION directly, it's an utility specifically for getting this information. BTW can you please check output of this command on your Nix system? It should be like this: glibc 2.35 If it does not have version of selected glibc (I guess? sorry, IDK Niz terminology), then it's not so „guaranteed to work” as I thought and will finally throw this path (in my mind) away.

BratishkaErik avatar May 29 '23 19:05 BratishkaErik

@BratishkaErik getconf GNU_LIBC_VERSION does indeed work with nix shells:

$ getconf GNU_LIBC_VERSION
glibc 2.35 # host glibc
$ nix develop
$ getconf GNU_LIBC_VERSION
glibc 2.37 # nix glibc

kknives avatar Jul 10 '23 17:07 kknives

The dynamic linker is now configurable via standardTargetOptions. Usage: nix build -Ddynamic-linker=...

This option is also exposed to Zig's cmake build (usage example with Nix).

Edit: What's missing for this issue to be resolved is removing the hardcoded env path (accepted solution).

erikarvstedt avatar Apr 19 '24 10:04 erikarvstedt