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

stdenv/darwin: set NIX_COREFOUNDATION_RPATH via hook #111385

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
useCoreFoundationFramework () {
# Avoid overriding value set by the impure CF
if [ -z "${NIX_COREFOUNDATION_RPATH+x}" ]; then
export NIX_COREFOUNDATION_RPATH=@out@/Library/Frameworks
fi
}

addEnvHooks "$hostOffset" useCoreFoundationFramework
9 changes: 6 additions & 3 deletions pkgs/os-specific/darwin/swift-corelibs/corefoundation.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ lib, stdenv, fetchFromGitHub, fetchurl, ninja, python3, curl, libxml2, objc4, ICU }:
{ lib, stdenv, fetchFromGitHub, fetchurl, ninja, python3, curl, libxml2, objc4, ICU
, withRpathHook ? true }:

let
# 10.12 adds a new sysdir.h that our version of CF in the main derivation depends on, but
Expand All @@ -10,7 +11,7 @@ let
};
in

stdenv.mkDerivation {
stdenv.mkDerivation ({
name = "swift-corefoundation";

src = fetchFromGitHub {
Expand Down Expand Up @@ -111,4 +112,6 @@ stdenv.mkDerivation {
ln -s Versions/Current/$i $base/$i
done
'';
}
} // lib.optionalAttrs withRpathHook {
setupHook = ./corefoundation-setup-hook.sh;
veprbl marked this conversation as resolved.
Show resolved Hide resolved
})
16 changes: 9 additions & 7 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ let
"/usr/lib/libSystem.B.dylib"
"/usr/lib/system/libunc.dylib" # This dependency is "hidden", so our scanning code doesn't pick it up
];

withoutRpathHook = drv: drv.override { withRpathHook = false; };
in rec {
commonPreHook = ''
export NIX_ENFORCE_NO_NATIVE=''${NIX_ENFORCE_NO_NATIVE-1}
Expand Down Expand Up @@ -343,7 +345,8 @@ in rec {
darwin = super.darwin // {
inherit (darwin)
binutils dyld Libsystem xnu configd ICU libdispatch libclosure
launchd CF darwin-stubs;
launchd darwin-stubs;
CF = withoutRpathHook darwin.CF;
};
};
in with prevStage; stageFun 2 prevStage {
Expand All @@ -352,7 +355,7 @@ in rec {
'';

extraNativeBuildInputs = [ pkgs.xz ];
extraBuildInputs = [ pkgs.darwin.CF ];
extraBuildInputs = [ (withoutRpathHook pkgs.darwin.CF) ];
libcxx = pkgs.libcxx;

allowedRequisites =
Expand Down Expand Up @@ -399,7 +402,7 @@ in rec {
# and instead goes by $PATH, which happens to contain bootstrapTools. So it goes and
# patches our shebangs back to point at bootstrapTools. This makes sure bash comes first.
extraNativeBuildInputs = with pkgs; [ xz ];
extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ];
extraBuildInputs = [ (withoutRpathHook pkgs.darwin.CF) pkgs.bash ];
libcxx = pkgs.libcxx;

extraPreHook = ''
Expand Down Expand Up @@ -448,16 +451,16 @@ in rec {
darwin = super.darwin // rec {
inherit (darwin) dyld Libsystem libiconv locale darwin-stubs;

CF = super.darwin.CF.override {
CF = withoutRpathHook (super.darwin.CF.override {
inherit libxml2;
python3 = prevStage.python3;
};
});
};
};
in with prevStage; stageFun 4 prevStage {
shell = "${pkgs.bash}/bin/bash";
extraNativeBuildInputs = with pkgs; [ xz ];
extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ];
extraBuildInputs = [ (withoutRpathHook pkgs.darwin.CF) pkgs.bash ];
libcxx = pkgs.libcxx;

extraPreHook = ''
Expand Down Expand Up @@ -503,7 +506,6 @@ in rec {
targetPlatform = localSystem;

preHook = commonPreHook + ''
export NIX_COREFOUNDATION_RPATH=${pkgs.darwin.CF}/Library/Frameworks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason this is set directly in the stdenv is to ensure that any usage of frameworks takes priority. The goal here is to link against the pure version as much as possible, but system frameworks also link against the CoreFoundation framework in which case also linking against the pure build causes problems.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the ordering might be enforced by extraBuildInputs, but just in case there is a simple bash logic in corefoundation-setup-hook.sh to avoid overriding NIX_COREFOUNDATION_RPATH.

export PATH_LOCALE=${pkgs.darwin.locale}/share/locale
'';

Expand Down