darwin.stdenv: add sdkRoot to extraNativeBuildInputs

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.
This commit is contained in:
Randy Eckenrode 2024-02-04 13:07:09 -05:00
parent f61e189ad3
commit 71c6ee9295
No known key found for this signature in database
GPG Key ID: 64C1CD4EC2A600D9

View File

@ -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
@ -196,6 +198,7 @@ in
cpio = null;
darwin = {
apple_sdk.sdkRoot = null;
binutils = null;
binutils-unwrapped = null;
cctools = null;
@ -435,6 +438,10 @@ in
});
darwin = super.darwin.overrideScope (selfDarwin: superDarwin: {
apple_sdk = superDarwin.apple_sdk // {
inherit (prevStage.darwin.apple_sdk) sdkRoot;
};
# Use this stages CF to build configd. Its required but cant be included in the stdenv.
configd = superDarwin.configd.overrideAttrs (old: {
buildInputs = old.buildInputs or [ ] ++ [ self.darwin.CF ];
@ -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 // (
@ -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; };
});
@ -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 // (
@ -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)
@ -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 // (
@ -1036,6 +1059,10 @@ in
# CF dependencies - dont rebuild them.
libobjc objc4;
apple_sdk = superDarwin.apple_sdk // {
inherit (prevStage.darwin.apple_sdk) sdkRoot;
};
signingUtils = superDarwin.signingUtils.override {
inherit (selfDarwin) sigtool;
};
@ -1206,7 +1233,7 @@ in
extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [
prevStage.updateAutotoolsGnuConfigScriptsHook
];
] ++ [ prevStage.darwin.apple_sdk.sdkRoot ];
extraBuildInputs = [ prevStage.darwin.CF ];
@ -1293,6 +1320,7 @@ in
dyld
libtapi
locale
apple_sdk.sdkRoot
]
++ lib.optional useAppleSDKLibs [ objc4 ]
++ lib.optionals doSign [ postLinkSignHook sigtool signingUtils ]);
@ -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;
});