Skip to content

Commit

Permalink
zig: fix darwin SDK lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
niklaskorz committed Jan 25, 2025
1 parent b16f240 commit d3a64dc
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions pkgs/development/compilers/zig/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
, zlib
, coreutils
, callPackage
, xcbuild
, ...
}:

Expand Down Expand Up @@ -50,15 +51,25 @@ stdenv.mkDerivation (finalAttrs: {
export ZIG_GLOBAL_CACHE_DIR="$TMPDIR/zig-cache";
'';

# Zig's build looks at /usr/bin/env to find dynamic linking info. This doesn't
# work in Nix's sandbox. Use env from our coreutils instead.
postPatch = if lib.versionAtLeast args.version "0.12" then ''
substituteInPlace lib/std/zig/system.zig \
--replace "/usr/bin/env" "${coreutils}/bin/env"
'' else ''
substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \
--replace-fail "/usr/bin/env" "${coreutils}/bin/env"
'';
postPatch =
# Zig's build looks at /usr/bin/env to find dynamic linking info. This doesn't
# work in Nix's sandbox. Use env from our coreutils instead.
(if lib.versionAtLeast args.version "0.12" then ''
substituteInPlace lib/std/zig/system.zig \
--replace "/usr/bin/env" "${coreutils}/bin/env"
'' else ''
substituteInPlace lib/std/zig/system/NativeTargetInfo.zig \
--replace-fail "/usr/bin/env" "${coreutils}/bin/env"
'')
# Zig tries to access xcrun at the absolute system path to query the macOS SDK
# location, which does not work in the darwin sandbox.
# We can just provide "xcrun" instead as it is part of the darwin stdenv.
# Upstream issue: https://github.com/ziglang/zig/issues/22600
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
substituteInPlace lib/std/zig/system/darwin.zig \
--replace-fail /usr/bin/xcrun xcrun \
--replace-fail /usr/bin/xcode-select '${lib.getExe' xcbuild "xcode-select"}'
'';

doInstallCheck = true;
installCheckPhase = ''
Expand Down

0 comments on commit d3a64dc

Please sign in to comment.