lol

zig: fix darwin SDK lookup

+40 -15
+33 -14
pkgs/development/compilers/zig/generic.nix
··· 4 4 fetchFromGitHub, 5 5 cmake, 6 6 llvmPackages, 7 + xcbuild, 7 8 targetPackages, 8 9 libxml2, 9 10 zlib, ··· 30 31 31 32 patches = args.patches or [ ]; 32 33 33 - nativeBuildInputs = [ 34 - cmake 35 - (lib.getDev llvmPackages.llvm.dev) 36 - ]; 34 + nativeBuildInputs = 35 + [ 36 + cmake 37 + (lib.getDev llvmPackages.llvm.dev) 38 + ] 39 + ++ lib.optionals stdenv.hostPlatform.isDarwin [ 40 + # provides xcode-select, which is required for SDK detection 41 + xcbuild 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 - if lib.versionAtLeast finalAttrs.version "0.12" then 85 - '' 86 - substituteInPlace lib/std/zig/system.zig \ 87 - --replace-fail "/usr/bin/env" "${coreutils}/bin/env" 88 - '' 89 - else 90 - '' 91 - substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \ 92 - --replace-fail "/usr/bin/env" "${coreutils}/bin/env" 93 - ''; 90 + ( 91 + if lib.versionAtLeast finalAttrs.version "0.12" then 92 + '' 93 + substituteInPlace lib/std/zig/system.zig \ 94 + --replace-fail "/usr/bin/env" "${coreutils}/bin/env" 95 + '' 96 + else 97 + '' 98 + substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \ 99 + --replace-fail "/usr/bin/env" "${coreutils}/bin/env" 100 + '' 101 + ) 102 + # Zig tries to access xcrun and xcode-select at the absolute system path to query the macOS SDK 103 + # location, which does not work in the darwin sandbox. 104 + # Upstream issue: https://github.com/ziglang/zig/issues/22600 105 + # Note that while this fix is already merged upstream and will be included in 0.14+, 106 + # we can't fetchpatch the upstream commit as it won't cleanly apply on older versions, 107 + # so we substitute the paths instead. 108 + + lib.optionalString (stdenv.hostPlatform.isDarwin && lib.versionOlder finalAttrs.version "0.14") '' 109 + substituteInPlace lib/std/zig/system/darwin.zig \ 110 + --replace-fail /usr/bin/xcrun xcrun \ 111 + --replace-fail /usr/bin/xcode-select xcode-select 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 + stdenv, 6 + xcbuild, 5 7 }: 6 8 7 9 makeSetupHook { 8 10 name = "zig-hook"; 9 11 10 - propagatedBuildInputs = [ zig ]; 12 + propagatedBuildInputs = 13 + [ zig ] 14 + # while xcrun is already included in the darwin stdenv, Zig also needs 15 + # xcode-select (provided by xcbuild) for SDK detection 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