about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2017-02-08 21:16:01 +0100
committerDaiderd Jordan <daiderd@gmail.com>2017-03-12 15:19:03 +0100
commit04fa8e006cf662a9cdefa52162e006304ad8877d (patch)
tree1d219cb7253046e940d854916f90033ee3c6cfe3 /pkgs/build-support
parent6fce6c9adb5dd252c09aea9fe2c5d26c8264d6b7 (diff)
downloadnixlib-04fa8e006cf662a9cdefa52162e006304ad8877d.tar
nixlib-04fa8e006cf662a9cdefa52162e006304ad8877d.tar.gz
nixlib-04fa8e006cf662a9cdefa52162e006304ad8877d.tar.bz2
nixlib-04fa8e006cf662a9cdefa52162e006304ad8877d.tar.lz
nixlib-04fa8e006cf662a9cdefa52162e006304ad8877d.tar.xz
nixlib-04fa8e006cf662a9cdefa52162e006304ad8877d.tar.zst
nixlib-04fa8e006cf662a9cdefa52162e006304ad8877d.zip
darwin: add setup-hook to fix CF references
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/setup-hooks/fix-darwin-frameworks.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkgs/build-support/setup-hooks/fix-darwin-frameworks.sh b/pkgs/build-support/setup-hooks/fix-darwin-frameworks.sh
new file mode 100644
index 000000000000..e3a08b2598d9
--- /dev/null
+++ b/pkgs/build-support/setup-hooks/fix-darwin-frameworks.sh
@@ -0,0 +1,31 @@
+# On Mac OS X, frameworks are linked to the system CoreFoundation but
+# dynamic libraries built with nix use a pure version of CF this
+# causes segfaults for binaries that depend on it at runtime.  This
+# can be solved in two ways.
+# 1. Rewrite references to the pure CF using this setup hook, this
+# works for the simple case but this can still cause problems if other
+# dependencies (eg. python) use the pure CF.
+# 2. Create a wrapper for the binary that sets DYLD_FRAMEWORK_PATH to
+# /System/Library/Frameworks.  This will make everything load the
+# system's CoreFoundation framework while still keeping the
+# dependencies pure for other packages.
+
+fixupOutputHooks+=('fixDarwinFrameworksIn $prefix')
+
+fixDarwinFrameworks() {
+    local systemPrefix='/System/Library/Frameworks'
+
+    for fn in "$@"; do
+        if [ -L "$fn" ]; then continue; fi
+        echo "$fn: fixing dylib"
+
+        for framework in $(otool -L "$fn" | awk '/CoreFoundation\.framework/ {print $1}'); do
+          install_name_tool -change "$framework" "$systemPrefix/CoreFoundation.framework/Versions/A/CoreFoundation" "$fn" >&2
+        done
+    done
+}
+
+fixDarwinFrameworksIn() {
+    local dir="$1"
+    fixDarwinFrameworks $(find "$dir" -name "*.dylib")
+}