From 71c6ee929561c149c81f3511697b1d43c6fbb1d8 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Sun, 4 Feb 2024 13:07:09 -0500 Subject: [PATCH] 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. --- pkgs/stdenv/darwin/default.nix | 42 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 40f9059ac67f..1786fce83a1f 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -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 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 ]; @@ -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 - don’t 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; });