diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index a6694e2e99c9c..bf1c27f2a812e 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -1,4 +1,4 @@ -{ lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages +{ lib, stdenv, pkgsBuildTarget, pkgsHostTarget, buildPackages, targetPackages # build-tools , bootPkgs @@ -39,7 +39,10 @@ enableShared ? !stdenv.targetPlatform.isWindows && !stdenv.targetPlatform.useiOSPrebuilt , # Whether to build terminfo. - enableTerminfo ? !stdenv.targetPlatform.isWindows + enableTerminfo ? !(stdenv.targetPlatform.isWindows + # terminfo can't be built for cross + || (stdenv.buildPlatform != stdenv.hostPlatform) + || (stdenv.hostPlatform != stdenv.targetPlatform)) , # What flavour to build. An empty string indicates no # specific flavour and falls back to ghc default values. @@ -55,21 +58,29 @@ , enableHaddockProgram ? # Disabled for cross; see note [HADDOCK_DOCS]. - (stdenv.targetPlatform == stdenv.hostPlatform) + (stdenv.buildPlatform == stdenv.hostPlatform && stdenv.targetPlatform == stdenv.hostPlatform) , # Whether to disable the large address space allocator # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ disableLargeAddressSpace ? stdenv.targetPlatform.isiOS + +, # Whether to build an unregisterised version of GHC. + # GHC will normally auto-detect whether it can do a registered build, but this + # option will force it to do an unregistered build when set to true. + # See https://gitlab.haskell.org/ghc/ghc/-/wikis/building/unregisterised + enableUnregisterised ? false }@args: assert !enableIntegerSimple -> gmp != null; # Cross cannot currently build the `haddock` program for silly reasons, # see note [HADDOCK_DOCS]. -assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; +assert (stdenv.buildPlatform != stdenv.hostPlatform || stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; + +# GHC does not support building when all 3 platforms are different. +assert stdenv.buildPlatform == stdenv.hostPlatform || stdenv.hostPlatform == stdenv.targetPlatform; let - libffi_name = if stdenv.isDarwin && stdenv.isAarch64 then "libffi" else "libffi_3_3"; inherit (stdenv) buildPlatform hostPlatform targetPlatform; inherit (bootPkgs) ghc; @@ -86,6 +97,8 @@ let endif BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} BUILD_SPHINX_PDF = NO + + WITH_TERMINFO = ${if enableTerminfo then "YES" else "NO"} '' + # Note [HADDOCK_DOCS]: # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` @@ -134,7 +147,9 @@ let pkgsBuildTarget.targetPackages.stdenv.cc ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; + buildCC = buildPackages.stdenv.cc; targetCC = builtins.head toolsForTarget; + installCC = pkgsHostTarget.targetPackages.stdenv.cc; # toolPath calculates the absolute path to the name tool associated with a # given `stdenv.cc` derivation, i.e. it picks the correct derivation to take @@ -185,14 +200,37 @@ let (lib.optionalString enableIntegerSimple "-integer-simple") ]; -in + libffi_name = if stdenv.isDarwin && stdenv.isAarch64 then "libffi" else "libffi_3_3"; + + # These libraries are library dependencies of the standard libraries bundled + # by GHC (core libs) users will link their compiled artifacts again. Thus, + # they should be taken from targetPackages. + # + # We need to use pkgsHostTarget if we are cross compiling a native GHC compiler, + # though (when native compiling GHC, pkgsHostTarget == targetPackages): + # + # 1. targetPackages would be empty(-ish) in this situation since we can't + # execute cross compiled compilers in order to obtain the libraries + # that would be in targetPackages. + # 2. pkgsHostTarget is fine to use since hostPlatform == targetPlatform in this + # situation. + # 3. The core libs used by the final GHC (stage 2) for user artifacts are also + # used to build stage 2 GHC itself, i.e. the core libs are both host and + # target. + targetLibs = + let + basePackageSet = + if hostPlatform != targetPlatform + then targetPackages + else pkgsHostTarget; + in + { + inherit (basePackageSet) gmp; + # dynamic inherits are not possible in Nix + libffi = basePackageSet.${libffi_name}; + }; -# 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; +in stdenv.mkDerivation (rec { version = "8.10.7"; @@ -299,6 +337,10 @@ stdenv.mkDerivation (rec { # 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" '' + '' + # No need for absolute paths since these tools only need to work during the build + export CC_STAGE0="$CC_FOR_BUILD" + export LD_STAGE0="$LD_FOR_BUILD" + export AR_STAGE0="$AR_FOR_BUILD" echo -n "${buildMK}" > mk/build.mk sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure @@ -329,21 +371,23 @@ stdenv.mkDerivation (rec { done ''; + # Although it is usually correct to pass --host, we don't do that here because + # GHC's usage of build, host, and target is non-standard. + # See https://gitlab.haskell.org/ghc/ghc/-/wikis/building/cross-compiling # TODO(@Ericson2314): Always pass "--target" and always prefix. - configurePlatforms = [ "build" "host" ] - ++ lib.optional (targetPlatform != hostPlatform) "target"; + configurePlatforms = [ "build" ] + ++ lib.optional (buildPlatform != hostPlatform || targetPlatform != hostPlatform) "target"; # `--with` flags for libraries needed for RTS linker configureFlags = [ "--datadir=$doc/share/doc/ghc" - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" ] ++ lib.optionals (args.${libffi_name} != null) [ "--with-system-libffi" - "--with-ffi-includes=${targetPackages.${libffi_name}.dev}/include" - "--with-ffi-libraries=${targetPackages.${libffi_name}.out}/lib" + "--with-ffi-includes=${targetLibs.libffi.dev}/include" + "--with-ffi-libraries=${targetLibs.libffi.out}/lib" ] ++ lib.optionals (targetPlatform == hostPlatform && !enableIntegerSimple) [ - "--with-gmp-includes=${targetPackages.gmp.dev}/include" - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" + "--with-gmp-includes=${targetLibs.gmp.dev}/include" + "--with-gmp-libraries=${targetLibs.gmp.out}/lib" ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib" @@ -355,6 +399,8 @@ stdenv.mkDerivation (rec { "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" ] ++ lib.optionals (disableLargeAddressSpace) [ "--disable-large-address-space" + ] ++ lib.optionals enableUnregisterised [ + "--enable-unregisterised" ]; # Make sure we never relax`$PATH` and hooks support for compatibility. @@ -366,12 +412,19 @@ stdenv.mkDerivation (rec { nativeBuildInputs = [ perl autoreconfHook autoconf automake m4 python3 ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour + bootPkgs.ghc-settings-edit ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ autoSignDarwinBinariesHook ] ++ lib.optionals enableDocs [ sphinx ]; + # Used by the STAGE0 compiler to build stage1 + depsBuildBuild = [ + buildCC + # stage0 builds terminfo unconditionally, so we always need ncurses + ncurses + ]; # For building runtime libs depsBuildTarget = toolsForTarget; @@ -402,6 +455,35 @@ stdenv.mkDerivation (rec { requiredSystemFeatures = [ "big-parallel" ]; postInstall = '' + settingsFile="$out/lib/${targetPrefix}${passthru.haskellCompilerName}/settings" + + # Make the installed GHC use the host->target tools. + ghc-settings-edit "$settingsFile" \ + "C compiler command" "${toolPath "cc" installCC}" \ + "Haskell CPP command" "${toolPath "cc" installCC}" \ + "C++ compiler command" "${toolPath "c++" installCC}" \ + "ld command" "${toolPath "ld${lib.optionalString useLdGold ".gold"}" installCC}" \ + "Merge objects command" "${toolPath "ld${lib.optionalString useLdGold ".gold"}" installCC}" \ + "ar command" "${toolPath "ar" installCC}" \ + "ranlib command" "${toolPath "ranlib" installCC}" + '' + + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' + ghc-settings-edit "$settingsFile" \ + "otool command" "${toolPath "otool" installCC}" \ + "install_name_tool command" "${toolPath "install_name_tool" installCC}" + '' + + lib.optionalString useLLVM '' + ghc-settings-edit "$settingsFile" \ + "LLVM llc command" "${lib.getBin llvmPackages.llvm}/bin/llc" \ + "LLVM opt command" "${lib.getBin llvmPackages.llvm}/bin/opt" + '' + # FIXME(@sternenseemann): use installCC instead if possible + + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' + ghc-settings-edit "$settingsFile" \ + "LLVM clang command" "${llvmPackages.clang}/bin/${llvmPackages.clang.targetPrefix}clang" + '' + + '' + # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc ''; @@ -427,7 +509,8 @@ stdenv.mkDerivation (rec { guibou ] ++ lib.teams.haskell.members; timeout = 24 * 3600; - inherit (ghc.meta) license platforms; + platforms = lib.platforms.all; + inherit (ghc.meta) license; }; } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index b6d4d7236fe6b..f9b24f291aaa0 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -12,6 +12,7 @@ , stdenv , pkgsBuildTarget , pkgsHostTarget +, buildPackages , targetPackages , fetchpatch @@ -65,8 +66,14 @@ enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic && !isGhcjs , # Whether to build terminfo. + # FIXME(@sternenseemann): This actually doesn't influence what hadrian does, + # just what buildInputs etc. looks like. It would be best if we could actually + # tell it what to do like it was possible with make. enableTerminfo ? !(stdenv.targetPlatform.isWindows - || stdenv.targetPlatform.isGhcjs) + || stdenv.targetPlatform.isGhcjs + # terminfo can't be built for cross + || (stdenv.buildPlatform != stdenv.hostPlatform) + || (stdenv.hostPlatform != stdenv.targetPlatform)) , # Libdw.c only supports x86_64, i686 and s390x as of 2022-08-04 enableDwarf ? (stdenv.targetPlatform.isx86 || @@ -117,9 +124,8 @@ -- no way to set this via the command line finalStage :: Stage finalStage = ${ - # Always build the stage 2 compiler if possible. Note we can currently - # assume hostPlatform == buildPlatform. - # TODO(@sternenseemann): improve this condition when we can cross-compile GHC + # Always build the stage 2 compiler if possible. + # TODO(@sternensemann): unify condition with make-built GHCs if stdenv.hostPlatform.canExecute stdenv.targetPlatform then "Stage2" # native compiler or “native” cross e.g. pkgsStatic else "Stage1" # cross compiler @@ -222,10 +228,22 @@ , # Whether to disable the large address space allocator # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ disableLargeAddressSpace ? stdenv.targetPlatform.isiOS + +, # Whether to build an unregisterised version of GHC. + # GHC will normally auto-detect whether it can do a registered build, but this + # option will force it to do an unregistered build when set to true. + # See https://gitlab.haskell.org/ghc/ghc/-/wikis/building/unregisterised + enableUnregisterised ? false }: assert !enableNativeBignum -> gmp != null; +# GHC does not support building when all 3 platforms are different. +assert stdenv.buildPlatform == stdenv.hostPlatform || stdenv.hostPlatform == stdenv.targetPlatform; + +# It is currently impossible to cross-compile GHC with Hadrian. +assert stdenv.buildPlatform == stdenv.hostPlatform; + let inherit (stdenv) buildPlatform hostPlatform targetPlatform; @@ -265,7 +283,9 @@ let else pkgsBuildTarget.targetPackages.stdenv.cc) ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; + buildCC = buildPackages.stdenv.cc; targetCC = builtins.head toolsForTarget; + installCC = pkgsHostTarget.targetPackages.stdenv.cc; # toolPath calculates the absolute path to the name tool associated with a # given `stdenv.cc` derivation, i.e. it picks the correct derivation to take @@ -316,14 +336,33 @@ let (lib.optionalString enableNativeBignum "-native-bignum") ]; -in + # These libraries are library dependencies of the standard libraries bundled + # by GHC (core libs) users will link their compiled artifacts again. Thus, + # they should be taken from targetPackages. + # + # We need to use pkgsHostTarget if we are cross compiling a native GHC compiler, + # though (when native compiling GHC, pkgsHostTarget == targetPackages): + # + # 1. targetPackages would be empty(-ish) in this situation since we can't + # execute cross compiled compilers in order to obtain the libraries + # that would be in targetPackages. + # 2. pkgsHostTarget is fine to use since hostPlatform == targetPlatform in this + # situation. + # 3. The core libs used by the final GHC (stage 2) for user artifacts are also + # used to build stage 2 GHC itself, i.e. the core libs are both host and + # target. + targetLibs = { + inherit + (if hostPlatform != targetPlatform then targetPackages else pkgsHostTarget) + elfutils + gmp + libffi; + }; -# 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 !targetPlatform.isGhcjs -> targetCC == pkgsHostTarget.targetPackages.stdenv.cc; -assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; -assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; + # Our Cabal compiler name + haskellCompilerName = "ghc-${version}"; + +in stdenv.mkDerivation ({ pname = "${targetPrefix}ghc${variantSuffix}"; @@ -346,6 +385,10 @@ stdenv.mkDerivation ({ for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do export "''${env#TARGET_}=''${!env}" done + # No need for absolute paths since these tools only need to work during the build + export CC_STAGE0="$CC_FOR_BUILD" + export LD_STAGE0="$LD_FOR_BUILD" + export AR_STAGE0="$AR_FOR_BUILD" # GHC is a bit confused on its cross terminology, as these would normally be # the *host* tools. export CC="${toolPath "cc" targetCC}" @@ -433,14 +476,13 @@ stdenv.mkDerivation ({ # `--with` flags for libraries needed for RTS linker configureFlags = [ "--datadir=$doc/share/doc/ghc" - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" ] ++ lib.optionals (libffi != null && !targetPlatform.isGhcjs) [ "--with-system-libffi" - "--with-ffi-includes=${targetPackages.libffi.dev}/include" - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" + "--with-ffi-includes=${targetLibs.libffi.dev}/include" + "--with-ffi-libraries=${targetLibs.libffi.out}/lib" ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ - "--with-gmp-includes=${targetPackages.gmp.dev}/include" - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" + "--with-gmp-includes=${targetLibs.gmp.dev}/include" + "--with-gmp-libraries=${targetLibs.gmp.out}/lib" ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib" @@ -454,14 +496,16 @@ stdenv.mkDerivation ({ "--disable-large-address-space" ] ++ lib.optionals enableDwarf [ "--enable-dwarf-unwind" - "--with-libdw-includes=${lib.getDev targetPackages.elfutils}/include" - "--with-libdw-libraries=${lib.getLib targetPackages.elfutils}/lib" + "--with-libdw-includes=${lib.getDev targetLibs.elfutils}/include" + "--with-libdw-libraries=${lib.getLib targetLibs.elfutils}/lib" ] ++ lib.optionals targetPlatform.isDarwin [ # Darwin uses llvm-ar. GHC will try to use `-L` with `ar` when it is `llvm-ar` # but it doesn’t currently work because Cabal never uses `-L` on Darwin. See: # https://gitlab.haskell.org/ghc/ghc/-/issues/23188 # https://github.com/haskell/cabal/issues/8882 "fp_cv_prog_ar_supports_dash_l=no" + ] ++ lib.optionals enableUnregisterised [ + "--enable-unregisterised" ]; # Make sure we never relax`$PATH` and hooks support for compatibility. @@ -476,6 +520,8 @@ stdenv.mkDerivation ({ autoconf automake m4 # Python is used in a few scripts invoked by hadrian to generate e.g. rts headers. python3 + # Tool used to update GHC's settings file in postInstall + bootPkgs.ghc-settings-edit ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ autoSignDarwinBinariesHook ] ++ lib.optionals enableDocs [ @@ -484,6 +530,12 @@ stdenv.mkDerivation ({ # For building runtime libs depsBuildTarget = toolsForTarget; + # Used by the STAGE0 compiler to build stage1 + depsBuildBuild = [ + buildCC + # stage0 builds terminfo unconditionally, so we always need ncurses + ncurses + ]; buildInputs = [ perl bash ] ++ (libDeps hostPlatform); @@ -553,19 +605,52 @@ stdenv.mkDerivation ({ # leave bindist directory popd + settingsFile="$out/lib/${targetPrefix}${haskellCompilerName}/lib/settings" + + # Make the installed GHC use the host->target tools. + ghc-settings-edit "$settingsFile" \ + "C compiler command" "${toolPath "cc" installCC}" \ + "Haskell CPP command" "${toolPath "cc" installCC}" \ + "C++ compiler command" "${toolPath "c++" installCC}" \ + "ld command" "${toolPath "ld${lib.optionalString useLdGold ".gold"}" installCC}" \ + "Merge objects command" "${toolPath "ld${lib.optionalString useLdGold ".gold"}" installCC}" \ + "ar command" "${toolPath "ar" installCC}" \ + "ranlib command" "${toolPath "ranlib" installCC}" + '' + + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' + ghc-settings-edit "$settingsFile" \ + "otool command" "${toolPath "otool" installCC}" \ + "install_name_tool command" "${toolPath "install_name_tool" installCC}" + '' + + lib.optionalString useLLVM '' + ghc-settings-edit "$settingsFile" \ + "LLVM llc command" "${lib.getBin llvmPackages.llvm}/bin/llc" \ + "LLVM opt command" "${lib.getBin llvmPackages.llvm}/bin/opt" + '' + # FIXME(@sternenseemann): use installCC instead if possible + + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' + ghc-settings-edit "$settingsFile" \ + "LLVM clang command" "${llvmPackages.clang}/bin/${llvmPackages.clang.targetPrefix}clang" + '' + # Work around a GHC bug which causes unlit to be installed under a different + # name than is used in the settings file. + # https://gitlab.haskell.org/ghc/ghc/-/issues/23317 + + lib.optionalString (lib.versionOlder version "9.8") '' + ghc-settings-edit "$settingsFile" \ + "unlit command" "\$topdir/bin/${targetPrefix}unlit" + '' + + '' + # Install the bash completion file. install -Dm 644 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc ''; passthru = { - inherit bootPkgs targetPrefix; + inherit bootPkgs targetPrefix haskellCompilerName; inherit llvmPackages; inherit enableShared; - # Our Cabal compiler name - haskellCompilerName = "ghc-${version}"; - # Expose hadrian used for bootstrapping, for debugging purposes inherit hadrian; @@ -581,7 +666,8 @@ stdenv.mkDerivation ({ guibou ] ++ lib.teams.haskell.members; timeout = 24 * 3600; - inherit (ghc.meta) license platforms; + platforms = lib.platforms.all; + inherit (ghc.meta) license; }; dontStrip = targetPlatform.useAndroidPrebuilt || targetPlatform.isWasm; diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index 2b23cd75a0ed7..03d7697e2de39 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -3,7 +3,7 @@ , url ? "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz" }: -{ lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages +{ lib, stdenv, pkgsBuildTarget, pkgsHostTarget, buildPackages, targetPackages # build-tools , bootPkgs @@ -42,7 +42,10 @@ enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic , # Whether to build terminfo. - enableTerminfo ? !stdenv.targetPlatform.isWindows + enableTerminfo ? !(stdenv.targetPlatform.isWindows + # terminfo can't be built for cross + || (stdenv.buildPlatform != stdenv.hostPlatform) + || (stdenv.hostPlatform != stdenv.targetPlatform)) , # What flavour to build. An empty string indicates no # specific flavour and falls back to ghc default values. @@ -58,18 +61,29 @@ , enableHaddockProgram ? # Disabled for cross; see note [HADDOCK_DOCS]. - (stdenv.targetPlatform == stdenv.hostPlatform) + (stdenv.buildPlatform == stdenv.hostPlatform && stdenv.targetPlatform == stdenv.hostPlatform) , # Whether to disable the large address space allocator # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ disableLargeAddressSpace ? stdenv.targetPlatform.isiOS + +, # Whether to build an unregisterised version of GHC. + # GHC will normally auto-detect whether it can do a registered build, but this + # option will force it to do an unregistered build when set to true. + # See https://gitlab.haskell.org/ghc/ghc/-/wikis/building/unregisterised + # Registerised RV64 compiler produces programs that segfault + # See https://gitlab.haskell.org/ghc/ghc/-/issues/23957 + enableUnregisterised ? stdenv.hostPlatform.isRiscV64 || stdenv.targetPlatform.isRiscV64 }: assert !enableNativeBignum -> gmp != null; # Cross cannot currently build the `haddock` program for silly reasons, # see note [HADDOCK_DOCS]. -assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; +assert (stdenv.buildPlatform != stdenv.hostPlatform || stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; + +# GHC does not support building when all 3 platforms are different. +assert stdenv.buildPlatform == stdenv.hostPlatform || stdenv.hostPlatform == stdenv.targetPlatform; let inherit (stdenv) buildPlatform hostPlatform targetPlatform; @@ -88,6 +102,8 @@ let endif BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} BUILD_SPHINX_PDF = NO + + WITH_TERMINFO = ${if enableTerminfo then "YES" else "NO"} '' + # Note [HADDOCK_DOCS]: # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` @@ -134,7 +150,9 @@ let pkgsBuildTarget.targetPackages.stdenv.cc ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; + buildCC = buildPackages.stdenv.cc; targetCC = builtins.head toolsForTarget; + installCC = pkgsHostTarget.targetPackages.stdenv.cc; # toolPath calculates the absolute path to the name tool associated with a # given `stdenv.cc` derivation, i.e. it picks the correct derivation to take @@ -185,14 +203,29 @@ let (lib.optionalString enableNativeBignum "-native-bignum") ]; -in + # These libraries are library dependencies of the standard libraries bundled + # by GHC (core libs) users will link their compiled artifacts again. Thus, + # they should be taken from targetPackages. + # + # We need to use pkgsHostTarget if we are cross compiling a native GHC compiler, + # though (when native compiling GHC, pkgsHostTarget == targetPackages): + # + # 1. targetPackages would be empty(-ish) in this situation since we can't + # execute cross compiled compilers in order to obtain the libraries + # that would be in targetPackages. + # 2. pkgsHostTarget is fine to use since hostPlatform == targetPlatform in this + # situation. + # 3. The core libs used by the final GHC (stage 2) for user artifacts are also + # used to build stage 2 GHC itself, i.e. the core libs are both host and + # target. + targetLibs = { + inherit + (if hostPlatform != targetPlatform then targetPackages else pkgsHostTarget) + gmp + libffi; + }; -# 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; +in stdenv.mkDerivation (rec { pname = "${targetPrefix}ghc${variantSuffix}"; @@ -305,6 +338,11 @@ stdenv.mkDerivation (rec { export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" '' + '' + # No need for absolute paths since these tools only need to work during the build + export CC_STAGE0="$CC_FOR_BUILD" + export LD_STAGE0="$LD_FOR_BUILD" + export AR_STAGE0="$AR_FOR_BUILD" + echo -n "${buildMK}" > mk/build.mk '' + lib.optionalString (lib.versionOlder version "9.2" || lib.versionAtLeast version "9.4") '' @@ -346,21 +384,23 @@ stdenv.mkDerivation (rec { 'MinBootGhcVersion="8.10"' ''; + # Although it is usually correct to pass --host, we don't do that here because + # GHC's usage of build, host, and target is non-standard. + # See https://gitlab.haskell.org/ghc/ghc/-/wikis/building/cross-compiling # TODO(@Ericson2314): Always pass "--target" and always prefix. - configurePlatforms = [ "build" "host" ] - ++ lib.optional (targetPlatform != hostPlatform) "target"; + configurePlatforms = [ "build" ] + ++ lib.optional (buildPlatform != hostPlatform || targetPlatform != hostPlatform) "target"; # `--with` flags for libraries needed for RTS linker configureFlags = [ "--datadir=$doc/share/doc/ghc" - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" ] ++ lib.optionals (libffi != null) [ "--with-system-libffi" - "--with-ffi-includes=${targetPackages.libffi.dev}/include" - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" + "--with-ffi-includes=${targetLibs.libffi.dev}/include" + "--with-ffi-libraries=${targetLibs.libffi.out}/lib" ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ - "--with-gmp-includes=${targetPackages.gmp.dev}/include" - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" + "--with-gmp-includes=${targetLibs.gmp.dev}/include" + "--with-gmp-libraries=${targetLibs.gmp.out}/lib" ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ "--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib" @@ -372,6 +412,8 @@ stdenv.mkDerivation (rec { "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" ] ++ lib.optionals (disableLargeAddressSpace) [ "--disable-large-address-space" + ] ++ lib.optionals enableUnregisterised [ + "--enable-unregisterised" ]; # Make sure we never relax`$PATH` and hooks support for compatibility. @@ -383,6 +425,7 @@ stdenv.mkDerivation (rec { nativeBuildInputs = [ perl autoconf automake m4 python3 ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour + bootPkgs.ghc-settings-edit ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ autoSignDarwinBinariesHook ] ++ lib.optionals enableDocs [ @@ -393,6 +436,12 @@ stdenv.mkDerivation (rec { xattr ]; + # Used by the STAGE0 compiler to build stage1 + depsBuildBuild = [ + buildCC + # stage0 builds terminfo unconditionally, so we always need ncurses + ncurses + ]; # For building runtime libs depsBuildTarget = toolsForTarget; @@ -423,6 +472,35 @@ stdenv.mkDerivation (rec { requiredSystemFeatures = [ "big-parallel" ]; postInstall = '' + settingsFile="$out/lib/${targetPrefix}${passthru.haskellCompilerName}/settings" + + # Make the installed GHC use the host->target tools. + ghc-settings-edit "$settingsFile" \ + "C compiler command" "${toolPath "cc" installCC}" \ + "Haskell CPP command" "${toolPath "cc" installCC}" \ + "C++ compiler command" "${toolPath "c++" installCC}" \ + "ld command" "${toolPath "ld${lib.optionalString useLdGold ".gold"}" installCC}" \ + "Merge objects command" "${toolPath "ld${lib.optionalString useLdGold ".gold"}" installCC}" \ + "ar command" "${toolPath "ar" installCC}" \ + "ranlib command" "${toolPath "ranlib" installCC}" + '' + + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' + ghc-settings-edit "$settingsFile" \ + "otool command" "${toolPath "otool" installCC}" \ + "install_name_tool command" "${toolPath "install_name_tool" installCC}" + '' + + lib.optionalString useLLVM '' + ghc-settings-edit "$settingsFile" \ + "LLVM llc command" "${lib.getBin llvmPackages.llvm}/bin/llc" \ + "LLVM opt command" "${lib.getBin llvmPackages.llvm}/bin/opt" + '' + # FIXME(@sternenseemann): use installCC instead if possible + + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' + ghc-settings-edit "$settingsFile" \ + "LLVM clang command" "${llvmPackages.clang}/bin/${llvmPackages.clang.targetPrefix}clang" + '' + + '' + # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc ''; @@ -448,7 +526,8 @@ stdenv.mkDerivation (rec { guibou ] ++ lib.teams.haskell.members; timeout = 24 * 3600; - inherit (ghc.meta) license platforms; + platforms = lib.platforms.all; + inherit (ghc.meta) license; }; } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { diff --git a/pkgs/development/haskell-modules/non-hackage-packages.nix b/pkgs/development/haskell-modules/non-hackage-packages.nix index bb995435fc600..c5cfbcec0313b 100644 --- a/pkgs/development/haskell-modules/non-hackage-packages.nix +++ b/pkgs/development/haskell-modules/non-hackage-packages.nix @@ -17,6 +17,8 @@ self: super: { # from the latest master instead of the current version on Hackage. cabal2nix-unstable = self.callPackage ./cabal2nix-unstable.nix { }; + ghc-settings-edit = self.callPackage ../tools/haskell/ghc-settings-edit { }; + # https://github.com/channable/vaultenv/issues/1 vaultenv = self.callPackage ../tools/haskell/vaultenv { }; diff --git a/pkgs/development/tools/haskell/ghc-settings-edit/default.nix b/pkgs/development/tools/haskell/ghc-settings-edit/default.nix new file mode 100644 index 0000000000000..f1f08b620588c --- /dev/null +++ b/pkgs/development/tools/haskell/ghc-settings-edit/default.nix @@ -0,0 +1,33 @@ +{ + stdenv, + ghc, + lib, +}: + +stdenv.mkDerivation { + pname = "ghc-settings-edit"; + version = "0.1.0"; + # See the source code for an explanation + src = ./ghc-settings-edit.lhs; + dontUnpack = true; + dontBuild = true; + + nativeBuildInputs = [ ghc ]; + installPhase = '' + runHook preInstall + + mkdir -p "$out/bin" + ${ghc.targetPrefix}ghc --make "$src" -o "$out/bin/ghc-settings-edit" + + runHook postInstall + ''; + + meta = { + license = [ + lib.licenses.mit + lib.licenses.bsd3 + ]; + platforms = lib.platforms.all; + description = "Tool for editing GHC's settings file"; + }; +} diff --git a/pkgs/development/tools/haskell/ghc-settings-edit/ghc-settings-edit.lhs b/pkgs/development/tools/haskell/ghc-settings-edit/ghc-settings-edit.lhs new file mode 100644 index 0000000000000..3b37bafe0d622 --- /dev/null +++ b/pkgs/development/tools/haskell/ghc-settings-edit/ghc-settings-edit.lhs @@ -0,0 +1,109 @@ +ghc-settings-edit is a small tool for changing certain fields in the settings +file that is part of every GHC installation (usually located at +lib/ghc-$version/lib/settings or lib/ghc-$version/settings). This is sometimes +necessary because GHC's build process leaks the tools used at build time into +the final settings file. This is fine, as long as the build and host platform +of the GHC build is the same since it will be possible to execute the tools +used at build time at run time. In case we are cross compiling GHC itself, +the settings file needs to be changed so that the correct tools are used in the +final installation. The GHC build system itself doesn't allow for this due to +its somewhat peculiar bootstrapping mechanism. + +This tool was originally written by sternenseemann and is licensed under the MIT +license (as is nixpkgs) as well as the BSD 3 Clause license since it incorporates +some code from GHC. It is primarily intended for use in nixpkgs, so it should be +considered unstable: No guarantees about the stability of its command line +interface are made at this time. + +> -- SPDX-License-Identifier: MIT AND BSD-3-Clause +> {-# LANGUAGE LambdaCase #-} +> module Main where + +ghc-settings-edit requires no additional dependencies to the ones already +required to bootstrap GHC. This means that it only depends on GHC and core +libraries shipped with the compiler (base and containers). This property should +be preserved going forward as to not needlessly complicate bootstrapping GHC +in nixpkgs. Additionally, a wide range of library versions and thus GHC versions +should be supported (via CPP if necessary). + +> import Control.Monad (foldM) +> import qualified Data.Map.Lazy as Map +> import System.Environment (getArgs, getProgName) +> import Text.Read (readEither) + +Note that the containers dependency is needed to represent the contents of the +settings file. In theory, [(String, String)] (think lookup) would suffice, but +base doesn't provide any facilities for updating such lists. To avoid needlessly +reinventing the wheel here, we depend on an extra core library. + +> type SettingsMap = Map.Map String String + +ghc-settings-edit accepts the following arguments: + +- The path to the settings file which is edited in place. +- For every field in the settings file to be updated, two arguments need to be + passed: the name of the field and its new value. Any number of these pairs + may be provided. If a field is missing from the given settings file, + it won't be added (see also below). + +> usage :: String -> String +> usage name = "Usage: " ++ name ++ " FILE [KEY NEWVAL [KEY2 NEWVAL2 ...]]" + +The arguments and the contents of the settings file are fed into the performEdits +function which implements the main logic of ghc-settings-edit (except IO). + +> performEdits :: [String] -> String -> Either String String +> performEdits editArgs settingsString = do + +First, the settings file is parsed and read into the SettingsMap structure. For +parsing, we can simply rely read, as GHC uses the familiar Read/Show format +(plus some formatting) for storing its settings. This is the main reason +ghc-settings-edit is written in Haskell: We don't need to roll our own parser. + +> settingsMap <- Map.fromList <$> readEither settingsString + +We also need to parse the remaining command line arguments (after the path) +which means splitting them into pairs of arguments describing the individual +edits. We use the chunkList utility function from GHC for this which is vendored +below. Since it doesn't guarantee that all sublists have the exact length given, +we'll have to check the length of the returned “pairs” later. + +> let edits = chunkList 2 editArgs + +Since each edit is a transformation of the SettingsMap, we use a fold to go +through the edits. The Either monad allows us to bail out if one is malformed. +The use of Map.adjust ensures that fields that aren't present in the original +settings file aren't added since the corresponding GHC installation wouldn't +understand them. Note that this is done silently which may be suboptimal: +It could be better to fail. + +> show . Map.toList <$> foldM applyEdit settingsMap edits +> where +> applyEdit :: SettingsMap -> [String] -> Either String SettingsMap +> applyEdit m [key, newValue] = Right $ Map.adjust (const newValue) key m +> applyEdit _ _ = Left "Uneven number of edit arguments provided" + +main just wraps performEdits and takes care of reading from and writing to the +given file. + +> main :: IO () +> main = +> getArgs >>= \case +> (settingsFile:edits) -> do +> orig <- readFile settingsFile +> case performEdits edits orig of +> Right edited -> writeFile settingsFile edited +> Left errorMsg -> error errorMsg +> _ -> do +> name <- getProgName +> error $ usage name + +As mentioned, chunkList is taken from GHC, specifically GHC.Utils.Misc of GHC +verson 9.8.2. We don't depend on the ghc library directly (which would be +possible in theory) since there are no stability guarantees or deprecation +windows for the ghc's public library. + +> -- | Split a list into chunks of /n/ elements +> chunkList :: Int -> [a] -> [[a]] +> chunkList _ [] = [] +> chunkList n xs = as : chunkList n bs where (as,bs) = splitAt n xs diff --git a/pkgs/test/cross/default.nix b/pkgs/test/cross/default.nix index bd233db4cd50f..f07e9c6220de7 100644 --- a/pkgs/test/cross/default.nix +++ b/pkgs/test/cross/default.nix @@ -146,6 +146,8 @@ let pkgs.pkgsCross.mips64el-linux-gnuabi64.stdenv pkgs.pkgsCross.mips64el-linux-gnuabin32.stdenv pkgs.pkgsCross.mingwW64.stdenv + # Uses the expression that is used by the most cross-compil_ed_ GHCs + pkgs.pkgsCross.riscv64.haskell.compiler.native-bignum.ghc948 ] ++ lib.optionals (with pkgs.stdenv.buildPlatform; isx86_64 && isLinux) [ # Musl-to-glibc cross on the same architecture tends to turn up diff --git a/pkgs/top-level/haskell-packages.nix b/pkgs/top-level/haskell-packages.nix index 6193d9d217ae9..2d54063e00746 100644 --- a/pkgs/top-level/haskell-packages.nix +++ b/pkgs/top-level/haskell-packages.nix @@ -1,4 +1,4 @@ -{ buildPackages, pkgsBuildTarget, pkgs, newScope, stdenv }: +{ buildPackages, pkgsBuildBuild, pkgsBuildTarget, pkgs, newScope, stdenv }: let # These are attributes in compiler that support integer-simple. @@ -52,7 +52,8 @@ in { package-list = callPackage ../development/haskell-modules/package-list.nix {}; - compiler = { + # Always get boot compilers from `pkgsBuildBuild` + compiler = let bb = pkgsBuildBuild.haskell; in { ghc865Binary = callPackage ../development/compilers/ghc/8.6.5-binary.nix { # Should be llvmPackages_6 which has been removed from nixpkgs llvmPackages = null; @@ -73,11 +74,11 @@ in { ghc8107 = callPackage ../development/compilers/ghc/8.10.7.nix { bootPkgs = # the oldest ghc with aarch64-darwin support is 8.10.5 - if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then + if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then # to my (@a-m-joseph) knowledge there are no newer official binaries for this platform - packages.ghc865Binary + bb.packages.ghc865Binary else - packages.ghc8107Binary; + bb.packages.ghc8107Binary; inherit (buildPackages.python311Packages) sphinx; # a distutils issue with 3.12 python3 = buildPackages.python311; # so that we don't have two of them # Need to use apple's patched xattr until @@ -91,10 +92,10 @@ in { ghc902 = callPackage ../development/compilers/ghc/9.0.2.nix { bootPkgs = # the oldest ghc with aarch64-darwin support is 8.10.5 - if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc810 + if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc810 else - packages.ghc8107Binary; + bb.packages.ghc8107Binary; inherit (buildPackages.python311Packages) sphinx; # a distutils issue with 3.12 python3 = buildPackages.python311; # so that we don't have two of them inherit (buildPackages.darwin) autoSignDarwinBinariesHook xattr; @@ -104,10 +105,10 @@ in { ghc90 = compiler.ghc902; ghc925 = callPackage ../development/compilers/ghc/9.2.5.nix { bootPkgs = - if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc810 + if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc810 else - packages.ghc8107Binary; + bb.packages.ghc8107Binary; inherit (buildPackages.python311Packages) sphinx; # a distutils issue with 3.12 python3 = buildPackages.python311; # so that we don't have two of them # Need to use apple's patched xattr until @@ -119,10 +120,10 @@ in { }; ghc926 = callPackage ../development/compilers/ghc/9.2.6.nix { bootPkgs = - if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc810 + if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc810 else - packages.ghc8107Binary; + bb.packages.ghc8107Binary; inherit (buildPackages.python311Packages) sphinx; # a distutils issue with 3.12 python3 = buildPackages.python311; # so that we don't have two of them # Need to use apple's patched xattr until @@ -134,10 +135,10 @@ in { }; ghc927 = callPackage ../development/compilers/ghc/9.2.7.nix { bootPkgs = - if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc810 + if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc810 else - packages.ghc8107Binary; + bb.packages.ghc8107Binary; inherit (buildPackages.python311Packages) sphinx; # a distutils issue with 3.12 python3 = buildPackages.python311; # so that we don't have two of them # Need to use apple's patched xattr until @@ -149,10 +150,10 @@ in { }; ghc928 = callPackage ../development/compilers/ghc/9.2.8.nix { bootPkgs = - if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc810 + if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc810 else - packages.ghc8107Binary; + bb.packages.ghc8107Binary; inherit (buildPackages.python311Packages) sphinx; # a distutils issue with 3.12 python3 = buildPackages.python311; # so that we don't have two of them # Need to use apple's patched xattr until @@ -170,14 +171,14 @@ in { # Use 8.10 as a workaround where possible to keep bootstrap path short. # On ARM text won't build with GHC 8.10.* - if stdenv.hostPlatform.isAarch then + if stdenv.buildPlatform.isAarch then # TODO(@sternenseemann): package bindist - packages.ghc902 + bb.packages.ghc902 # No suitable bindists for powerpc64le - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc902 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc902 else - packages.ghc8107Binary; + bb.packages.ghc8107Binary; inherit (buildPackages.python311Packages) sphinx; # a distutils issue with 3.12 python3 = buildPackages.python311; # so that we don't have two of them # Need to use apple's patched xattr until @@ -195,14 +196,14 @@ in { # Use 8.10 as a workaround where possible to keep bootstrap path short. # On ARM text won't build with GHC 8.10.* - if stdenv.hostPlatform.isAarch then + if stdenv.buildPlatform.isAarch then # TODO(@sternenseemann): package bindist - packages.ghc902 + bb.packages.ghc902 # No suitable bindists for powerpc64le - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc902 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc902 else - packages.ghc8107Binary; + bb.packages.ghc8107Binary; inherit (buildPackages.python311Packages) sphinx; # a distutils issue with 3.12 python3 = buildPackages.python311; # so that we don't have two of them # Need to use apple's patched xattr until @@ -220,14 +221,14 @@ in { # Use 8.10 as a workaround where possible to keep bootstrap path short. # On ARM text won't build with GHC 8.10.* - if stdenv.hostPlatform.isAarch then + if stdenv.buildPlatform.isAarch then # TODO(@sternenseemann): package bindist - packages.ghc902 + bb.packages.ghc902 # No suitable bindists for powerpc64le - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc902 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc902 else - packages.ghc8107Binary; + bb.packages.ghc8107Binary; inherit (buildPackages.python3Packages) sphinx; # Need to use apple's patched xattr until # https://github.com/xattr/xattr/issues/44 and @@ -244,14 +245,14 @@ in { # Use 8.10 as a workaround where possible to keep bootstrap path short. # On ARM text won't build with GHC 8.10.* - if stdenv.hostPlatform.isAarch then + if stdenv.buildPlatform.isAarch then # TODO(@sternenseemann): package bindist - packages.ghc902 + bb.packages.ghc902 # No suitable bindists for powerpc64le - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc902 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc902 else - packages.ghc8107Binary; + bb.packages.ghc8107Binary; inherit (buildPackages.python3Packages) sphinx; # Need to use apple's patched xattr until # https://github.com/xattr/xattr/issues/44 and @@ -265,12 +266,12 @@ in { ghc963 = callPackage ../development/compilers/ghc/9.6.3.nix { bootPkgs = # For GHC 9.2 no armv7l bindists are available. - if stdenv.hostPlatform.isAarch32 then - packages.ghc928 - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc928 + if stdenv.buildPlatform.isAarch32 then + bb.packages.ghc928 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc928 else - packages.ghc924Binary; + bb.packages.ghc924Binary; inherit (buildPackages.python3Packages) sphinx; # Need to use apple's patched xattr until # https://github.com/xattr/xattr/issues/44 and @@ -283,12 +284,12 @@ in { ghc964 = callPackage ../development/compilers/ghc/9.6.4.nix { bootPkgs = # For GHC 9.2 no armv7l bindists are available. - if stdenv.hostPlatform.isAarch32 then - packages.ghc928 - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc928 + if stdenv.buildPlatform.isAarch32 then + bb.packages.ghc928 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc928 else - packages.ghc924Binary; + bb.packages.ghc924Binary; inherit (buildPackages.python3Packages) sphinx; # Need to use apple's patched xattr until # https://github.com/xattr/xattr/issues/44 and @@ -301,12 +302,12 @@ in { ghc965 = callPackage ../development/compilers/ghc/9.6.5.nix { bootPkgs = # For GHC 9.2 no armv7l bindists are available. - if stdenv.hostPlatform.isAarch32 then - packages.ghc928 - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc928 + if stdenv.buildPlatform.isAarch32 then + bb.packages.ghc928 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc928 else - packages.ghc924Binary; + bb.packages.ghc924Binary; inherit (buildPackages.python3Packages) sphinx; # Need to use apple's patched xattr until # https://github.com/xattr/xattr/issues/44 and @@ -319,12 +320,12 @@ in { ghc966 = callPackage ../development/compilers/ghc/9.6.6.nix { bootPkgs = # For GHC 9.2 no armv7l bindists are available. - if stdenv.hostPlatform.isAarch32 then - packages.ghc928 - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc928 + if stdenv.buildPlatform.isAarch32 then + bb.packages.ghc928 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc928 else - packages.ghc924Binary; + bb.packages.ghc924Binary; inherit (buildPackages.python3Packages) sphinx; # Need to use apple's patched xattr until # https://github.com/xattr/xattr/issues/44 and @@ -338,12 +339,12 @@ in { ghc981 = callPackage ../development/compilers/ghc/9.8.1.nix { bootPkgs = # For GHC 9.6 no armv7l bindists are available. - if stdenv.hostPlatform.isAarch32 then - packages.ghc963 - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc963 + if stdenv.buildPlatform.isAarch32 then + bb.packages.ghc963 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc963 else - packages.ghc963Binary; + bb.packages.ghc963Binary; inherit (buildPackages.python3Packages) sphinx; # Need to use apple's patched xattr until # https://github.com/xattr/xattr/issues/44 and @@ -356,12 +357,12 @@ in { ghc982 = callPackage ../development/compilers/ghc/9.8.2.nix { bootPkgs = # For GHC 9.6 no armv7l bindists are available. - if stdenv.hostPlatform.isAarch32 then - packages.ghc963 - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc963 + if stdenv.buildPlatform.isAarch32 then + bb.packages.ghc963 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc963 else - packages.ghc963Binary; + bb.packages.ghc963Binary; inherit (buildPackages.python3Packages) sphinx; # Need to use apple's patched xattr until # https://github.com/xattr/xattr/issues/44 and @@ -375,19 +376,19 @@ in { ghc9101 = callPackage ../development/compilers/ghc/9.10.1.nix { bootPkgs = # For GHC 9.6 no armv7l bindists are available. - if stdenv.hostPlatform.isAarch32 then - packages.ghc963 - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc963 - else if stdenv.hostPlatform.isDarwin then + if stdenv.buildPlatform.isAarch32 then + bb.packages.ghc963 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc963 + else if stdenv.buildPlatform.isDarwin then # it seems like the GHC 9.6.* bindists are built with a different # toolchain than we are using (which I'm guessing from the fact # that 9.6.4 bindists pass linker flags our ld doesn't support). # With both 9.6.3 and 9.6.4 binary it is impossible to link against # the clock package (probably a hsc2hs problem). - packages.ghc963 + bb.packages.ghc963 else - packages.ghc963Binary; + bb.packages.ghc963Binary; inherit (buildPackages.python3Packages) sphinx; # Need to use apple's patched xattr until # https://github.com/xattr/xattr/issues/44 and @@ -401,12 +402,12 @@ in { ghcHEAD = callPackage ../development/compilers/ghc/head.nix { bootPkgs = # For GHC 9.6 no armv7l bindists are available. - if stdenv.hostPlatform.isAarch32 then - packages.ghc963 - else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then - packages.ghc963 + if stdenv.buildPlatform.isAarch32 then + bb.packages.ghc963 + else if stdenv.buildPlatform.isPower64 && stdenv.buildPlatform.isLittleEndian then + bb.packages.ghc963 else - packages.ghc963Binary; + bb.packages.ghc963Binary; inherit (buildPackages.python3Packages) sphinx; # Need to use apple's patched xattr until # https://github.com/xattr/xattr/issues/44 and @@ -419,7 +420,7 @@ in { ghcjs = compiler.ghcjs810; ghcjs810 = callPackage ../development/compilers/ghcjs/8.10 { - bootPkgs = packages.ghc810; + bootPkgs = bb.packages.ghc810; ghcjsSrcJson = ../development/compilers/ghcjs/8.10/git.json; stage0 = ../development/compilers/ghcjs/8.10/stage0.nix; };