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

Zig fails to get the include paths on NixOS Unstable #8269

Closed
sagehane opened this issue Mar 16, 2021 · 2 comments · Fixed by #8667
Closed

Zig fails to get the include paths on NixOS Unstable #8269

sagehane opened this issue Mar 16, 2021 · 2 comments · Fixed by #8667
Labels
bug Observed behavior contradicts documented or intended behavior os-linux
Milestone

Comments

@sagehane
Copy link
Contributor

sagehane commented Mar 16, 2021

Problem:

NixOS fails to detect system header locations on Unstable, accompanied by the following error:

warning: Unrecognized C flag from NIX_CFLAGS_COMPILE: -frandom-seed=<some 10 digit string>

Tested on:

$ nixos-version
21.05pre275822.916ee862e87 (Okapi)

How to reproduce:

  1. Prepare a Zig project that interfaces with C code, such as the the raylib example code on the main page.
  2. Use nix-shell to install the required dependencies (raylib in this case).
  3. Attempt to compile the file (zig build-exe cimport.zig -lc -lraylib as per the code comment).

The cause:

NixOS/nixpkgs#102251 added -frandom-seed as one of the flags of NIX_CFLAGS_COMPILE.

An example of what happens after running nix-shell -p raylib:

$ echo $NIX_CFLAGS_COMPILE
-frandom-seed=k1in0vqnyx -isystem /nix/store/ndbz36pb6rl0n2582n6598az61bsa7pl-raylib-3.5.0/include -isystem /nix/store/ndbz36pb6rl0n2582n6598az61bsa7pl-raylib-3.5.0/include

Since Zig doesn't expect this, it breaks out of the loop described here and doesn't properly add the header paths.

Possible Solutions:

Zig should adds support for passing -frandom-seed. Should be the ideal fix? Should just be about working on that loop mentioned above.

Also, idk if Zig is supposed to have feature parity with Clang, but frandom-seed seems to be mentioned here.


According to NixOS/nixpkgs#109033, NixOS currently lacks a way to disable this flag from being added.

As such, for people who just want to "ignore" the problem, they can add something like this to the shell.nix file:

  # This is a workaround that needs to be revised
  shellHook = ''
    NIX_CFLAGS_COMPILE="$(echo "$NIX_CFLAGS_COMPILE" | sed -e "s/-frandom-seed=[^-]*//")"
  '';
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior os-linux labels May 19, 2021
@andrewrk andrewrk added this to the 0.8.0 milestone May 19, 2021
@will
Copy link

will commented Jul 20, 2024

I'm having a similar issue while building a zig 0.13 project inside of the devshell provided by github:Cloudef/zig2nix on macos. zig build worked fine until I added exe.linkSystemLibrary("libgit2"); to the build.zig file. Then it started erroring with

error: warning: Unrecognized C flag from NIX_CFLAGS_COMPILE: -isysroot
warning: Unrecognized C flag from NIX_CFLAGS_COMPILE: /nix/store/7n8zp0cpbnf1rf7d3dc7gi0x43iadqn3-sdkroot-11.0/MacOSX11.0.sdk

and the value for that env var for me is

❯ echo $NIX_CFLAGS_COMPILE
 -frandom-seed=maaa31cchk -isysroot /nix/store/7n8zp0cpbnf1rf7d3dc7gi0x43iadqn3-sdkroot-11.0/MacOSX11.0.sdk

@nektro
Copy link
Contributor

nektro commented Jul 20, 2024

that's #18998. also make sure to check out Communitys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-linux
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants