on iko/ghcjs-patch-master help sign in
Make sure we don't flood libraries with RPATHs on macOS
5838e54Moritz Angermann
builder/comp-builder.nix+30−1
@@ -73,6 +73,35 @@ let
73 ${lib.concatMapStringsSep "\n" (p: exactDep "--package-db ${p.components.library}/package.conf.d" p.identifier.name) component.depends}
73 ${lib.concatMapStringsSep "\n" (p: exactDep "--package-db ${p.components.library}/package.conf.d" p.identifier.name) component.depends}
74 ${lib.concatMapStringsSep "\n" (exactDep "") nonReinstallablePkgs}
74 ${lib.concatMapStringsSep "\n" (exactDep "") nonReinstallablePkgs}
75
75
76+ ''
77+ # This code originates in the `generic-builder.nix` from nixpkgs. However GHC has been fixed
78+ # to drop unused libraries referneced from libraries; and this patch is usually included in the
79+ # nixpkgs's GHC builds. This doesn't sadly make this stupid hack unnecessary. It resurfes in
80+ # the form of Cabal trying to be smart. Cabal when linking a library figures out that you likely
81+ # need those `rpath` entries, and passes `-optl-Wl,-rpath,...` for each dynamic library path to
82+ # GHC, thus subverting the linker and forcing it to insert all those RPATHs weather or not they
83+ # are needed. We therfore reuse the linker hack here to move all al dynamic lirbaries into a
84+ # common folder (as links) and thus prevent Cabal from going nuts.
85+ #
86+ # TODO: Fix Cabal.
87+ # TODO: this is only needed if we do dynamic libraries.
88+ + lib.optionalString stdenv.isDarwin ''
89+ # Work around a limit in the macOS Sierra linker on the number of paths
90+ # referenced by any one dynamic library:
91+ #
92+ # Create a local directory with symlinks of the *.dylib (macOS shared
93+ # libraries) from all the dependencies.
94+ local dynamicLinksDir="$out/lib/links"
95+ mkdir -p $dynamicLinksDir
96+ for d in $(grep dynamic-library-dirs "$out/package.conf.d/"*|awk '{print $2}'|sort -u); do
97+ ln -s "$d/"*.dylib $dynamicLinksDir
98+ done
99+ # Edit the local package DB to reference the links directory.
100+ for f in "$out/package.conf.d/"*.conf; do
101+ sed -i "s,dynamic-library-dirs: .*,dynamic-library-dirs: $dynamicLinksDir," $f
102+ done
103+ '' + ''
104+ ${ghc.targetPrefix}ghc-pkg --package-db $out/package.conf.d recache
76 '' + ''
105 '' + ''
77 ${ghc.targetPrefix}ghc-pkg --package-db $out/package.conf.d check
106 ${ghc.targetPrefix}ghc-pkg --package-db $out/package.conf.d check
78 '');
107 '');
@@ -138,7 +167,7 @@ in stdenv.mkDerivation ({
138 '';
167 '';
139
168
140 buildPhase = ''
169 buildPhase = ''
141− $SETUP_HS build -j$NIX_BUILD_CORES
170+ $SETUP_HS build -j$NIX_BUILD_CORES ${lib.concatStringsSep " " component.setupBuildFlags}
142 '';
171 '';
143
172
144 checkPhase = ''
173 checkPhase = ''
modules/package.nix+4
@@ -123,6 +123,10 @@ in {
123 type = listOfFilteringNulls str;
123 type = listOfFilteringNulls str;
124 default = [];
124 default = [];
125 };
125 };
126+ setupBuildFlags = mkOption {
127+ type = listOfFilteringNulls str;
128+ default = [];
129+ };
126 doExactConfig = mkOption {
130 doExactConfig = mkOption {
127 type = bool;
131 type = bool;
128 default = false;
132 default = false;