Skip to content

Commit

Permalink
Nixpkgs work around for strip on aarch64-darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishmack committed Mar 17, 2023
1 parent 25d82a0 commit 49e77eb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion compiler/ghc/default.nix
Expand Up @@ -283,6 +283,26 @@ stdenv.mkDerivation (rec {
"distPhase"
];

# This work around comes from nixpkgs/pkgs/development/compilers/ghc
#
# Sometimes we have to dispatch between the bintools wrapper and the unwrapped
# derivation for certain tools depending on the platform.
bintoolsFor = {
# GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is
# part of the bintools wrapper (due to codesigning requirements), but not on
# x86_64-darwin.
install_name_tool =
if stdenv.targetPlatform.isAarch64
then targetCC.bintools
else targetCC.bintools.bintools;
# Same goes for strip.
strip =
# TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold"
if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin
then targetCC.bintools
else targetCC.bintools.bintools;
};

# GHC is a bit confused on its cross terminology.
preConfigure =
# This code is only included when cross compiling as it breaks aarch64-darwin native compilation
Expand All @@ -305,7 +325,10 @@ stdenv.mkDerivation (rec {
export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
export STRIP="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}strip"
export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip"
'' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") ''
export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool"
export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool"
'' + lib.optionalString (targetPlatform == hostPlatform && useLdGold)
# set LD explicitly if we want gold even if we aren't cross compiling
''
Expand Down

0 comments on commit 49e77eb

Please sign in to comment.