diff options
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/ghc/8.10.7.nix')
-rw-r--r-- | nixpkgs/pkgs/development/compilers/ghc/8.10.7.nix | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/nixpkgs/pkgs/development/compilers/ghc/8.10.7.nix b/nixpkgs/pkgs/development/compilers/ghc/8.10.7.nix index 7e59bd974a25..40b57223fa1d 100644 --- a/nixpkgs/pkgs/development/compilers/ghc/8.10.7.nix +++ b/nixpkgs/pkgs/development/compilers/ghc/8.10.7.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, pkgsBuildTarget, targetPackages +{ lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages # build-tools , bootPkgs @@ -11,11 +11,13 @@ , # 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. - buildLlvmPackages, llvmPackages + buildTargetLlvmPackages, llvmPackages , # If enabled, GHC will be built with the GPL-free but slower integer-simple # library instead of the faster but GPLed integer-gmp library. @@ -120,26 +122,37 @@ 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 buildLlvmPackages.llvm; + ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; targetCC = builtins.head toolsForTarget; + # 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; + }; + # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 # see #84670 and #49071 for more background. 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 - ]; + (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. variantSuffix = lib.concatStrings [ @@ -148,6 +161,14 @@ let ]; in + +# C compiler, bintools and LLVM are used at build time, but will also leak into +# the resulting GHC's settings file and used at runtime. This means that we are +# currently only able to build GHC if hostPlatform == buildPlatform. +assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; +assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; +assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; + stdenv.mkDerivation (rec { version = "8.10.7"; pname = "${targetPrefix}ghc${variantSuffix}"; @@ -196,6 +217,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}" @@ -211,7 +233,17 @@ 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 useLLVM '' + export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" + export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" + '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' + # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm + export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" + '' + '' echo -n "${buildMK}" > mk/build.mk sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure @@ -290,9 +322,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 +349,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 = { |