Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add setup-hook to fix darwin frameworks #22571

Merged
merged 2 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pkgs/build-support/setup-hooks/fix-darwin-frameworks.sh
Original file line number Diff line number Diff line change
@@ -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")
}
3 changes: 3 additions & 0 deletions pkgs/os-specific/darwin/apple-sdk/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ];

Expand Down
5 changes: 4 additions & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -8731,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 { };
Expand Down