Skip to content

Commit

Permalink
darwin.stdenv: add sdkRoot to extraNativeBuildInputs
Browse files Browse the repository at this point in the history
Setting the SDK root by default allows `overrideSDK` to correctly set
the SDK version when using a different SDK. It also allows the correct
SDK version to be set when using an older deployment target. Not setting
the correct SDK version can result in unexpected behavior at runtime.

Examples:

* Automatic dark mode switching requires linking against an SDK version
  of 10.14 or newer. With the current behavior, the only way to do this
  is by using a 10.14+ deployment target even when the application
  supports older platforms when build with a newer SDK.
* MetalD3D checks that the system version is at least 14.0. The API it
  uses returns a compatibility version when the the SDK is older than
  11.0, which causes it to display an error and terminate the
  application even when even when its requirements are all met.
  • Loading branch information
reckenrode committed Mar 29, 2024
1 parent f61e189 commit 71c6ee9
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ let
hostPlatform = localSystem;
targetPlatform = localSystem;

inherit config extraNativeBuildInputs;
inherit config;

extraBuildInputs = [ prevStage.darwin.CF ];
extraNativeBuildInputs = extraNativeBuildInputs
++ [ prevStage.darwin.apple_sdk.sdkRoot ];

preHook = lib.optionalString (!isBuiltByNixpkgsCompiler bash) ''
# Don't patch #!/interpreter because it leads to retained
Expand Down Expand Up @@ -196,6 +198,7 @@ in
cpio = null;

darwin = {
apple_sdk.sdkRoot = null;
binutils = null;
binutils-unwrapped = null;
cctools = null;
Expand Down Expand Up @@ -435,6 +438,10 @@ in
});

darwin = super.darwin.overrideScope (selfDarwin: superDarwin: {
apple_sdk = superDarwin.apple_sdk // {
inherit (prevStage.darwin.apple_sdk) sdkRoot;
};

# Use this stage’s CF to build configd. It’s required but can’t be included in the stdenv.
configd = superDarwin.configd.overrideAttrs (old: {
buildInputs = old.buildInputs or [ ] ++ [ self.darwin.CF ];
Expand Down Expand Up @@ -558,9 +565,13 @@ in

darwin = super.darwin.overrideScope (_: superDarwin: {
inherit (prevStage.darwin)
CF Libsystem binutils-unwrapped cctools cctools-port configd darwin-stubs dyld
CF sdkRoot Libsystem binutils-unwrapped cctools cctools-port configd darwin-stubs dyld
launchd libclosure libdispatch libobjc locale objc4 postLinkSignHook
print-reexports rewrite-tbd signingUtils sigtool;

apple_sdk = superDarwin.apple_sdk // {
inherit (prevStage.darwin.apple_sdk) sdkRoot;
};
});

llvmPackages = super.llvmPackages // (
Expand Down Expand Up @@ -638,6 +649,10 @@ in
CF Libsystem configd darwin-stubs dyld launchd libclosure libdispatch libobjc
locale objc4 postLinkSignHook print-reexports rewrite-tbd signingUtils sigtool;

apple_sdk = superDarwin.apple_sdk // {
inherit (prevStage.darwin.apple_sdk) sdkRoot;
};

# Avoid building unnecessary Python dependencies due to building LLVM manpages.
cctools-llvm = superDarwin.cctools-llvm.override { enableManpages = false; };
});
Expand Down Expand Up @@ -735,6 +750,10 @@ in
inherit (prevStage.darwin)
CF binutils-unwrapped cctools configd darwin-stubs launchd libobjc libtapi locale
objc4 print-reexports rewrite-tbd signingUtils sigtool;

apple_sdk = superDarwin.apple_sdk // {
inherit (prevStage.darwin.apple_sdk) sdkRoot;
};
});

llvmPackages = super.llvmPackages // (
Expand Down Expand Up @@ -773,7 +792,7 @@ in
'';
})

# This stage rebuilds CF and compiler-rt.
# This stage rebuilds CF, compiler-rt, and the sdkRoot derivation.
#
# CF requires:
# - aarch64-darwin: libobjc (due to being apple_sdk.frameworks.CoreFoundation instead of swift-corefoundation)
Expand Down Expand Up @@ -958,6 +977,10 @@ in
CF Libsystem binutils binutils-unwrapped cctools cctools-llvm cctools-port configd
darwin-stubs dyld launchd libclosure libdispatch libobjc libtapi locale objc4
postLinkSignHook print-reexports rewrite-tbd signingUtils sigtool;

apple_sdk = superDarwin.apple_sdk // {
inherit (prevStage.darwin.apple_sdk) sdkRoot;
};
});

llvmPackages = super.llvmPackages // (
Expand Down Expand Up @@ -1036,6 +1059,10 @@ in
# CF dependencies - don’t rebuild them.
libobjc objc4;

apple_sdk = superDarwin.apple_sdk // {
inherit (prevStage.darwin.apple_sdk) sdkRoot;
};

signingUtils = superDarwin.signingUtils.override {
inherit (selfDarwin) sigtool;
};
Expand Down Expand Up @@ -1206,7 +1233,7 @@ in

extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [
prevStage.updateAutotoolsGnuConfigScriptsHook
];
] ++ [ prevStage.darwin.apple_sdk.sdkRoot ];

extraBuildInputs = [ prevStage.darwin.CF ];

Expand Down Expand Up @@ -1293,6 +1320,7 @@ in
dyld
libtapi
locale
apple_sdk.sdkRoot
]
++ lib.optional useAppleSDKLibs [ objc4 ]
++ lib.optionals doSign [ postLinkSignHook sigtool signingUtils ]);
Expand All @@ -1307,9 +1335,13 @@ in
libunistring libxml2 libyaml ncurses nghttp2 openbsm openpam openssl patch pbzx
pcre python3Minimal xar xz zlib zstd;

darwin = super.darwin.overrideScope (_: _: {
darwin = super.darwin.overrideScope (_: superDarwin: {
inherit (prevStage.darwin)
CF ICU Libsystem darwin-stubs dyld locale libobjc libtapi rewrite-tbd xnu;

apple_sdk = superDarwin.apple_sdk // {
inherit (prevStage.darwin.apple_sdk) sdkRoot;
};
} // lib.optionalAttrs (super.stdenv.targetPlatform == localSystem) {
inherit (prevStage.darwin) binutils binutils-unwrapped cctools-llvm cctools-port;
});
Expand Down

0 comments on commit 71c6ee9

Please sign in to comment.