Skip to content

Commit

Permalink
haskell.compiler.ghc9*: work around output cycles on aarch64-darwin
Browse files Browse the repository at this point in the history
Due to link time dead code elimination not working on aarch64-darwin,
some unused store path references in Paths_* modules are retained. This
causes reference cycles when a separate `bin` output is used.

To prevent this, add a patch to Cabal as shipped by GHC which infers
based on the installation layout (which is influenced by
enableSeparateBinOutput, enableSeparateDataOutput etc. in a Nix build)
which references can be retained without causing a reference cycle. This
ensures that packages that were fine with a bin output will also work on
aarch64-darwin. Packages that cause a reference cycle anyways (by
actually using references that do cause one) fail due to a missing
symbol – here we are trading the overall benefit for a more confusing
error message.

For details, refer to the explanation comment in the patch.
  • Loading branch information
sternenseemann committed Mar 11, 2023
1 parent 41c538f commit 45aae5c
Show file tree
Hide file tree
Showing 5 changed files with 634 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkgs/development/compilers/ghc/9.2.4.nix
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ stdenv.mkDerivation (rec {
extraPrefix = "libraries/Cabal/";
sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY=";
})
] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [
# Prevent the paths module from emitting symbols that we don't use
# when building with separate outputs.
#
# These cause problems as they're not eliminated by GHC's dead code
# elimination on aarch64-darwin. (see
# https://github.com/NixOS/nixpkgs/issues/140774 for details).
./Cabal-3.6-paths-fix-cycle-aarch64-darwin.patch
];

postPatch = "patchShebangs .";
Expand Down
8 changes: 8 additions & 0 deletions pkgs/development/compilers/ghc/9.2.5.nix
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ stdenv.mkDerivation (rec {
extraPrefix = "libraries/Cabal/";
sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY=";
})
] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [
# Prevent the paths module from emitting symbols that we don't use
# when building with separate outputs.
#
# These cause problems as they're not eliminated by GHC's dead code
# elimination on aarch64-darwin. (see
# https://github.com/NixOS/nixpkgs/issues/140774 for details).
./Cabal-3.6-paths-fix-cycle-aarch64-darwin.patch
];

postPatch = "patchShebangs .";
Expand Down
8 changes: 8 additions & 0 deletions pkgs/development/compilers/ghc/9.2.6.nix
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ stdenv.mkDerivation (rec {
extraPrefix = "libraries/Cabal/";
sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY=";
})
] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [
# Prevent the paths module from emitting symbols that we don't use
# when building with separate outputs.
#
# These cause problems as they're not eliminated by GHC's dead code
# elimination on aarch64-darwin. (see
# https://github.com/NixOS/nixpkgs/issues/140774 for details).
./Cabal-3.6-paths-fix-cycle-aarch64-darwin.patch
];

postPatch = "patchShebangs .";
Expand Down
8 changes: 8 additions & 0 deletions pkgs/development/compilers/ghc/9.2.7.nix
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ stdenv.mkDerivation (rec {
extraPrefix = "libraries/Cabal/";
sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY=";
})
] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [
# Prevent the paths module from emitting symbols that we don't use
# when building with separate outputs.
#
# These cause problems as they're not eliminated by GHC's dead code
# elimination on aarch64-darwin. (see
# https://github.com/NixOS/nixpkgs/issues/140774 for details).
./Cabal-3.6-paths-fix-cycle-aarch64-darwin.patch
];

postPatch = "patchShebangs .";
Expand Down
Loading

0 comments on commit 45aae5c

Please sign in to comment.