summary refs log tree commit diff
path: root/pkgs/os-specific/darwin/swift-corelibs
diff options
context:
space:
mode:
authorDan Peebles <pumpkin@me.com>2018-09-07 02:18:36 -0400
committerDan Peebles <pumpkin@me.com>2018-09-08 03:08:16 -0400
commitf223f417fa57719e79aaa59ef2d1cef3b6171129 (patch)
tree8e634f9afd63b26f0ff6b8bccbdc801eb3338eb2 /pkgs/os-specific/darwin/swift-corelibs
parent667e54bdb094dc34e3d4528fba0a0d484a8fd673 (diff)
downloadnixpkgs-f223f417fa57719e79aaa59ef2d1cef3b6171129.tar
nixpkgs-f223f417fa57719e79aaa59ef2d1cef3b6171129.tar.gz
nixpkgs-f223f417fa57719e79aaa59ef2d1cef3b6171129.tar.bz2
nixpkgs-f223f417fa57719e79aaa59ef2d1cef3b6171129.tar.lz
nixpkgs-f223f417fa57719e79aaa59ef2d1cef3b6171129.tar.xz
nixpkgs-f223f417fa57719e79aaa59ef2d1cef3b6171129.tar.zst
nixpkgs-f223f417fa57719e79aaa59ef2d1cef3b6171129.zip
swift-corelibs.corefoundation: update and modernize
This actually makes it useful to the Darwin stdenv, which I'll soon be
adjusting to use this library
Diffstat (limited to 'pkgs/os-specific/darwin/swift-corelibs')
-rw-r--r--pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix76
-rw-r--r--pkgs/os-specific/darwin/swift-corelibs/default.nix4
2 files changed, 63 insertions, 17 deletions
diff --git a/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix b/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix
index 969168fa54b..1dea55cccc9 100644
--- a/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix
+++ b/pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix
@@ -1,32 +1,78 @@
-{ stdenv, fetchFromGitHub, python, ninja, libxml2 }:
+{ stdenv, fetchFromGitHub, fetchurl, python, ninja, libxml2, objc4, ICU, curl }:
 
-stdenv.mkDerivation {
+let
+  # 10.12 adds a new sysdir.h that our version of CF in the main derivation depends on, but
+  # isn't available publicly, so instead we grab an older version of the same file that did
+  # not use sysdir.h, but provided the same functionality. Luckily it's simple :) hack hack
+  sysdir-free-system-directories = fetchurl {
+    url    = "https://raw.githubusercontent.com/apple/swift-corelibs-foundation/9a5d8420f7793e63a8d5ec1ede516c4ebec939f0/CoreFoundation/Base.subproj/CFSystemDirectories.c";
+    sha256 = "0krfyghj4f096arvvpf884ra5czqlmbrgf8yyc0b3avqmb613pcc";
+  };
+in stdenv.mkDerivation {
   name = "swift-corefoundation";
 
   src = fetchFromGitHub {
     owner  = "apple";
     repo   = "swift-corelibs-foundation";
-    rev    = "dce4233f583ec15190b240d6116396bf9641cd57";
-    sha256 = "0i2ldvy14x05k2vgl5z0g5l2i5llifdfbij5zwfdwb8jmmq215qr";
+    rev    = "85c640e7ce50e6ca61a134c72270e214bc63fdba"; # https://github.com/apple/swift-corelibs-foundation/pull/1686
+    sha256 = "0z2v278wy7jh0c92g1dszd8hj8naxari660sqx6yab5dwapd46qc";
   };
 
-  buildInputs = [ ninja python libxml2 ];
+  buildInputs = [ ninja python libxml2 objc4 ICU curl ];
+
+  sourceRoot = "source/CoreFoundation";
 
   patchPhase = ''
-    substituteInPlace CoreFoundation/build.py \
-      --replace '-I''${SYSROOT}/usr/include/libxml2' '-I${libxml2.dev}/include/libxml2' \
-  '';
+    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" '#' \
+      --replace "Base.subproj/SwiftRuntime/CoreFoundation.h" 'Base.subproj/CoreFoundation.h'
+
+    # 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'
+
+    # Why do we define __GNU__? Is that normal?
+    substituteInPlace Base.subproj/CFAsmMacros.h \
+      --replace '#if defined(__GNU__) ||' '#if 0 &&'
 
-  configurePhase = ":";
+    # 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'
 
-  buildPhase = ''
-    cd CoreFoundation
-    ../configure --sysroot unused
-    ninja
+    # 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
+  LDFLAGS = "-install_name ${placeholder "out"}/Frameworks/CoreFoundation.framework/CoreFoundation -current_version 1234.56.7 -compatibility_version 150.0.0 -init ___CFInitialize";
+  configurePhase = "../configure --sysroot unused";
+
+  enableParallelBuilding = true;
+  buildPhase = "ninja -j $NIX_BUILD_CORES";
+
+  # 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 = ''
-    mkdir -p $out/lib
-    cp ../Build/CoreFoundation/libCoreFoundation.a $out/lib
+    base="$out/Library/Frameworks/CoreFoundation.framework"
+    mkdir -p $base/Versions/A/{Headers,PrivateHeaders,Modules}
+
+    cp ./Build/CoreFoundation/libCoreFoundation.dylib $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
   '';
 }
diff --git a/pkgs/os-specific/darwin/swift-corelibs/default.nix b/pkgs/os-specific/darwin/swift-corelibs/default.nix
index dd652dc5627..0d96b8fd008 100644
--- a/pkgs/os-specific/darwin/swift-corelibs/default.nix
+++ b/pkgs/os-specific/darwin/swift-corelibs/default.nix
@@ -1,7 +1,7 @@
-{callPackage, darwin}:
+{ callPackage, darwin }:
 
 rec {
-  corefoundation = callPackage ./corefoundation.nix {};
+  corefoundation = callPackage ./corefoundation.nix { inherit (darwin) objc4 ICU; };
   libdispatch = callPackage ./libdispatch.nix {
    inherit (darwin) apple_sdk_sierra xnu;
   };