Merge pull request #263598 from reckenrode/curl-propagation-fix

curl: fix build failures due to needing to propagate frameworks
This commit is contained in:
toonn 2023-10-27 18:25:39 +02:00 committed by GitHub
commit f65ccb3163
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 124 additions and 15 deletions

View file

@ -53,9 +53,9 @@ stdenv.mkDerivation (finalAttrs: {
libglvnd # libGL.so
webkitgtk # webkit2gtk-4.0
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk_11_0.frameworks.Cocoa
darwin.apple_sdk_11_0.frameworks.MetalKit
darwin.apple_sdk_11_0.frameworks.WebKit
darwin.apple_sdk.frameworks.Cocoa
darwin.apple_sdk.frameworks.MetalKit
darwin.apple_sdk.frameworks.WebKit
];
meta = with lib; {

View file

@ -47,9 +47,8 @@ buildPecl rec {
curl
pcre2
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk_11_0.frameworks.CoreFoundation
darwin.apple_sdk_11_0.frameworks.Security
darwin.apple_sdk_11_0.Libsystem
darwin.apple_sdk.frameworks.CoreFoundation
darwin.apple_sdk.frameworks.Security
libiconv
];

View file

@ -34,7 +34,7 @@ rustPlatform.buildRustPackage rec {
openssl
zlib
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk_11_0.frameworks.Security
darwin.apple_sdk.frameworks.Security
];
cargoBuildFlags = [ "-p=cargo-codspeed" ];

View file

@ -246,4 +246,103 @@ rec {
env = (args.env or {}) // { NIX_CFLAGS_COMPILE = toString (args.env.NIX_CFLAGS_COMPILE or "") + " ${toString compilerFlags}"; };
});
});
# Overriding the SDK changes the Darwin SDK used to build the package, which:
# * Ensures that the compiler and bintools have the correct Libsystem version; and
# * Replaces any SDK references with those in the SDK corresponding to the requested SDK version.
#
# `sdkVersion` can be any of the following:
# * A version string indicating the requested SDK version; or
# * An attrset consisting of either or both of the following fields: darwinSdkVersion and darwinMinVersion.
overrideSDK = stdenv: sdkVersion:
let
inherit (
{ inherit (stdenv.hostPlatform) darwinMinVersion darwinSdkVersion; }
// (if lib.isAttrs sdkVersion then sdkVersion else { darwinSdkVersion = sdkVersion; })
) darwinMinVersion darwinSdkVersion;
sdk = pkgs.darwin."apple_sdk_${lib.replaceStrings [ "." ] [ "_" ] darwinSdkVersion}";
isSDKFramework = pkg: lib.hasPrefix "apple-framework-" (lib.getName pkg);
replacePropagatedFrameworks = pkg:
let
propagatedFrameworks = lib.filter isSDKFramework pkg.propagatedBuildInputs;
env = {
inherit (pkg) outputs;
# Map the old frameworks to new and the packages outputs to their original outPaths.
# The mappings are rendered into tab-separated files to be read back with `read`.
frameworks = lib.concatMapStrings (pkg: "${pkg}\t${mapPackageToSDK pkg}\n") propagatedFrameworks;
pkgOutputs = lib.concatMapStrings (output: "${output}\t${(lib.getOutput output pkg).outPath}\n") pkg.outputs;
passAsFile = [ "frameworks" "pkgOutputs" ];
};
in
if lib.length propagatedFrameworks > 0
then pkgs.runCommand pkg.name env ''
# Iterate over the outputs in the package being replaced to make sure the proxy is
# a fully functional replacement. This is like `symlinkJoin` except for outputs and
# the contents of `nix-support`, which will be customized for the requested SDK.
while IFS=$'\t\n' read -r outputName pkgOutputPath; do
mkdir -p "''${!outputName}"
for targetPath in "$pkgOutputPath"/*; do
targetName=$(basename "$targetPath")
# `nix-support` is special-cased because any propagated inputs need their SDK
# frameworks replaced with those from the requested SDK.
if [ "$targetName" == "nix-support" ]; then
mkdir "''${!outputName}/nix-support"
for file in "$targetPath"/*; do
fileName=$(basename "$file")
if [ "$fileName" == "propagated-build-inputs" ]; then
cp "$file" "''${!outputName}/nix-support/$fileName"
while IFS=$'\t\n' read -r oldFramework newFramework; do
substituteInPlace "''${!outputName}/nix-support/$fileName" \
--replace "$oldFramework" "$newFramework"
done < "$frameworksPath"
fi
done
else
ln -s "$targetPath" "''${!outputName}/$targetName"
fi
done
done < "$pkgOutputsPath"
''
else pkg;
# Remap a framework from one SDK version to another.
mapPackageToSDK = pkg:
let
name = lib.getName pkg;
framework = lib.removePrefix "apple-framework-" name;
in
if isSDKFramework pkg
then sdk.frameworks."${framework}"
else replacePropagatedFrameworks pkg;
mapInputsToSDK = inputs: args:
lib.genAttrs inputs (input: map mapPackageToSDK (args."${input}" or [ ]));
mkCC = cc: cc.override {
bintools = cc.bintools.override { libc = sdk.Libsystem; };
libc = sdk.Libsystem;
};
in
# TODO: make this work across all input types and not just propagatedBuildInputs
stdenv.override (old: {
buildPlatform = old.buildPlatform // { inherit darwinMinVersion darwinSdkVersion; };
hostPlatform = old.hostPlatform // { inherit darwinMinVersion darwinSdkVersion; };
targetPlatform = old.targetPlatform // { inherit darwinMinVersion darwinSdkVersion; };
allowedRequisites = null;
cc = mkCC old.cc;
extraBuildInputs = [sdk.frameworks.CoreFoundation ];
mkDerivationFromStdenv = extendMkDerivationArgs old (mapInputsToSDK [
"buildInputs"
]);
});
}

View file

@ -64,11 +64,6 @@ stdenv.mkDerivation (finalAttrs: {
strictDeps = true;
buildInputs = lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
CoreFoundation
CoreServices
SystemConfiguration
]);
nativeBuildInputs = [ pkg-config perl ];
# Zlib and OpenSSL must be propagated because `libcurl.la' contains
@ -91,7 +86,12 @@ stdenv.mkDerivation (finalAttrs: {
optional wolfsslSupport wolfssl ++
optional rustlsSupport rustls-ffi ++
optional zlibSupport zlib ++
optional zstdSupport zstd;
optional zstdSupport zstd ++
optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
CoreFoundation
CoreServices
SystemConfiguration
]);
# for the second line see https://curl.haxx.se/mail/tracker-2014-03/0087.html
preConfigure = ''

View file

@ -5755,7 +5755,9 @@ with pkgs;
joystickwake = callPackage ../tools/games/joystickwake { };
juce = darwin.apple_sdk_11_0.callPackage ../development/misc/juce { };
juce = callPackage ../development/misc/juce {
stdenv = if stdenv.isDarwin then overrideSDK stdenv "11.0" else stdenv;
};
jumppad = callPackage ../tools/virtualization/jumppad { };
@ -17031,7 +17033,12 @@ with pkgs;
cargo-clone = callPackage ../development/tools/rust/cargo-clone {
inherit (darwin.apple_sdk.frameworks) Security SystemConfiguration;
};
cargo-codspeed = callPackage ../development/tools/rust/cargo-codspeed { };
cargo-codspeed = callPackage ../development/tools/rust/cargo-codspeed {
rustPlatform = makeRustPlatform {
stdenv = if stdenv.isDarwin then overrideSDK stdenv "11.0" else stdenv;
inherit rustc cargo;
};
};
cargo-component = callPackage ../development/tools/rust/cargo-component { };
cargo-cranky = callPackage ../development/tools/rust/cargo-cranky { };
cargo-criterion = callPackage ../development/tools/rust/cargo-criterion { };

View file

@ -30,6 +30,7 @@
, openldap
, openssl_1_1
, openssl
, overrideSDK
, pam
, pcre2
, postgresql
@ -239,6 +240,9 @@ lib.makeScope pkgs.newScope (self: with self; {
couchbase = callPackage ../development/php-packages/couchbase { };
datadog_trace = callPackage ../development/php-packages/datadog_trace {
buildPecl = buildPecl.override {
stdenv = if stdenv.isDarwin then overrideSDK stdenv "11.0" else stdenv;
};
inherit (pkgs) darwin;
};