tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
zig: fix darwin SDK lookup
Niklas Korz
1 year ago
0ae3ecb3
62eb6058
+40
-15
2 changed files
expand all
collapse all
unified
split
pkgs
development
compilers
zig
generic.nix
hook.nix
+33
-14
pkgs/development/compilers/zig/generic.nix
···
4
4
fetchFromGitHub,
5
5
cmake,
6
6
llvmPackages,
7
7
+
xcbuild,
7
8
targetPackages,
8
9
libxml2,
9
10
zlib,
···
30
31
31
32
patches = args.patches or [ ];
32
33
33
33
-
nativeBuildInputs = [
34
34
-
cmake
35
35
-
(lib.getDev llvmPackages.llvm.dev)
36
36
-
];
34
34
+
nativeBuildInputs =
35
35
+
[
36
36
+
cmake
37
37
+
(lib.getDev llvmPackages.llvm.dev)
38
38
+
]
39
39
+
++ lib.optionals stdenv.hostPlatform.isDarwin [
40
40
+
# provides xcode-select, which is required for SDK detection
41
41
+
xcbuild
42
42
+
];
37
43
38
44
buildInputs =
39
45
[
···
81
87
# Zig's build looks at /usr/bin/env to find dynamic linking info. This doesn't
82
88
# work in Nix's sandbox. Use env from our coreutils instead.
83
89
postPatch =
84
84
-
if lib.versionAtLeast finalAttrs.version "0.12" then
85
85
-
''
86
86
-
substituteInPlace lib/std/zig/system.zig \
87
87
-
--replace-fail "/usr/bin/env" "${coreutils}/bin/env"
88
88
-
''
89
89
-
else
90
90
-
''
91
91
-
substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \
92
92
-
--replace-fail "/usr/bin/env" "${coreutils}/bin/env"
93
93
-
'';
90
90
+
(
91
91
+
if lib.versionAtLeast finalAttrs.version "0.12" then
92
92
+
''
93
93
+
substituteInPlace lib/std/zig/system.zig \
94
94
+
--replace-fail "/usr/bin/env" "${coreutils}/bin/env"
95
95
+
''
96
96
+
else
97
97
+
''
98
98
+
substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \
99
99
+
--replace-fail "/usr/bin/env" "${coreutils}/bin/env"
100
100
+
''
101
101
+
)
102
102
+
# Zig tries to access xcrun and xcode-select at the absolute system path to query the macOS SDK
103
103
+
# location, which does not work in the darwin sandbox.
104
104
+
# Upstream issue: https://github.com/ziglang/zig/issues/22600
105
105
+
# Note that while this fix is already merged upstream and will be included in 0.14+,
106
106
+
# we can't fetchpatch the upstream commit as it won't cleanly apply on older versions,
107
107
+
# so we substitute the paths instead.
108
108
+
+ lib.optionalString (stdenv.hostPlatform.isDarwin && lib.versionOlder finalAttrs.version "0.14") ''
109
109
+
substituteInPlace lib/std/zig/system/darwin.zig \
110
110
+
--replace-fail /usr/bin/xcrun xcrun \
111
111
+
--replace-fail /usr/bin/xcode-select xcode-select
112
112
+
'';
94
113
95
114
postBuild =
96
115
if lib.versionAtLeast finalAttrs.version "0.13" then
+7
-1
pkgs/development/compilers/zig/hook.nix
···
2
2
lib,
3
3
makeSetupHook,
4
4
zig,
5
5
+
stdenv,
6
6
+
xcbuild,
5
7
}:
6
8
7
9
makeSetupHook {
8
10
name = "zig-hook";
9
11
10
10
-
propagatedBuildInputs = [ zig ];
12
12
+
propagatedBuildInputs =
13
13
+
[ zig ]
14
14
+
# while xcrun is already included in the darwin stdenv, Zig also needs
15
15
+
# xcode-select (provided by xcbuild) for SDK detection
16
16
+
++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild ];
11
17
12
18
substitutions = {
13
19
# This zig_default_flags below is meant to avoid CPU feature impurity in