nixpkgs/pkgs/development/compilers/zig/hook.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.5 KiB
Nix
Raw Normal View History

{ lib
, makeSetupHook
, zig
}:
makeSetupHook {
name = "zig-hook";
propagatedBuildInputs = [ zig ];
2023-08-06 02:41:13 +00:00
substitutions = {
# This zig_default_flags below is meant to avoid CPU feature impurity in
# Nixpkgs. However, this flagset is "unstable": it is specifically meant to
# be controlled by the upstream development team - being up to that team
# exposing or not that flags to the outside (especially the package manager
# teams).
# Because of this hurdle, @andrewrk from Zig Software Foundation proposed
# some solutions for this issue. Hopefully they will be implemented in
# future releases of Zig. When this happens, this flagset should be
# revisited accordingly.
# Below are some useful links describing the discovery process of this 'bug'
# in Nixpkgs:
# https://github.com/NixOS/nixpkgs/issues/169461
# https://github.com/NixOS/nixpkgs/issues/185644
# https://github.com/NixOS/nixpkgs/pull/197046
# https://github.com/NixOS/nixpkgs/pull/241741#issuecomment-1624227485
# https://github.com/ziglang/zig/issues/14281#issuecomment-1624220653
2023-08-06 02:41:13 +00:00
zig_default_flags =
2023-08-21 11:38:30 +00:00
let
releaseType =
if lib.versionAtLeast zig.version "0.11" then
"-Doptimize=ReleaseSafe"
else
"-Drelease-safe=true";
2023-08-21 11:38:30 +00:00
in
[ "-Dcpu=baseline" releaseType ];
2023-08-06 02:41:13 +00:00
};
passthru = { inherit zig; };
meta = {
description = "A setup hook for using the Zig compiler in Nixpkgs";
inherit (zig.meta) maintainers platforms broken;
};
} ./setup-hook.sh