-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
unknown NIX_CFLAGS_COMPILE flag causes compliation to fail #18998
Comments
I don't think zig should try to interpret these env vars at all. The nix specific code in zig IMO is misguided. |
as a workaround I made a custom 0.11 build with /lib/std/zig/system/NativePaths.zig#L42 deleted, which allowed me to continue work on my project |
I did run into the same issue. I currently solve that issue by running
|
@urso using that i either get |
That means your flake / nix env does not have correct buildInputs or you are not including pkg-config as nativeBuildInputs |
That's because zig is being too smart and reads those env vars, aka it's doing the bad thing and hiding build bugs in nix sandbox. I suggest including pkg-config in your nativeBuildInputs, that's the correct way of dealing with system deps. |
good catch, so this is the diff that fixed my build diff --git a/shell.nix b/shell.nix
index 0f9e8d5..e25da0c 100644
--- a/shell.nix
+++ b/shell.nix
@@ -5,7 +5,14 @@ pkgs.mkShell {
gcc
xorg.libX11
mesa_glu
+ pkg-config
];
hardeningDisable = [ "all" ];
+
+ # https://github.com/ziglang/zig/issues/18998
+ shellHook = ''
+ unset NIX_CFLAGS_COMPILE
+ unset NIX_LDFLAGS
+ '';
} thanks both |
update: the output binaries are not runnable
|
That's normal (on nixos), you need to run them in the develop shell that sets LD_LIBRARY_PATH, make a nix package that uses autoPatchelfHook, or use something like steam-run. It's also the reason zig2nix has convenience shells for this: https://github.com/Cloudef/zig2nix?tab=readme-ov-file#convenience-shell-for-multimedia-programs as well as ability to put any custom runtime deps in the zig-env if you use zig2nix flake: https://github.com/Cloudef/zig2nix/blob/master/flake.nix#L70 |
do you know how? https://nixos.wiki/wiki/Packaging/Binaries#Using_AutoPatchelfHook seems incompatible with my workflow |
If you don't want to package, on nixos your options are set LD_LIBRARY_PATH, use steam-run or something like nix-ld (Or use zig2nix and you get packaging for free as well) |
imo this is a regression, im using |
No zig should not do any smart decisions here. The problem is that you are linking against soname library, and this is the correct linking behavior with soname libraries, it does not link to the absolute path of that library but rather the "soname". The fact that the libraries are not found by default is nixos specific issue and you either have to use different distro or do it the nixos way. If you want to still embed the paths, you can instruct zig to insert multiple rpaths to the linked executable. |
The NativePaths.zig parses NIX_LDFLAGS to set rpaths https://github.com/ziglang/zig/blob/0.11.0/lib/std/zig/system/NativePaths.zig#L50-L55 thats why it worked for you before, but it's again something zig really should not do as these env variables are not meant to be used outside of nixpkgs. If zig wants to rely on env vars it should use the standard ones:
And to get the current zig behaviour one can do LDFLAGS=$NIX_LDFLAGS inside a nix shell. |
Zig Version
0.11.0
Steps to Reproduce and Observed Behavior
972f719bbd3de730d6f19a5ef52175486db365b7
at time of writingnix-shell
zig build -Dall
after upgrading from nixos 23.05 to 23.11
Expected Behavior
ignore the ones it doesnt recognize, a successful compile
The text was updated successfully, but these errors were encountered: