From 04fa8e006cf662a9cdefa52162e006304ad8877d Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Wed, 8 Feb 2017 21:16:01 +0100 Subject: [PATCH 1/2] darwin: add setup-hook to fix CF references --- .../setup-hooks/fix-darwin-frameworks.sh | 31 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 33 insertions(+) create mode 100644 pkgs/build-support/setup-hooks/fix-darwin-frameworks.sh 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 00000000000..e3a08b2598d --- /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") +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index dc3924c5829..f40f7d10577 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -305,6 +305,8 @@ with pkgs; fixDarwinDylibNames = makeSetupHook { } ../build-support/setup-hooks/fix-darwin-dylib-names.sh; + fixDarwinFrameworks = makeSetupHook { } ../build-support/setup-hooks/fix-darwin-frameworks.sh; + keepBuildTree = makeSetupHook { } ../build-support/setup-hooks/keep-build-tree.sh; enableGCOVInstrumentation = makeSetupHook { } ../build-support/setup-hooks/enable-coverage-instrumentation.sh; From 97a3e7cf52068f9e48d3d811f97638c73a513d85 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Tue, 7 Mar 2017 22:10:07 +0100 Subject: [PATCH 2/2] darwin-frameworks: don't use pure CF --- pkgs/os-specific/darwin/apple-sdk/default.nix | 3 +++ pkgs/top-level/all-packages.nix | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/os-specific/darwin/apple-sdk/default.nix b/pkgs/os-specific/darwin/apple-sdk/default.nix index 1148fe5c4a1..338e02b9df3 100644 --- a/pkgs/os-specific/darwin/apple-sdk/default.nix +++ b/pkgs/os-specific/darwin/apple-sdk/default.nix @@ -119,6 +119,9 @@ let propagatedBuildInputs = deps; + # don't use pure CF for dylibs that depend on frameworks + setupHook = ../../../build-support/setup-hooks/fix-darwin-frameworks.sh; + # allows building the symlink tree __impureHostDeps = [ "/System/Library/Frameworks/${name}.framework" ]; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f40f7d10577..45f2438c782 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8733,7 +8733,8 @@ with pkgs; libusb = callPackage ../development/libraries/libusb {}; libusb1 = callPackage ../development/libraries/libusb1 { - inherit (darwin) libobjc IOKit; + inherit (darwin) libobjc; + inherit (darwin.apple_sdk.frameworks) IOKit; }; libusbmuxd = callPackage ../development/libraries/libusbmuxd { };