Merge pull request #147260 from NixOS/haskell-updates

haskellPackages: improve LLVM handling for GHC
This commit is contained in:
sterni 2021-11-28 20:13:48 +01:00 committed by GitHub
commit 2222809b8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 257 additions and 150 deletions

View file

@ -24,8 +24,29 @@
</section>
<section xml:id="sec-release-22.05-incompatibilities">
<title>Backward Incompatibilities</title>
<itemizedlist spacing="compact">
<listitem>
<para>
<literal>pkgs.ghc</literal> now refers to
<literal>pkgs.targetPackages.haskellPackages.ghc</literal>.
This <emphasis>only</emphasis> makes a difference if you are
cross-compiling and will ensure that
<literal>pkgs.ghc</literal> always runs on the host platform
and compiles for the target platform (similar to
<literal>pkgs.gcc</literal> for example).
<literal>haskellPackages.ghc</literal> still behaves as
before, running on the build platform and compiling for the
host platform (similar to <literal>stdenv.cc</literal>). This
means you dont have to adjust your derivations if you use
<literal>haskellPackages.callPackage</literal>, but when using
<literal>pkgs.callPackage</literal> and taking
<literal>ghc</literal> as an input, you should now use
<literal>buildPackages.ghc</literal> instead to ensure cross
compilation keeps working (or switch to
<literal>haskellPackages.callPackage</literal>).
</para>
</listitem>
</itemizedlist>
</section>
<section xml:id="sec-release-22.05-notable-changes">
<title>Other Notable Changes</title>

View file

@ -10,4 +10,16 @@ In addition to numerous new and upgraded packages, this release has the followin
## Backward Incompatibilities {#sec-release-22.05-incompatibilities}
* `pkgs.ghc` now refers to `pkgs.targetPackages.haskellPackages.ghc`.
This *only* makes a difference if you are cross-compiling and will
ensure that `pkgs.ghc` always runs on the host platform and compiles
for the target platform (similar to `pkgs.gcc` for example).
`haskellPackages.ghc` still behaves as before, running on the build
platform and compiling for the host platform (similar to `stdenv.cc`).
This means you don't have to adjust your derivations if you use
`haskellPackages.callPackage`, but when using `pkgs.callPackage` and
taking `ghc` as an input, you should now use `buildPackages.ghc`
instead to ensure cross compilation keeps working (or switch to
`haskellPackages.callPackage`).
## Other Notable Changes {#sec-release-22.05-notable-changes}

View file

