1{ lib
2, makeSetupHook
3, zig
4}:
5
6makeSetupHook {
7 name = "zig-hook";
8
9 propagatedBuildInputs = [ zig ];
10
11 substitutions = {
12 # This zig_default_flags below is meant to avoid CPU feature impurity in
13 # Nixpkgs. However, this flagset is "unstable": it is specifically meant to
14 # be controlled by the upstream development team - being up to that team
15 # exposing or not that flags to the outside (especially the package manager
16 # teams).
17
18 # Because of this hurdle, @andrewrk from Zig Software Foundation proposed
19 # some solutions for this issue. Hopefully they will be implemented in
20 # future releases of Zig. When this happens, this flagset should be
21 # revisited accordingly.
22
23 # Below are some useful links describing the discovery process of this 'bug'
24 # in Nixpkgs:
25
26 # https://github.com/NixOS/nixpkgs/issues/169461
27 # https://github.com/NixOS/nixpkgs/issues/185644
28 # https://github.com/NixOS/nixpkgs/pull/197046
29 # https://github.com/NixOS/nixpkgs/pull/241741#issuecomment-1624227485
30 # https://github.com/ziglang/zig/issues/14281#issuecomment-1624220653
31
32 zig_default_flags =
33 let
34 releaseType =
35 if lib.versionAtLeast zig.version "0.11" then
36 "-Doptimize=ReleaseSafe"
37 else
38 "-Drelease-safe=true";
39 in
40 [ "-Dcpu=baseline" releaseType ];
41 };
42
43 passthru = { inherit zig; };
44
45 meta = {
46 description = "A setup hook for using the Zig compiler in Nixpkgs";
47 inherit (zig.meta) maintainers platforms broken;
48 };
49} ./setup-hook.sh