summary refs log tree commit diff
path: root/pkgs/os-specific/darwin/cf-private
diff options
context:
space:
mode:
authorDan Peebles <pumpkin@me.com>2018-09-09 13:36:05 -0400
committerDan Peebles <pumpkin@me.com>2018-09-15 16:05:46 -0400
commit4efd4053ed183d63f09615cf30ea822e708a4fbe (patch)
treed5f3e3c30303a936c1508e82fa63759685610e9a /pkgs/os-specific/darwin/cf-private
parentb93f4234e8b662600dc3caba2ed2fbc1fb7619d9 (diff)
downloadnixlib-4efd4053ed183d63f09615cf30ea822e708a4fbe.tar
nixlib-4efd4053ed183d63f09615cf30ea822e708a4fbe.tar.gz
nixlib-4efd4053ed183d63f09615cf30ea822e708a4fbe.tar.bz2
nixlib-4efd4053ed183d63f09615cf30ea822e708a4fbe.tar.lz
nixlib-4efd4053ed183d63f09615cf30ea822e708a4fbe.tar.xz
nixlib-4efd4053ed183d63f09615cf30ea822e708a4fbe.tar.zst
nixlib-4efd4053ed183d63f09615cf30ea822e708a4fbe.zip
stdenv/darwin: integrate a new CoreFoundation
This also updates the bootstrap tool builder to LLVM 5, but not the ones
we actually use for bootstrap. I'll make that change in a subsequent commit
so as to provide traceable provenance of the bootstrap tools.
Diffstat (limited to 'pkgs/os-specific/darwin/cf-private')
-rw-r--r--pkgs/os-specific/darwin/cf-private/default.nix74
1 files changed, 56 insertions, 18 deletions
diff --git a/pkgs/os-specific/darwin/cf-private/default.nix b/pkgs/os-specific/darwin/cf-private/default.nix
index 603c0f652b01..3fac20d23c78 100644
--- a/pkgs/os-specific/darwin/cf-private/default.nix
+++ b/pkgs/os-specific/darwin/cf-private/default.nix
@@ -1,21 +1,59 @@
-{ stdenv, osx_private_sdk, CF }:
+{ CF, apple_sdk }:
 
-stdenv.mkDerivation {
-  name = "${CF.name}-private";
-  phases = [ "installPhase" "fixupPhase" ];
-  installPhase = ''
-    dest=$out/Library/Frameworks/CoreFoundation.framework/Headers
-    mkdir -p $dest
-    pushd $dest
-      for file in ${CF}/Library/Frameworks/CoreFoundation.framework/Headers/*; do
-        ln -sf $file
-      done
-
-      # Copy or overwrite private headers, some of these might already
-      # exist in CF but the private versions have more information.
-      cp -Lfv ${osx_private_sdk}/include/CoreFoundationPrivateHeaders/* $dest
-    popd
-  '';
+# cf-private is a bit weird, but boils down to CF with a weird setup-hook that
+# makes a build link against the system CoreFoundation rather than our pure one.
+# The reason it exists is that although our CF headers and build are pretty legit
+# now, the underlying runtime is quite different. Apple's in a bit of flux around CF
+# right now, and support three different backends for it: swift, "C", and an ObjC
+# one. The former two can be built from public sources, but the ObjC one isn't really
+# public. Unfortunately, it's also one of the core underpinnings of a lot of Mac-
+# specific behavior, and defines a lot of symbols that some Objective C apps depend
+# on, even though one might expect those symbols to derive from Foundation. So if
+# your app relies on NSArray and several other basic ObjC types, it turns out that
+# because of their magic "toll-free bridging" support, the symbols for those types
+# live in CoreFoundation with an ObjC runtime. And because that isn't public, we have
+# this hack in place to let people link properly anyway. Phew!
+# 
+# This can be revisited if Apple ever decide to release the ObjC backend in a publicly
+# buildable form.
+# 
+# This doesn't really need to rebuild CF, but it's cheap, and adding a setup hook to
+# an existing package was annoying. We need a buildEnv that knows how to add those
+CF.overrideAttrs (orig: {
+  # PLEASE if you add things to this derivation, explain in reasonable detail why
+  # you're adding them and when the workaround can go away. This whole derivation is
+  # a workaround and if you don't explain what you're working around, it makes it
+  # very hard for people to clean it up later.
 
+  name = "${orig.name}-private";
   setupHook = ./setup-hook.sh;
-}
+
+  # TODO: consider re-adding https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/darwin/apple-source-releases/CF/cf-bridging.patch
+  # once the missing headers are in and see if that fixes all need for this.
+
+  # This can go away once https://bugs.swift.org/browse/SR-8741 happens, which is
+  # looking more likely these days with the friendly people at Apple! We only need
+  # the header because the setup hook takes care of linking us against a version
+  # of the framework with the functionality built into it. The main user I know of
+  # this is watchman, who can almost certainly switch to the pure CF once the header
+  # and functionality is merged in.
+  installPhase = orig.installPhase + ''
+    basepath="Library/Frameworks/CoreFoundation.framework/Headers"
+    path="$basepath/CFFileDescriptor.h"
+
+    # Append the include at top level or nobody will notice the header we're about to add
+    sed -i '/CFNotificationCenter.h/a #include <CoreFoundation/CFFileDescriptor.h>' \
+      "$out/$basepath/CoreFoundation.h"
+
+    cp ${apple_sdk.frameworks.CoreFoundation}/$path $out/$path
+  '' +
+  # This one is less likely to go away, but I'll mention it anyway. The issue is at
+  # https://bugs.swift.org/browse/SR-8744, and the main user I know of is qtbase
+  ''
+    path="$basepath/CFURLEnumerator.h"    
+    sed -i '/CFNotificationCenter.h/a #include <CoreFoundation/CFURLEnumerator.h>' \
+      "$out/$basepath/CoreFoundation.h"
+
+    cp ${apple_sdk.frameworks.CoreFoundation}/$path $out/$path
+  '';
+})
\ No newline at end of file