@ -3,6 +3,8 @@
, ncurses5
, ncurses6, gmp, libiconv, numactl
, llvmPackages
, coreutils
, targetPackages
# minimal = true; will remove files that aren't strictly necessary for
# regular builds and GHC bootstrapping.
@ -140,6 +142,19 @@ let
libEnvVar = lib.optionalString stdenv.hostPlatform.isDarwin "DY"
+ "LD_LIBRARY_PATH";
runtimeDeps = [
targetPackages.stdenv.cc
targetPackages.stdenv.cc.bintools
coreutils # for cat
]
++ lib.optionals useLLVM [
(lib.getBin llvmPackages.llvm)
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];
in
stdenv.mkDerivation rec {
@ -156,7 +171,6 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ perl ];
propagatedBuildInputs =
lib.optionals useLLVM [ llvmPackages.llvm ]
# Because musl bindists currently provide no way to tell where
# libgmp is (see not [musl bindists have no .buildinfo]), we need
# to propagate `gmp`, otherwise programs built by this ghc will
@ -177,7 +191,7 @@ stdenv.mkDerivation rec {
# fixing the above-mentioned release issue,
# and for GHC >= 9.* it is not clear as of writing whether that switch
# will be made there too.
++ lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this
lib.optionals stdenv.hostPlatform.isMusl [ gmp ]; # musl bindist needs this
# Set LD_LIBRARY_PATH or equivalent so that the programs running as part
# of the bindist installer can find the libraries they expect.
@ -278,6 +292,15 @@ stdenv.mkDerivation rec {
# calls install-strip ...
dontBuild = true;
# Patch scripts to include runtime dependencies in $PATH.
postInstall = ''
for i in "$out/bin/"*; do
test ! -h "$i" || continue
isScript "$i" || continue
sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i"
done
'';
# Apparently necessary for the ghc Alpine (musl) bindist:
# When we strip, and then run the
# patchelf --set-rpath "${libPath}:$(patchelf --print-rpath $p)" $p
@ -360,7 +383,6 @@ stdenv.mkDerivation rec {
doInstallCheck = true;
installCheckPhase = ''
unset ${libEnvVar}
# Sanity check, can ghc create executables?
cd $TMP
mkdir test-ghc; cd test-ghc
@ -369,6 +391,8 @@ stdenv.mkDerivation rec {
module Main where
main = putStrLn \$([|"yes"|])
EOF
# can't use env -i here because otherwise we don't find -lgmp on musl
env ${libEnvVar}= PATH= \
$out/bin/ghc --make main.hs || exit 1
echo compilation ok
[ $(./main) == "yes" ]
@ -378,6 +402,8 @@ stdenv.mkDerivation rec {
targetPrefix = "";
enableShared = true;
inherit llvmPackages;
# Our Cabal compiler name
haskellCompilerName = "ghc-${version}";
};

View file

@ -3,6 +3,8 @@
, ncurses5
, ncurses6, gmp, libiconv, numactl
, llvmPackages
, coreutils
, targetPackages
# minimal = true; will remove files that aren't strictly necessary for
# regular builds and GHC bootstrapping.
@ -155,6 +157,19 @@ let
libEnvVar = lib.optionalString stdenv.hostPlatform.isDarwin "DY"
+ "LD_LIBRARY_PATH";
runtimeDeps = [
targetPackages.stdenv.cc
targetPackages.stdenv.cc.bintools
coreutils # for cat
]
++ lib.optionals useLLVM [
(lib.getBin llvmPackages.llvm)
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];
in
stdenv.mkDerivation rec {
@ -175,9 +190,6 @@ stdenv.mkDerivation rec {
# and update this comment accordingly.
nativeBuildInputs = [ perl ];
propagatedBuildInputs =
lib.optionals useLLVM [ llvmPackages.llvm ]
;
# Set LD_LIBRARY_PATH or equivalent so that the programs running as part
# of the bindist installer can find the libraries they expect.
@ -278,6 +290,15 @@ stdenv.mkDerivation rec {
# calls install-strip ...
dontBuild = true;
# Patch scripts to include runtime dependencies in $PATH.
postInstall = ''
for i in "$out/bin/"*; do
test ! -h "$i" || continue
isScript "$i" || continue
sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i"
done
'';
# Apparently necessary for the ghc Alpine (musl) bindist:
# When we strip, and then run the
# patchelf --set-rpath "${libPath}:$(patchelf --print-rpath $p)" $p
@ -360,7 +381,6 @@ stdenv.mkDerivation rec {
doInstallCheck = true;
installCheckPhase = ''
unset ${libEnvVar}
# Sanity check, can ghc create executables?
cd $TMP
mkdir test-ghc; cd test-ghc
@ -369,7 +389,7 @@ stdenv.mkDerivation rec {
module Main where
main = putStrLn \$([|"yes"|])
EOF
$out/bin/ghc --make main.hs || exit 1
env -i $out/bin/ghc --make main.hs || exit 1
echo compilation ok
[ $(./main) == "yes" ]
'';
@ -378,6 +398,8 @@ stdenv.mkDerivation rec {
targetPrefix = "";
enableShared = true;
inherit llvmPackages;
# Our Cabal compiler name
haskellCompilerName = "ghc-${version}";
};

View file

@ -11,7 +11,9 @@
, # GHC can be built with system libffi or a bundled one.
libffi ? null
, useLLVM ? !stdenv.targetPlatform.isx86
, useLLVM ? !(stdenv.targetPlatform.isx86
|| stdenv.targetPlatform.isPowerPC
|| stdenv.targetPlatform.isSparc)
, # LLVM is conceptually a run-time-only depedendency, but for
# non-x86, we need LLVM to bootstrap later stages, so it becomes a
# build-time dependency too.
@ -120,6 +122,8 @@ let
++ lib.optional (!enableIntegerSimple) gmp
++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
# TODO(@sternenseemann): is buildTarget LLVM unnecessary?
# GHC doesn't seem to have {LLC,OPT}_HOST
toolsForTarget = [
pkgsBuildTarget.targetPackages.stdenv.cc
] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;
@ -132,15 +136,6 @@ let
useLdGold = targetPlatform.linker == "gold" ||
(targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl);
runtimeDeps = [
targetPackages.stdenv.cc.bintools
coreutils
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];
# Makes debugging easier to see which variant is at play in `nix-store -q --tree`.
variantSuffix = lib.concatStrings [
(lib.optionalString stdenv.hostPlatform.isMusl "-musl")
@ -196,6 +191,7 @@ stdenv.mkDerivation (rec {
postPatch = "patchShebangs .";
# GHC is a bit confused on its cross terminology.
# TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths
preConfigure = ''
for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
export "''${env#TARGET_}=''${!env}"
@ -212,6 +208,19 @@ stdenv.mkDerivation (rec {
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"
'' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") ''
export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool"
export INSTALL_NAME_TOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}install_name_tool"
'' + lib.optionalString useLLVM ''
export LLC="${lib.getBin llvmPackages.llvm}/bin/llc"
export OPT="${lib.getBin llvmPackages.llvm}/bin/opt"
'' + lib.optionalString (targetCC.isClang || (useLLVM && stdenv.targetPlatform.isDarwin)) (let
# LLVM backend on Darwin needs clang, if we are already using clang, might as well set the environment variable.
# See also https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm
clang = if targetCC.isClang then targetCC else llvmPackages.clang;
in ''
export CLANG="${clang}/bin/${clang.targetPrefix}clang"
'') + ''
echo -n "${buildMK}" > mk/build.mk
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
@ -290,9 +299,6 @@ stdenv.mkDerivation (rec {
buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
propagatedBuildInputs = [ targetPackages.stdenv.cc ]
++ lib.optional useLLVM llvmPackages.llvm;
depsTargetTarget = map lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);
@ -320,13 +326,6 @@ stdenv.mkDerivation (rec {
postInstall = ''
# Install the bash completion file.
install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
# Patch scripts to include "readelf" and "cat" in $PATH.
for i in "$out/bin/"*; do
test ! -h $i || continue
egrep --quiet '^#!' <(head -n 1 $i) || continue
sed -i -e '2i export PATH="$PATH:${lib.makeBinPath runtimeDeps}"' $i
done
'';
passthru = {

View file

@ -2,6 +2,8 @@
, fetchurl, perl, gcc
, ncurses5, ncurses6, gmp, glibc, libiconv
, llvmPackages
, coreutils
, targetPackages
}:
# Prebuilt only does native
@ -30,6 +32,19 @@ let
downloadsUrl = "https://downloads.haskell.org/ghc";
runtimeDeps = [
targetPackages.stdenv.cc
targetPackages.stdenv.cc.bintools
coreutils # for cat
]
++ lib.optionals useLLVM [
(lib.getBin llvmPackages.llvm)
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];
in
stdenv.mkDerivation rec {
@ -62,7 +77,6 @@ stdenv.mkDerivation rec {
or (throw "cannot bootstrap GHC on this platform"));
nativeBuildInputs = [ perl ];
propagatedBuildInputs = lib.optionals useLLVM [ llvmPackages.llvm ];
# Cannot patchelf beforehand due to relative RPATHs that anticipate
# the final install location/
@ -130,6 +144,15 @@ stdenv.mkDerivation rec {
# calls install-strip ...
dontBuild = true;
# Patch scripts to include runtime dependencies in $PATH.
postInstall = ''
for i in "$out/bin/"*; do
test ! -h "$i" || continue
isScript "$i" || continue
sed -i -e '2i export PATH="${lib.makeBinPath runtimeDeps}:$PATH"' "$i"
done
'';
# On Linux, use patchelf to modify the executables so that they can
# find editline/gmp.
postFixup = lib.optionalString stdenv.isLinux ''
@ -163,7 +186,6 @@ stdenv.mkDerivation rec {
doInstallCheck = true;
installCheckPhase = ''
unset ${libEnvVar}
# Sanity check, can ghc create executables?
cd $TMP
mkdir test-ghc; cd test-ghc
@ -172,7 +194,7 @@ stdenv.mkDerivation rec {
module Main where
main = putStrLn \$([|"yes"|])
EOF
$out/bin/ghc --make main.hs || exit 1
env -i $out/bin/ghc --make main.hs || exit 1
echo compilation ok
[ $(./main) == "yes" ]
'';
@ -181,14 +203,15 @@ stdenv.mkDerivation rec {
targetPrefix = "";
enableShared = true;
inherit llvmPackages;
# Our Cabal compiler name
haskellCompilerName = "ghc-${version}";
};
meta = rec {
license = lib.licenses.bsd3;
platforms = ["x86_64-linux" "aarch64-linux" "i686-linux" "x86_64-darwin"];
hydraPlatforms = builtins.filter (p: p != "aarch64-linux") platforms;
platforms = ["x86_64-linux" "i686-linux" "x86_64-darwin"];
# build segfaults, use ghc8102Binary which has proper musl support instead
broken = stdenv.hostPlatform.isMusl;
maintainers = with lib.maintainers; [

View file

@ -10,7 +10,9 @@
, # GHC can be built with system libffi or a bundled one.
libffi ? null
, useLLVM ? !stdenv.targetPlatform.isx86
, useLLVM ? !(stdenv.targetPlatform.isx86
|| stdenv.targetPlatform.isPowerPC
|| stdenv.targetPlatform.isSparc)
, # LLVM is conceptually a run-time-only depedendency, but for
# non-x86, we need LLVM to bootstrap later stages, so it becomes a
# build-time dependency too.
@ -128,6 +130,8 @@ let
++ lib.optional (!enableIntegerSimple) gmp
++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
# TODO(@sternenseemann): is buildTarget LLVM unnecessary?
# GHC doesn't seem to have {LLC,OPT}_HOST
toolsForTarget = [
pkgsBuildTarget.targetPackages.stdenv.cc
] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;
@ -140,15 +144,6 @@ let
useLdGold = targetPlatform.linker == "gold" ||
(targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl);
runtimeDeps = [
targetPackages.stdenv.cc.bintools
coreutils
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];
# Makes debugging easier to see which variant is at play in `nix-store -q --tree`.
variantSuffix = lib.concatStrings [
(lib.optionalString stdenv.hostPlatform.isMusl "-musl")
@ -197,6 +192,7 @@ stdenv.mkDerivation (rec {
postPatch = "patchShebangs .";
# GHC is a bit confused on its cross terminology.
# TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths
preConfigure =
# Aarch64 allow backward bootstrapping since earlier versions are unstable.
# Same for musl, as earlier versions do not provide a musl bindist for bootstrapping.
@ -220,6 +216,16 @@ stdenv.mkDerivation (rec {
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"
'' + lib.optionalString useLLVM ''
export LLC="${lib.getBin llvmPackages.llvm}/bin/llc"
export OPT="${lib.getBin llvmPackages.llvm}/bin/opt"
'' + lib.optionalString (targetCC.isClang || (useLLVM && stdenv.targetPlatform.isDarwin)) (let
# LLVM backend on Darwin needs clang, if we are already using clang, might as well set the environment variable.
# See also https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm
clang = if targetCC.isClang then targetCC else llvmPackages.clang;
in ''
export CLANG="${clang}/bin/${clang.targetPrefix}clang"
'') + ''
echo -n "${buildMK dontStrip}" > mk/build.mk
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
@ -293,9 +299,6 @@ stdenv.mkDerivation (rec {
buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
propagatedBuildInputs = [ targetPackages.stdenv.cc ]
++ lib.optional useLLVM llvmPackages.llvm;
depsTargetTarget = map lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);
@ -319,13 +322,6 @@ stdenv.mkDerivation (rec {
postInstall = ''
# Install the bash completion file.
install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
# Patch scripts to include "readelf" and "cat" in $PATH.
for i in "$out/bin/"*; do
test ! -h $i || continue
egrep --quiet '^#!' <(head -n 1 $i) || continue
sed -i -e '2i export PATH="$PATH:${lib.makeBinPath runtimeDeps}"' $i
done
'';
passthru = {
@ -345,7 +341,17 @@ stdenv.mkDerivation (rec {
guibou
] ++ lib.teams.haskell.members;
timeout = 24 * 3600;
inherit (ghc.meta) license platforms;
inherit (ghc.meta) license;
# hardcode platforms because the bootstrap GHC differs depending on the platform,
# with differing platforms available for each of them; See HACK comment in
# 8.10.2-binary.nix for an explanation of the musl special casing.
platforms = [
"x86_64-linux"
] ++ lib.optionals (!hostPlatform.isMusl) [
"i686-linux"
"aarch64-linux"
"x86_64-darwin"
];
# integer-simple builds are broken with musl when bootstrapping using
# GHC 8.10.2 and below, however it is not possible to reverse bootstrap
# GHC 8.8.4 with GHC 8.10.7.

View file

@ -12,7 +12,9 @@
, # GHC can be built with system libffi or a bundled one.
libffi ? null
, useLLVM ? !stdenv.targetPlatform.isx86
, useLLVM ? !(stdenv.targetPlatform.isx86
|| stdenv.targetPlatform.isPowerPC
|| stdenv.targetPlatform.isSparc)
, # LLVM is conceptually a run-time-only depedendency, but for
# non-x86, we need LLVM to bootstrap later stages, so it becomes a
# build-time dependency too.
@ -115,6 +117,8 @@ let
++ lib.optional (!enableIntegerSimple) gmp
++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
# TODO(@sternenseemann): is buildTarget LLVM unnecessary?
# GHC doesn't seem to have {LLC,OPT}_HOST
toolsForTarget = [
pkgsBuildTarget.targetPackages.stdenv.cc
] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;
@ -127,15 +131,6 @@ let
useLdGold = targetPlatform.linker == "gold" ||
(targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl);
runtimeDeps = [
targetPackages.stdenv.cc.bintools
coreutils
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];
# Makes debugging easier to see which variant is at play in `nix-store -q --tree`.
variantSuffix = lib.concatStrings [
(lib.optionalString stdenv.hostPlatform.isMusl "-musl")
@ -162,6 +157,7 @@ stdenv.mkDerivation (rec {
LANG = "en_US.UTF-8";
# GHC is a bit confused on its cross terminology.
# TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths
preConfigure = ''
for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
export "''${env#TARGET_}=''${!env}"
@ -178,6 +174,19 @@ stdenv.mkDerivation (rec {
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"
'' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") ''
export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool"
export INSTALL_NAME_TOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}install_name_tool"
'' + lib.optionalString useLLVM ''
export LLC="${lib.getBin llvmPackages.llvm}/bin/llc"
export OPT="${lib.getBin llvmPackages.llvm}/bin/opt"
'' + lib.optionalString (targetCC.isClang || (useLLVM && stdenv.targetPlatform.isDarwin)) (let
# LLVM backend on Darwin needs clang, if we are already using clang, might as well set the environment variable.
# See also https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm
clang = if targetCC.isClang then targetCC else llvmPackages.clang;
in ''
export CLANG="${clang}/bin/${clang.targetPrefix}clang"
'') + ''
echo -n "${buildMK}" > mk/build.mk
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
@ -255,9 +264,6 @@ stdenv.mkDerivation (rec {
buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
propagatedBuildInputs = [ targetPackages.stdenv.cc ]
++ lib.optional useLLVM llvmPackages.llvm;
depsTargetTarget = map lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);
@ -285,13 +291,6 @@ stdenv.mkDerivation (rec {
postInstall = ''
# Install the bash completion file.
install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
# Patch scripts to include "readelf" and "cat" in $PATH.
for i in "$out/bin/"*; do
test ! -h $i || continue
egrep --quiet '^#!' <(head -n 1 $i) || continue
sed -i -e '2i export PATH="$PATH:${lib.makeBinPath runtimeDeps}"' $i
done
'';
passthru = {

View file

@ -12,7 +12,10 @@
, # GHC can be built with system libffi or a bundled one.
libffi ? null
, useLLVM ? !stdenv.targetPlatform.isx86
, useLLVM ? !(stdenv.targetPlatform.isx86
|| stdenv.targetPlatform.isPowerPC
|| stdenv.targetPlatform.isSparc
|| (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin))
, # LLVM is conceptually a run-time-only depedendency, but for
# non-x86, we need LLVM to bootstrap later stages, so it becomes a
# build-time dependency too.
@ -115,6 +118,8 @@ let
++ lib.optional (!enableIntegerSimple) gmp
++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
# TODO(@sternenseemann): is buildTarget LLVM unnecessary?
# GHC doesn't seem to have {LLC,OPT}_HOST
toolsForTarget = [
pkgsBuildTarget.targetPackages.stdenv.cc
] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;
@ -126,15 +131,6 @@ let
# see #84670 and #49071 for more background.
useLdGold = targetPlatform.linker == "gold" || (targetPlatform.linker == "bfd" && !targetPlatform.isMusl);
runtimeDeps = [
targetPackages.stdenv.cc.bintools
coreutils
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];
# Makes debugging easier to see which variant is at play in `nix-store -q --tree`.
variantSuffix = lib.concatStrings [
(lib.optionalString stdenv.hostPlatform.isMusl "-musl")
@ -161,6 +157,7 @@ stdenv.mkDerivation (rec {
LANG = "en_US.UTF-8";
# GHC is a bit confused on its cross terminology.
# TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths
preConfigure = ''
for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
export "''${env#TARGET_}=''${!env}"
@ -177,6 +174,19 @@ stdenv.mkDerivation (rec {
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"
'' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") ''
export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool"
export INSTALL_NAME_TOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}install_name_tool"
'' + lib.optionalString useLLVM ''
export LLC="${lib.getBin llvmPackages.llvm}/bin/llc"
export OPT="${lib.getBin llvmPackages.llvm}/bin/opt"
'' + lib.optionalString (targetCC.isClang || (useLLVM && stdenv.targetPlatform.isDarwin)) (let
# LLVM backend on Darwin needs clang, if we are already using clang, might as well set the environment variable.
# See also https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm
clang = if targetCC.isClang then targetCC else llvmPackages.clang;
in ''
export CLANG="${clang}/bin/${clang.targetPrefix}clang"
'') + ''
echo -n "${buildMK}" > mk/build.mk
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
@ -258,9 +268,6 @@ stdenv.mkDerivation (rec {
buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
propagatedBuildInputs = [ targetPackages.stdenv.cc ]
++ lib.optional useLLVM llvmPackages.llvm;
depsTargetTarget = map lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);
@ -288,13 +295,6 @@ stdenv.mkDerivation (rec {
postInstall = ''
# Install the bash completion file.
install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
# Patch scripts to include "readelf" and "cat" in $PATH.
for i in "$out/bin/"*; do
test ! -h $i || continue
egrep --quiet '^#!' <(head -n 1 $i) || continue
sed -i -e '2i export PATH="$PATH:${lib.makeBinPath runtimeDeps}"' $i
done
'';
passthru = {

View file

@ -17,7 +17,10 @@
!stdenv.targetPlatform.isWindows
, elfutils # for DWARF support
, useLLVM ? !stdenv.targetPlatform.isx86 || stdenv.targetPlatform.isiOS
, useLLVM ? !(stdenv.targetPlatform.isx86
|| stdenv.targetPlatform.isPowerPC
|| stdenv.targetPlatform.isSparc
|| (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin))
, # LLVM is conceptually a run-time-only depedendency, but for
# non-x86, we need LLVM to bootstrap later stages, so it becomes a
# build-time dependency too.
@ -128,6 +131,8 @@ let
++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv
++ lib.optional enableDwarf elfutils;
# TODO(@sternenseemann): is buildTarget LLVM unnecessary?
# GHC doesn't seem to have {LLC,OPT}_HOST
toolsForTarget = [
pkgsBuildTarget.targetPackages.stdenv.cc
] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;
@ -140,15 +145,6 @@ let
useLdGold = targetPlatform.linker == "gold" ||
(targetPlatform.linker == "bfd" && (targetPackages.stdenv.cc.bintools.bintools.hasGold or false) && !targetPlatform.isMusl);
runtimeDeps = [
targetPackages.stdenv.cc.bintools
coreutils
]
# On darwin, we need unwrapped bintools as well (for otool)
++ lib.optionals (stdenv.targetPlatform.linker == "cctools") [
targetPackages.stdenv.cc.bintools.bintools
];
# Makes debugging easier to see which variant is at play in `nix-store -q --tree`.
variantSuffix = lib.concatStrings [
(lib.optionalString stdenv.hostPlatform.isMusl "-musl")
@ -174,6 +170,7 @@ stdenv.mkDerivation (rec {
postPatch = "patchShebangs .";
# GHC is a bit confused on its cross terminology.
# TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths
preConfigure = ''
for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
export "''${env#TARGET_}=''${!env}"
@ -191,6 +188,19 @@ stdenv.mkDerivation (rec {
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"
'' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") ''
export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool"
export INSTALL_NAME_TOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}install_name_tool"
'' + lib.optionalString useLLVM ''
export LLC="${lib.getBin llvmPackages.llvm}/bin/llc"
export OPT="${lib.getBin llvmPackages.llvm}/bin/opt"
'' + lib.optionalString (targetCC.isClang || (useLLVM && stdenv.targetPlatform.isDarwin)) (let
# LLVM backend on Darwin needs clang, if we are already using clang, might as well set the environment variable.
# See also https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm
clang = if targetCC.isClang then targetCC else llvmPackages.clang;
in ''
export CLANG="${clang}/bin/${clang.targetPrefix}clang"
'') + ''
# otherwise haddock fails when generating the compiler docs
export LANG=C.UTF-8
@ -278,9 +288,6 @@ stdenv.mkDerivation (rec {
buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
propagatedBuildInputs = [ targetPackages.stdenv.cc ]
++ lib.optional useLLVM llvmPackages.llvm;
depsTargetTarget = map lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);
@ -308,13 +315,6 @@ stdenv.mkDerivation (rec {
postInstall = ''
# Install the bash completion file.
install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
# Patch scripts to include "readelf" and "cat" in $PATH.
for i in "$out/bin/"*; do
test ! -h $i || continue
egrep --quiet '^#!' <(head -n 1 $i) || continue
sed -i -e '2i export PATH="$PATH:${lib.makeBinPath runtimeDeps}"' $i
done
'';
passthru = {

View file

@ -4,8 +4,7 @@ with haskellLib;
self: super: {
# This compiler version needs llvm 9.x.
llvmPackages = pkgs.lib.dontRecurseIntoAttrs pkgs.llvmPackages_9;
llvmPackages = pkgs.lib.dontRecurseIntoAttrs self.ghc.llvmPackages;
# Disable GHC 8.10.x core libraries.
array = null;

View file

@ -4,8 +4,7 @@ with haskellLib;
self: super: {
# This compiler version needs llvm 6.x.
llvmPackages = pkgs.lib.dontRecurseIntoAttrs pkgs.llvmPackages_6;
llvmPackages = pkgs.lib.dontRecurseIntoAttrs self.ghc.llvmPackages;
# Disable GHC 8.6.x core libraries.
array = null;

View file

@ -4,8 +4,7 @@ with haskellLib;
self: super: {
# This compiler version needs llvm 7.x.
llvmPackages = pkgs.lib.dontRecurseIntoAttrs pkgs.llvmPackages_7;
llvmPackages = pkgs.lib.dontRecurseIntoAttrs self.ghc.llvmPackages;
# Disable GHC 8.8.x core libraries.
array = null;

View file

@ -4,8 +4,7 @@ with haskellLib;
self: super: {
# This compiler version needs llvm 10.x.
llvmPackages = pkgs.lib.dontRecurseIntoAttrs pkgs.llvmPackages_10;
llvmPackages = pkgs.lib.dontRecurseIntoAttrs self.ghc.llvmPackages;
# Disable GHC 9.0.x core libraries.
array = null;

View file

@ -4,8 +4,7 @@ with haskellLib;
self: super: {
# This compiler version needs llvm 10.x.
llvmPackages = pkgs.lib.dontRecurseIntoAttrs pkgs.llvmPackages_10;
llvmPackages = pkgs.lib.dontRecurseIntoAttrs self.ghc.llvmPackages;
# Disable GHC 9.2.x core libraries.
array = null;

View file

@ -11,7 +11,7 @@ with haskellLib;
self: super: {
llvmPackages = pkgs.lib.dontRecurseIntoAttrs pkgs.llvmPackages_10;
llvmPackages = pkgs.lib.dontRecurseIntoAttrs self.ghc.llvmPackages;
# Disable GHC 8.7.x core libraries.
array = null;

View file

@ -1,14 +1,8 @@
{ lib, stdenv, ghc, llvmPackages, packages, symlinkJoin, makeWrapper
# Include LLVM by default if GHC doesn't have native code generation support
# See https://gitlab.haskell.org/ghc/ghc/-/wikis/platforms
, useLLVM ? !(lib.any lib.id ([
stdenv.targetPlatform.isx86
stdenv.targetPlatform.isPowerPC
stdenv.targetPlatform.isSparc
] ++ lib.optionals (lib.versionAtLeast ghc.version "9.2") [
(stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin)
# TODO(@sternenseemann): Is armv7a supported for iOS?
]))
# GHC will have LLVM available if necessary for the respective target,
# so useLLVM only needs to be changed if -fllvm is to be used for a
# platform that has NCG support
, useLLVM ? false
, postBuild ? ""
, ghcLibdir ? null # only used by ghcjs, when resolving plugins
}:

View file

@ -12074,7 +12074,15 @@ with pkgs;
# current default compiler is”, if you bump this:
haskellPackages = dontRecurseIntoAttrs haskell.packages.ghc8107;
inherit (haskellPackages) ghc;
# haskellPackages.ghc is build->host (it exposes the compiler used to build the
# set, similarly to stdenv.cc), but pkgs.ghc should be host->target to be more
# consistent with the gcc, gnat, clang etc. derivations
#
# We use targetPackages.haskellPackages.ghc if available since this also has
# the withPackages wrapper available. In the final cross-compiled package set
# however, targetPackages won't be populated, so we need to fall back to the
# plain, cross-compiled compiler (which is only theoretical at the moment).
ghc = targetPackages.haskellPackages.ghc or haskell.compiler.ghc8107;
cabal-install = haskell.lib.compose.justStaticExecutables haskellPackages.cabal-install;

View file

@ -50,7 +50,9 @@ in {
compiler = {
ghc865Binary = callPackage ../development/compilers/ghc/8.6.5-binary.nix { };
ghc865Binary = callPackage ../development/compilers/ghc/8.6.5-binary.nix {
llvmPackages = pkgs.llvmPackages_6;
};
ghc8102Binary = callPackage ../development/compilers/ghc/8.10.2-binary.nix {
llvmPackages = pkgs.llvmPackages_9;
@ -62,11 +64,11 @@ in {
};
ghc8107Binary = callPackage ../development/compilers/ghc/8.10.7-binary.nix {
llvmPackages = pkgs.llvmPackages_11;
llvmPackages = pkgs.llvmPackages_12;
};
ghc8107BinaryMinimal = callPackage ../development/compilers/ghc/8.10.7-binary.nix {
llvmPackages = pkgs.llvmPackages_11;
llvmPackages = pkgs.llvmPackages_12;
minimal = true;
};
@ -96,8 +98,8 @@ in {
# https://github.com/xattr/xattr/issues/44 and
# https://github.com/xattr/xattr/issues/55 are solved.
inherit (buildPackages.darwin) xattr autoSignDarwinBinariesHook;
buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_9;
llvmPackages = pkgs.llvmPackages_9;
buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_12;
llvmPackages = pkgs.llvmPackages_12;
};
ghc901 = callPackage ../development/compilers/ghc/9.0.1.nix {
bootPkgs =
@ -109,8 +111,8 @@ in {
packages.ghc8107Binary;
inherit (buildPackages.python3Packages) sphinx;
inherit (buildPackages.darwin) autoSignDarwinBinariesHook;
buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_10;
llvmPackages = pkgs.llvmPackages_10;
buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_9;
llvmPackages = pkgs.llvmPackages_9;
};
ghc921 = callPackage ../development/compilers/ghc/9.2.1.nix {
bootPkgs =
@ -124,8 +126,8 @@ in {
# https://github.com/xattr/xattr/issues/44 and
# https://github.com/xattr/xattr/issues/55 are solved.
inherit (buildPackages.darwin) xattr autoSignDarwinBinariesHook;
buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_10;
llvmPackages = pkgs.llvmPackages_10;
buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_12;
llvmPackages = pkgs.llvmPackages_12;
};
ghcHEAD = callPackage ../development/compilers/ghc/head.nix {
bootPkgs = packages.ghc8107Binary;
@ -134,8 +136,8 @@ in {
# https://github.com/xattr/xattr/issues/44 and
# https://github.com/xattr/xattr/issues/55 are solved.
inherit (buildPackages.darwin) xattr autoSignDarwinBinariesHook;
buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_10;
llvmPackages = pkgs.llvmPackages_10;
buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_12;
llvmPackages = pkgs.llvmPackages_12;
libffi = pkgs.libffi;
};