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

meta: fix 'zig build -Denable-llvm' on nixos 24 #22728

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nektro
Copy link
Contributor

@nektro nektro commented Feb 3, 2025

No description provided.

@nektro nektro changed the title meta: fix 'zig build -Denable-llvm' on nixos meta: fix 'zig build -Denable-llvm' on nixos 24 Feb 3, 2025
@alexrp alexrp added this to the 0.14.0 milestone Feb 3, 2025
@alexrp alexrp force-pushed the nektro-patch-56893 branch from b82afa0 to 21dfee7 Compare February 3, 2025 14:46
Copy link
Member

@alexrp alexrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire code path looks insanely sus to my non-NixOS-using sensibilities but I guess one more flag isn't going to be the end of the world.

@Jan200101
Copy link
Contributor

I'm not entirely sure what this is suppose to do.
Zig already ignores any C flags it doesn't recognize, what does this change which fixes building on nixos?

@nektro
Copy link
Contributor Author

nektro commented Feb 5, 2025

it prevents this

[nix-shell:~/src/zig/build]$ ./stage3/bin/zig build -p ./stage4 -Doptimize=ReleaseSafe -Denable-llvm
install
└─ install zig
   └─ zig build-exe zig ReleaseSafe native failure
error: warning: Unrecognized C flag from NIX_CFLAGS_COMPILE: -idirafter
warning: Unrecognized C flag from NIX_CFLAGS_COMPILE: /usr/include

upon further inspection it does appear a binary may still have been produced

[nix-shell:~/src/zig/build]$ ll ./stage4/bin/zig 
-rwxr-xr-x 1 meghan users 138913688 Feb  5 02:08 ./stage4/bin/zig
[nix-shell:~/src/zig/build]$ ./stage4/bin/zig version
0.14.0-dev.3051+cf059ee08

@erikarvstedt
Copy link
Contributor

In Nix build environments on Linux, -idirafter in NIX_CFLAGS_COMPILE is usually not set by the stdenv or any pkgs.
But it might be set by default on Darwin (see this nixpkgs sourcegraph search).
@nektro, are you on Darwin?

In any case, -idirafter shouldn't be silently ignored, because a user might have intentionally added this flag.

@nektro
Copy link
Contributor Author

nektro commented Feb 5, 2025

no im on nixos 24.05 linux

@erikarvstedt
Copy link
Contributor

Related: #18998

@nektro
Copy link
Contributor Author

nektro commented Feb 5, 2025

its odd because if i echo $NIX_CFLAGS_COMPILE inside my zig dev environment i get this and no sign of -idirafter

-frandom-seed=zpc3qrs0li
-isystem /nix/store/zps3l0mc26r7bvjqd8x0y1lbc6gmbdvn-gnumake-4.4.1/include
-isystem /nix/store/06q0p7bhn2ffxxya20rrfqdib3h32csn-zlib-1.3.1-dev/include
-isystem /nix/store/q474makx3105m1493i8fg8al1pf8z18p-libxml2-2.13.5-dev/include
-isystem /nix/store/9i7q9wy845i5na9bccpdial1va49gsr9-llvm-19.1.7-dev/include
-isystem /nix/store/69v6c64pn1ay26207b0cmzi40qpr9q0w-ncurses-6.4.20221231-dev/include
-isystem /nix/store/zj8ywgyz8nnhq995q798r5hhqlndbars-lld-19.1.7-dev/include
-isystem /nix/store/6fmmfc0fa3wzyb02nmsx6qd73cmka91f-clang-19.1.7-dev/include
-isystem /nix/store/zps3l0mc26r7bvjqd8x0y1lbc6gmbdvn-gnumake-4.4.1/include
-isystem /nix/store/06q0p7bhn2ffxxya20rrfqdib3h32csn-zlib-1.3.1-dev/include
-isystem /nix/store/q474makx3105m1493i8fg8al1pf8z18p-libxml2-2.13.5-dev/include
-isystem /nix/store/9i7q9wy845i5na9bccpdial1va49gsr9-llvm-19.1.7-dev/include
-isystem /nix/store/69v6c64pn1ay26207b0cmzi40qpr9q0w-ncurses-6.4.20221231-dev/include
-isystem /nix/store/zj8ywgyz8nnhq995q798r5hhqlndbars-lld-19.1.7-dev/include
-isystem /nix/store/6fmmfc0fa3wzyb02nmsx6qd73cmka91f-clang-19.1.7-dev/include

@@ -37,6 +37,10 @@ pub fn detect(arena: Allocator, native_target: std.Target) !NativePaths {
if (mem.startsWith(u8, word, "-frandom-seed=")) {
continue;
}
if (mem.eql(u8, word, "-idirafter")) {
_ = it.next().?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? will incorrectly crash if missing arg. also the information must not be discarded.

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 this pull request may close these issues.

5 participants