-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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: builds for -march=native by default #185665
Comments
create a issue upstream? EDIT: someone created one 2 days ago ziglang/zig#12458 |
upstream basically says "not an issue", so we should probably just fix this in nixpkgs |
Where is this flag implemented? |
Ideally, I think |
grepping for
all of those look like they're doing the right thing, but
To fix both these shortcomings, we should probably create a zig setupHook, so including The real-world issue this would fix is #185644 and it would ideally prevent any such issues from occurring again in the future. |
Indeed, this would help to unbreak ncdu for instance ! |
I just wanted to make sure if I tried building
I'm not sure if I even did the cross-compilation correctly though, based it on the expression from https://nixos.wiki/wiki/Cross_Compiling and did something like: with import <nixpkgs> {
crossSystem = {
config = "aarch64-unknown-linux-gnu";
};
};
mkShell {
buildInputs = [ ncdu ncdu_1 ];
} |
Also adds `-Dcpu=baseline` to fix: NixOS#185665
Proposed fix: #214440 |
Hi, upstream here. I'd like to provide some perspective from this side of things, and then we can meet in the middle, for the benefit of our mutual users. Zig packages do not necessarily have an optimization mode or a target. Consider, for example, a package which uses the zig build system, but only uses it compiles a tool for the host and then run it at build time to produce documentation, and the only thing installed to $prefix is some HTML files. In such case there will be no optimization flags or target flags exposed. On the other hand, most zig projects, at least today, do install target-specific build artifacts, and that is why the zig build system has a way to ask for optimization mode and target with a standard set of flags. However, nix cannot assume the existence of Regarding determinism - Zig guarantees deterministic builds when the optimization mode is a release build rather than a debug build. When building a Zig package, nix must always choose a release mode, rather than debug mode. It would be unthinkable to ship debug builds to users who install applications via nix. Zig packages generally will choose between one or two options when exposing optimization options:
I'd like to push back on the shortcomings mentioned earlier in this thread:
ncdu at least now has adjusted its makefile to address this problem, and is already fixed in the nix package. This problem is solved. I argue that its makefile should have been patched rather than patching the zig compiler itself, when the problem existed.
I fundamentally disagree with this being an issue. Each package might be differently configured, and that is why there is a nix file for each package, so that each package's special needs can be addressed. I think that it is desirable for there to be this layer of dialogue between nix and a zig package's build script, which could advertise a rich array of options, of which target CPU and optimization mode are only scratching the surface.
I think a better way would be accessing the desired target architecture, operating system along with minimum/maximum OS version, and ABI, along with potentially the glibc version, from nix, and then specifying these via the standard I mentioned this over in #214440, but I'll say it again here: Consider that, while it is crucial for zig to use the baseline CPU when zig is being used by nix to build nix packages for binary distributions, another important use case is nix users directly using the zig binary provided by nix to develop their own upstream projects. Please, let us not have a repeat of #18995. BTW I have been a happy NixOS user for many years now. I'm available to discuss this further here as well as |
This is not my experience with the Zig toolchain:
|
Pretty sure this means that release builds are deterministic for the given target. It does not mean that release builds are portable by default. |
26b9a2f changes Zig 0.10 to build the compiler (notably *not* its outputs, at least not by default) with its baseline CPU target, but we should ideally do it for both versions to increase reproducibility, as well as increase the number of users who are able to use Hydra-provided Zig binaries. This also adds a comment above the flag in 0.10, to explain why we're adding the flag, as we do with the RPATH one. See NixOS#214356 and NixOS#185665 for further context.
26b9a2f changes Zig 0.10 to build the compiler (notably *not* its outputs, at least not by default) with its baseline CPU target, but we should ideally do it for both versions to increase reproducibility, as well as increase the number of users who are able to use Hydra-provided Zig binaries. This also adds a comment above the flag in 0.10, to explain why we're adding the flag, as we do with the RPATH one. See NixOS#214356 and NixOS#185665 for further context.
Can this be closed now since the introduction of |
Well, given that it was solved even before this - the hook merely made the fixup more portable - I believe it can be finally closed as solved. |
Describe the bug
zig
as currently used in nixpkgs builds for the current machine's native CPU architecture instead of baseline x86-64, resulting in SIGILLs on older machines.Steps To Reproduce
nix build nixpkgs#ncdu --rebuild
on a machine with AVX512Expected behavior
The resulting binaries are not built with extended instructions.
Additional context
Do we really need to wrap zig for this?
Notify maintainers
@aiotter @andrewrk @AndersonTorres
The text was updated successfully, but these errors were encountered: