From 92652b4d79cf09705c011dbf1c38bc871a4011c8 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Fri, 21 Jul 2017 20:29:18 +0200 Subject: [PATCH 1/3] darwin-CF: use @rpath for library id and add an rpath entry for CF based on NIX_COREFOUNDATION_RPATH --- pkgs/build-support/cc-wrapper/ld-wrapper.sh | 4 ++++ pkgs/os-specific/darwin/apple-source-releases/CF/default.nix | 2 +- pkgs/stdenv/darwin/default.nix | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/cc-wrapper/ld-wrapper.sh b/pkgs/build-support/cc-wrapper/ld-wrapper.sh index a775b6da8237d..38712665e432d 100644 --- a/pkgs/build-support/cc-wrapper/ld-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/ld-wrapper.sh @@ -145,6 +145,10 @@ if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ]; then fi done done + + if [ -n "${NIX_COREFOUNDATION_RPATH:-}" ]; then + extraAfter+=(-rpath $NIX_COREFOUNDATION_RPATH) + fi fi diff --git a/pkgs/os-specific/darwin/apple-source-releases/CF/default.nix b/pkgs/os-specific/darwin/apple-source-releases/CF/default.nix index e44966aa84d67..5589d1592f462 100644 --- a/pkgs/os-specific/darwin/apple-source-releases/CF/default.nix +++ b/pkgs/os-specific/darwin/apple-source-releases/CF/default.nix @@ -18,7 +18,7 @@ appleDerivation { --replace "/usr/sbin/" "" \ --replace "/bin/" "" \ --replace "INSTALLNAME=/System" "INSTALLNAME=$out" \ - --replace "install_name_tool -id /System" "install_name_tool -id $out" \ + --replace "install_name_tool -id /System/Library/Frameworks" "install_name_tool -id @rpath" \ --replace 'chown -RH -f root:wheel $(DSTBASE)/CoreFoundation.framework' "" \ --replace 'chmod -RH' 'chmod -R' diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 61b7df1954347..6739ce3f5c8fe 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -300,6 +300,7 @@ in rec { targetPlatform = localSystem; preHook = commonPreHook + '' + export NIX_COREFOUNDATION_RPATH=${pkgs.darwin.CF}/Library/Frameworks export PATH_LOCALE=${pkgs.darwin.locale}/share/locale ''; From cc1bfbd9a7f0fe7f7c4f0dec81990b5ce7d6cff3 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Sat, 22 Jul 2017 13:31:48 +0200 Subject: [PATCH 2/3] darwin-frameworks: use the system CF when frameworks are used This will get propagated down to other libraries loaded because everything in nixpkgs references CF based on an rpath entry. --- pkgs/os-specific/darwin/apple-sdk/default.nix | 2 +- .../os-specific/darwin/apple-sdk/framework-setup-hook.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 pkgs/os-specific/darwin/apple-sdk/framework-setup-hook.sh diff --git a/pkgs/os-specific/darwin/apple-sdk/default.nix b/pkgs/os-specific/darwin/apple-sdk/default.nix index 73126ce1f5c1f..957b610f3a259 100644 --- a/pkgs/os-specific/darwin/apple-sdk/default.nix +++ b/pkgs/os-specific/darwin/apple-sdk/default.nix @@ -134,7 +134,7 @@ let propagatedBuildInputs = deps; # don't use pure CF for dylibs that depend on frameworks - setupHook = ../../../build-support/setup-hooks/fix-darwin-frameworks.sh; + setupHook = ./framework-setup-hook.sh; # allows building the symlink tree __impureHostDeps = [ "/System/Library/Frameworks/${name}.framework" ]; diff --git a/pkgs/os-specific/darwin/apple-sdk/framework-setup-hook.sh b/pkgs/os-specific/darwin/apple-sdk/framework-setup-hook.sh new file mode 100644 index 0000000000000..9d96a4adbaa1f --- /dev/null +++ b/pkgs/os-specific/darwin/apple-sdk/framework-setup-hook.sh @@ -0,0 +1,9 @@ +# This configures the stdenv to use /System/Library/Frameworks/CoreFoundation.framework +# instead of the nix version by including the system frameworks path +# as an rpath entry when creating binaries. + +useSystemCoreFoundationFramework () { + export NIX_COREFOUNDATION_RPATH=/System/Library/Frameworks +} + +envHooks+=(useSystemCoreFoundationFramework) From 5a28fd660a3f6eff6e6b53ecf787577ae271201a Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Mon, 28 Aug 2017 21:14:59 +0200 Subject: [PATCH 3/3] darwin-frameworks: move fixup setup-hook --- .../setup-hooks/fix-darwin-frameworks.sh | 31 ----------------- .../darwin/apple-sdk/framework-setup-hook.sh | 33 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 -- 3 files changed, 33 insertions(+), 33 deletions(-) delete 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 deleted file mode 100644 index cf8416c0838dc..0000000000000 --- a/pkgs/build-support/setup-hooks/fix-darwin-frameworks.sh +++ /dev/null @@ -1,31 +0,0 @@ -# On macOS, 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/os-specific/darwin/apple-sdk/framework-setup-hook.sh b/pkgs/os-specific/darwin/apple-sdk/framework-setup-hook.sh index 9d96a4adbaa1f..04d8e878f4f76 100644 --- a/pkgs/os-specific/darwin/apple-sdk/framework-setup-hook.sh +++ b/pkgs/os-specific/darwin/apple-sdk/framework-setup-hook.sh @@ -1,3 +1,36 @@ +# On macOS, 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") +} + + # This configures the stdenv to use /System/Library/Frameworks/CoreFoundation.framework # instead of the nix version by including the system frameworks path # as an rpath entry when creating binaries. diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e51bc545aec85..e44b670ac082f 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -328,8 +328,6 @@ 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;