diff options
Diffstat (limited to 'pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix')
-rw-r--r-- | pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix | 104 |
1 files changed, 43 insertions, 61 deletions
diff --git a/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix b/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix index 1e7aeb3689ea9..d77976773c66d 100644 --- a/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix +++ b/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, fetchFromGitHub, fetchurl, makeSetupHook, ninja, python3, curl, libxml2, objc4, ICU }: +{ lib, stdenv, fetchFromGitHub, fetchurl, makeSetupHook, cmake, ninja, pkg-config, launchd, libdispatch, python3, libxml2, objc4, icu }: let # 10.12 adds a new sysdir.h that our version of CF in the main derivation depends on, but @@ -21,29 +21,39 @@ stdenv.mkDerivation { sha256 = "17kpql0f27xxz4jjw84vpas5f5sn4vdqwv10g151rc3rswbwln1z"; }; - nativeBuildInputs = [ ninja python3 ]; - buildInputs = [ curl libxml2 objc4 ICU ]; - - patches = [ ./0001-Add-missing-TARGET_OS_-defines.patch ]; + nativeBuildInputs = [ cmake ninja pkg-config python3 ]; + buildInputs = [ (lib.getDev launchd) libdispatch libxml2 objc4 icu ]; + + patches = [ + ./0001-Add-missing-TARGET_OS_-defines.patch + # CFMessagePort.h uses `bootstrap_check_in` without declaring it, which is defined in the launchd headers. + ./0002-Add-missing-launchd-header.patch + # CFURLComponents fails to build with clang 16 due to an invalid pointer conversion. This is fixed upstream. + ./0003-Fix-incompatible-pointer-conversion.patch + # Fix `CMakeLists.txt` to allow it to be used instead of `build.py` to build on Darwin. + ./0004-Fix-Darwin-cmake-build.patch + # Install CF framework in `$out/Library/Frameworks` instead of `$out/System/Frameworks`. + ./0005-Fix-framework-installation-path.patch + # Build a framework that matches the contents of the system CoreFoundation. This patch adds + # versioning and drops the prefix and suffix, so the dynamic library is named `CoreFoundation` + # instead of `libCoreFoundation.dylib`. + ./0006-System-CF-framework-compatibility.patch + # Link against the nixpkgs ICU instead of using Apple’s vendored version. + ./0007-Use-nixpkgs-icu.patch + # Don’t link against libcurl. This breaks a cycle between CF and curl, which depends on CF and + # uses the SystemConfiguration framework to support NAT64. + # This is safe because the symbols provided in CFURLSessionInterface are not provided by the + # system CoreFoundation. They are meant to be used by the implementation of `NSURLSession` in + # swift-corelibs-foundation, which is not built because it is not fully compatible with the + # system Foundation used on Darwin. + ./0008-Dont-link-libcurl.patch + ]; postPatch = '' cd CoreFoundation cp ${sysdir-free-system-directories} Base.subproj/CFSystemDirectories.c - # In order, since I can't comment individual lines: - # 1. Disable dispatch support for now - # 2. For the linker too - # 3. Use the legit CoreFoundation.h, not the one telling you not to use it because of Swift - substituteInPlace build.py \ - --replace "cf.CFLAGS += '-DDEPLOYMENT" '#' \ - --replace "cf.LDFLAGS += '-ldispatch" '#' - - # Fix sandbox impurities. - substituteInPlace ../lib/script.py \ - --replace '/bin/cp' cp - patchShebangs --build ../configure - # Includes xpc for some initialization routine that they don't define anyway, so no harm here substituteInPlace PlugIn.subproj/CFBundlePriv.h \ --replace '#if (TARGET_OS_MAC' '#if (0' @@ -55,55 +65,27 @@ stdenv.mkDerivation { # The MIN macro doesn't seem to be defined sensibly for us. Not sure if our stdenv or their bug substituteInPlace Base.subproj/CoreFoundation_Prefix.h \ --replace '#if DEPLOYMENT_TARGET_WINDOWS || DEPLOYMENT_TARGET_LINUX' '#if 1' - - # Somehow our ICU doesn't have this, probably because it's too old (we'll update it soon when we update the rest of the SDK) - substituteInPlace Locale.subproj/CFLocale.c \ - --replace '#if U_ICU_VERSION_MAJOR_NUM' '#if 0 //' ''; - BUILD_DIR = "./Build"; - CFLAGS = "-DINCLUDE_OBJC -I${libxml2.dev}/include/libxml2"; # They seem to assume we include objc in some places and not in others, make a PR; also not sure why but libxml2 include path isn't getting picked up from buildInputs + env.NIX_CFLAGS_COMPILE = toString [ + # Silence warnings regarding other targets + "-Wno-error=undef-prefix" + # Avoid redefinitions when including objc headers + "-DINCLUDE_OBJC=1" + ]; - # I'm guessing at the version here. https://github.com/apple/swift-corelibs-foundation/commit/df3ec55fe6c162d590a7653d89ad669c2b9716b1 imported "high sierra" - # and this version is a version from there. No idea how accurate it is. - LDFLAGS = "-current_version 1454.90.0 -compatibility_version 150.0.0 -init ___CFInitialize"; - - configurePhase = '' - ../configure release --sysroot UNUSED - ''; + cmakeFlags = [ + "-DBUILD_SHARED_LIBS=ON" + "-DCF_ENABLE_LIBDISPATCH=OFF" + ]; enableParallelBuilding = true; - buildPhase = '' - runHook preBuild + postInstall = '' + install_name_tool -id '@rpath/CoreFoundation.framework/Versions/A/CoreFoundation' \ + "$out/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation" - ninja -j $NIX_BUILD_CORES - - runHook postBuild + mkdir -p "$out/nix-support" + substituteAll ${./pure-corefoundation-hook.sh} "$out/nix-support/setup-hook" ''; - - # TODO: their build system sorta kinda can do this, but it doesn't seem to work right now - # Also, this includes a bunch of private headers in the framework, which is not what we want - installPhase = '' - base="$out/Library/Frameworks/CoreFoundation.framework" - mkdir -p $base/Versions/A/{Headers,PrivateHeaders,Modules} - - cp ./Build/CoreFoundation/libCoreFoundation.dylib $base/Versions/A/CoreFoundation - - # Note that this could easily live in the ldflags above as `-install_name @rpath/...` but - # https://github.com/NixOS/nixpkgs/issues/46434 thwarts that, so for now I'm hacking it up - # after the fact. - install_name_tool -id '@rpath/CoreFoundation.framework/Versions/A/CoreFoundation' $base/Versions/A/CoreFoundation - - cp ./Build/CoreFoundation/usr/include/CoreFoundation/*.h $base/Versions/A/Headers - cp ./Build/CoreFoundation/usr/include/CoreFoundation/module.modulemap $base/Versions/A/Modules - - ln -s A $base/Versions/Current - - for i in CoreFoundation Headers Modules; do - ln -s Versions/Current/$i $base/$i - done - ''; - - darwinEnvHook = makeSetupHook { name = "darwin-env-hook"; } ./pure-corefoundation-hook.sh; } |