From 65962d6ce86bda4941cd1eef8de9b6e4c23b4b39 Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Sun, 23 Jul 2023 09:30:35 +0100 Subject: [PATCH 01/16] haskell.compiler.ghc*: set stage 0 tools This is easy in comparison since these tools won't end up in GHC's settings nor need to be available at runtime, so we can use the *_FOR_BUILD environment variables. It is important to add buildCC to depsBuildBuild to engage the stdenv/wrapper script machinery properly. Co-authored-by: sternenseemann --- pkgs/development/compilers/ghc/8.10.7.nix | 11 ++++++++++- pkgs/development/compilers/ghc/common-hadrian.nix | 10 ++++++++++ .../compilers/ghc/common-make-native-bignum.nix | 12 +++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index a6694e2e99c9c..9bcf8eb1fecea 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 @@ -134,6 +134,7 @@ let pkgsBuildTarget.targetPackages.stdenv.cc ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; + buildCC = buildPackages.stdenv.cc; targetCC = builtins.head toolsForTarget; # toolPath calculates the absolute path to the name tool associated with a @@ -299,6 +300,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 @@ -372,6 +377,10 @@ stdenv.mkDerivation (rec { sphinx ]; + # Used by the STAGE0 compiler to build stage1 + depsBuildBuild = [ + buildCC + ]; # For building runtime libs depsBuildTarget = toolsForTarget; diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index b6d4d7236fe6b..aefaf5b70aaf9 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 @@ -265,6 +266,7 @@ let else pkgsBuildTarget.targetPackages.stdenv.cc) ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; + buildCC = buildPackages.stdenv.cc; targetCC = builtins.head toolsForTarget; # toolPath calculates the absolute path to the name tool associated with a @@ -346,6 +348,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}" @@ -484,6 +490,10 @@ stdenv.mkDerivation ({ # For building runtime libs depsBuildTarget = toolsForTarget; + # Used by the STAGE0 compiler to build stage1 + depsBuildBuild = [ + buildCC + ]; buildInputs = [ perl bash ] ++ (libDeps hostPlatform); diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index 2b23cd75a0ed7..3788efeda8ba4 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 @@ -134,6 +134,7 @@ let pkgsBuildTarget.targetPackages.stdenv.cc ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; + buildCC = buildPackages.stdenv.cc; targetCC = builtins.head toolsForTarget; # toolPath calculates the absolute path to the name tool associated with a @@ -305,6 +306,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") '' @@ -393,6 +399,10 @@ stdenv.mkDerivation (rec { xattr ]; + # Used by the STAGE0 compiler to build stage1 + depsBuildBuild = [ + buildCC + ]; # For building runtime libs depsBuildTarget = toolsForTarget; From 875cc633b678b9df8cc77317febae3de74365bb0 Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Sun, 23 Jul 2023 09:50:55 +0100 Subject: [PATCH 02/16] haskell.compiler.ghc*: correctly account for ncurses in cross 1. Explicitly set WITH_TERMINFO. We usually match GHC's behavior well, but it is better to tie the Nix option to make explicitly. Unfortunately, the same is very complicated to achieve with hadrian (iirc). 2. Disable enableTerminfo if we are cross-compiling. This matches the behavior of GHC's build system, so we'll have to match it now. It also reduces the ncurses-related headache a bit. 3. Stop passing --with-curses* flags. Unfortunately, GHC does not account for the fact that different platforms need different ncurses libraries. This is somewhat migitated by the fact that ncurses is only ever needed for the build platform if we are cross compiling, but I seem to remember it leaking into the final GHC somehow. A more reliable alternative is relying on the cc/ld wrapper scripts, as they'll always pull out the correct ncurses out of the environment when GHC's build system passes -lcurses. 4. Unconditionally add ncurses to depsBuildBuild. Stage0 unconditionally builds terminfo (maybe the stage1 compiler needs it?), so we need to make sure that ncurses for the build platform is available. Co-authored-by: sternenseemann --- pkgs/development/compilers/ghc/8.10.7.nix | 10 ++++++++-- pkgs/development/compilers/ghc/common-hadrian.nix | 11 +++++++++-- .../compilers/ghc/common-make-native-bignum.nix | 10 ++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index 9bcf8eb1fecea..873925417c16c 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -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. @@ -86,6 +89,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` @@ -341,7 +346,6 @@ stdenv.mkDerivation (rec { # `--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" @@ -380,6 +384,8 @@ stdenv.mkDerivation (rec { # 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; diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index aefaf5b70aaf9..78e0e2dd167e0 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -66,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 || @@ -439,7 +445,6 @@ 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" @@ -493,6 +498,8 @@ stdenv.mkDerivation ({ # 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); diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index 3788efeda8ba4..3d5d9d6329a50 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -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. @@ -88,6 +91,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` @@ -359,7 +364,6 @@ stdenv.mkDerivation (rec { # `--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" @@ -402,6 +406,8 @@ stdenv.mkDerivation (rec { # 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; From 9d3e4d287a19716711265148874b7bf89d598f9c Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Sun, 23 Jul 2023 09:43:41 +0100 Subject: [PATCH 03/16] =?UTF-8?q?haskell.compiler.ghc*:=20fall=20back=20to?= =?UTF-8?q?=20host=20libs=20for=20=E2=80=9Ccross=20native=E2=80=9D=20ghc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The goal of this commit is basically to eliminate the use of targetPackages for finding libraries. Instead, we introduce a `targetLibs` set that can be used instead. The libraries in there philosophically come from targetPackages since they are used by the core libs and will be linked against user code. However, when cross compiling GHC it's always a native compiler, so we can and have to use pkgsHostTarget (targetPackages would be empty). This is explained more in the acccompanying comment. An alternative to this approach is not to pass in the libraries explicitly via `--with-*` flags and rely on cc-wrapper and splicing to pick the correct library. This works well for ncurses and probably merits testing for other libraries as well since it's very simple. It would need to be verified, however, that configure doesn't discover the “wrong” library and leaks it somewhere. Co-authored-by: sternenseemann --- pkgs/development/compilers/ghc/8.10.7.nix | 39 ++++++++++++++++--- .../compilers/ghc/common-hadrian.nix | 35 ++++++++++++++--- .../ghc/common-make-native-bignum.nix | 30 ++++++++++++-- 3 files changed, 89 insertions(+), 15 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index 873925417c16c..8874f4221e814 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -72,7 +72,6 @@ assert !enableIntegerSimple -> gmp != null; assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; let - libffi_name = if stdenv.isDarwin && stdenv.isAarch64 then "libffi" else "libffi_3_3"; inherit (stdenv) buildPlatform hostPlatform targetPlatform; inherit (bootPkgs) ghc; @@ -191,6 +190,36 @@ let (lib.optionalString enableIntegerSimple "-integer-simple") ]; + 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}; + }; + in # C compiler, bintools and LLVM are used at build time, but will also leak into @@ -348,11 +377,11 @@ stdenv.mkDerivation (rec { "--datadir=$doc/share/doc/ghc" ] ++ 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" diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index 78e0e2dd167e0..11d6059a5616d 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -324,6 +324,29 @@ let (lib.optionalString enableNativeBignum "-native-bignum") ]; + # 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; + }; + in # C compiler, bintools and LLVM are used at build time, but will also leak into @@ -447,11 +470,11 @@ stdenv.mkDerivation ({ "--datadir=$doc/share/doc/ghc" ] ++ 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" @@ -465,8 +488,8 @@ 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: diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index 3d5d9d6329a50..812bb8fa95ab3 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -191,6 +191,28 @@ let (lib.optionalString enableNativeBignum "-native-bignum") ]; + # 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; + }; + in # C compiler, bintools and LLVM are used at build time, but will also leak into @@ -366,11 +388,11 @@ stdenv.mkDerivation (rec { "--datadir=$doc/share/doc/ghc" ] ++ 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" From 814f924438b7acf0c72ad8258c6d17d3c29022d6 Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Sun, 23 Jul 2023 09:56:56 +0100 Subject: [PATCH 04/16] haskell.compiler.ghc*: don't configure --host --- pkgs/development/compilers/ghc/8.10.7.nix | 7 +++++-- .../compilers/ghc/common-make-native-bignum.nix | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index 8874f4221e814..8601a1361f1f6 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -368,9 +368,12 @@ 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 = [ diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index 812bb8fa95ab3..4992be47cf7bb 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -379,9 +379,12 @@ 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 = [ From dd1c4a7849e54df9713fdfbe29793093dba6b92d Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Sun, 14 Apr 2024 15:05:58 +0200 Subject: [PATCH 05/16] ghc-settings-edit: init at 0.1.0 --- .../haskell-modules/non-hackage-packages.nix | 2 + .../haskell/ghc-settings-edit/default.nix | 33 ++++++ .../ghc-settings-edit/ghc-settings-edit.lhs | 109 ++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 pkgs/development/tools/haskell/ghc-settings-edit/default.nix create mode 100644 pkgs/development/tools/haskell/ghc-settings-edit/ghc-settings-edit.lhs 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 From 0512d98573c8762b37aa2ce731774ed31f119e92 Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Sun, 23 Jul 2023 10:01:19 +0100 Subject: [PATCH 06/16] haskell.compiler.ghc*: use host->target CC and tools in settings GHC's build system assumes that the C compiler, tools etc. discovered during configure can also be used at runtime. This means that the CC, LD, AR etc. variables given at runtime are used to populate the settings file which GHC uses to lookup the tools it needs. The implicit assumption of this mechanism is that the build and runtime environment of GHC are similar enough and PATH is used to find the tools. I. e. if we set CC=clang, we wouldn't need to worry about this as much. We, however, pass absolute paths which is useful since it allows GHC to work outside of stdenv (as long as e. g. no FFI is involved). Even so, until now, we didn't really have any problems stemming from this, as we used pkgsBuildTarget to get everything we need. The compiler we'd want to execute would in principle need to come from pkgsHostTarget. 1. For native compilers, all package sets are the same since build == host == target. 2. For cross compilers build == host, so pkgsBuildTarget is practically the same as pkgsHostTarget. When cross-compiling a native compiler, build != host, so we need to actually ensure that GHC uses different tools at runtime compared to bootstrapping. There is currently no intended way to achieve this, so we use a custom tool to edit the settings file. An alternative would be to patch the build system, but this would be difficult to maintain. We could go down this route if there's interest from upstream to provide a proper way to specify the runtime tools. Co-authored-by: sternenseemann --- pkgs/development/compilers/ghc/8.10.7.nix | 21 +++++++++++------ .../compilers/ghc/common-hadrian.nix | 23 +++++++++++++++---- .../ghc/common-make-native-bignum.nix | 21 +++++++++++------ 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index 8601a1361f1f6..59f02b7ab57c7 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -140,6 +140,7 @@ let 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 @@ -222,13 +223,6 @@ 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}"; @@ -407,6 +401,7 @@ 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 [ @@ -449,6 +444,18 @@ 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}" + # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc ''; diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index 11d6059a5616d..4487eac6c378c 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -274,6 +274,7 @@ let 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 @@ -347,6 +348,9 @@ let libffi; }; + # Our Cabal compiler name + haskellCompilerName = "ghc-${version}"; + in # C compiler, bintools and LLVM are used at build time, but will also leak into @@ -510,6 +514,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 [ @@ -593,19 +599,28 @@ 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}" + # 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; diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index 4992be47cf7bb..4067bc084fecc 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -141,6 +141,7 @@ let 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 @@ -215,13 +216,6 @@ 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 { pname = "${targetPrefix}ghc${variantSuffix}"; inherit version; @@ -418,6 +412,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 [ @@ -464,6 +459,18 @@ 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}" + # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc ''; From 9ac88eecdb6f37cee77d8bdb7c22ab22609869f5 Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Sun, 23 Jul 2023 10:10:04 +0100 Subject: [PATCH 07/16] haskell.compiler.ghc*: don't cross-compile haddock --- pkgs/development/compilers/ghc/8.10.7.nix | 4 ++-- pkgs/development/compilers/ghc/common-make-native-bignum.nix | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index 59f02b7ab57c7..f0514b71e9cd6 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -58,7 +58,7 @@ , 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/ @@ -69,7 +69,7 @@ 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; let inherit (stdenv) buildPlatform hostPlatform targetPlatform; diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index 4067bc084fecc..4dff963c85510 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -61,7 +61,7 @@ , 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/ @@ -72,7 +72,7 @@ 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; let inherit (stdenv) buildPlatform hostPlatform targetPlatform; From c1dbadc9b6886dc6a9084deb5616839395bbe034 Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Sun, 23 Jul 2023 10:12:19 +0100 Subject: [PATCH 08/16] haskell.compiler.ghc*: add enableUnregisterised --- pkgs/development/compilers/ghc/8.10.7.nix | 8 ++++++++ pkgs/development/compilers/ghc/common-hadrian.nix | 8 ++++++++ .../compilers/ghc/common-make-native-bignum.nix | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index f0514b71e9cd6..e223ef157df90 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -63,6 +63,12 @@ , # 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; @@ -390,6 +396,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. diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index 4487eac6c378c..f534ad3afd3e9 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -229,6 +229,12 @@ , # 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; @@ -500,6 +506,8 @@ stdenv.mkDerivation ({ # 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. diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index 4dff963c85510..e8cec98aaa364 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -66,6 +66,14 @@ , # 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; @@ -401,6 +409,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. From 55b6cf6f2943677498762eb95e6cc2cb5abaa920 Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Sun, 23 Jul 2023 10:13:50 +0100 Subject: [PATCH 09/16] haskell.compiler.ghc*: assert cross is possible --- pkgs/development/compilers/ghc/8.10.7.nix | 3 +++ pkgs/development/compilers/ghc/common-hadrian.nix | 13 ++++++------- .../compilers/ghc/common-make-native-bignum.nix | 3 +++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index e223ef157df90..7597e40bfe9ef 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -77,6 +77,9 @@ assert !enableIntegerSimple -> gmp != null; # see note [HADDOCK_DOCS]. 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; diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index f534ad3afd3e9..a38706554dccb 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -239,6 +239,12 @@ 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; @@ -359,13 +365,6 @@ 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 !targetPlatform.isGhcjs -> targetCC == pkgsHostTarget.targetPackages.stdenv.cc; -assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; -assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; - stdenv.mkDerivation ({ pname = "${targetPrefix}ghc${variantSuffix}"; inherit version; diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index e8cec98aaa364..dc8ddfd0d9c0d 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -82,6 +82,9 @@ assert !enableNativeBignum -> gmp != null; # see note [HADDOCK_DOCS]. 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; From 30883fd615f93b98f26c637e35c020b373e196c8 Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Sun, 23 Jul 2023 10:16:26 +0100 Subject: [PATCH 10/16] haskell.compiler.ghc*: allow all platforms Propagating the supported platforms of the boot compiler doesn't make much sense when unregistered cross-compilation is possible. --- pkgs/development/compilers/ghc/8.10.7.nix | 3 ++- pkgs/development/compilers/ghc/common-hadrian.nix | 3 ++- pkgs/development/compilers/ghc/common-make-native-bignum.nix | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index 7597e40bfe9ef..294ec4d8c3c84 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -492,7 +492,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 a38706554dccb..efdf6865bea03 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -643,7 +643,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 dc8ddfd0d9c0d..b3f04952de77c 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -509,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 { From 9351f3eee4744235d9ddcb4dd1096803c9589c3d Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Sun, 23 Jul 2023 10:18:58 +0100 Subject: [PATCH 11/16] haskell.compiler.ghc*: use GHC from pkgsBuildBuild --- pkgs/top-level/haskell-packages.nix | 167 ++++++++++++++-------------- 1 file changed, 84 insertions(+), 83 deletions(-) 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; }; From 4f6dd13aea9fecbd23fa07759485278bb708e505 Mon Sep 17 00:00:00 2001 From: Alex Tunstall Date: Fri, 29 Mar 2024 10:05:19 +0000 Subject: [PATCH 12/16] tests.cross.sanity: Add GHC to catch regressions This is to ensure that Haskell users on platforms that lack official bindists still have a convenient means of getting GHC running natively. In my admittedly somewhat limited testing on RISC-V, GHC 8.10.7 is able to bootstrap native builds for 9.2.8 and 9.4.5. GHC 9.2.8 and 9.4.5 are unable to bootstrap themselves and 9.6.2 when cross-compiled. If you're looking at this commit to see whether you can safely upgrade the compiler used here to remove 8.10, please try cross-compiling 9.0 or later and then booting a native GHC with it. --- pkgs/test/cross/default.nix | 2 ++ 1 file changed, 2 insertions(+) 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 From e0c1b68988b9cdc85ae00146dd8d8099fd4f2a28 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 5 Sep 2024 18:51:27 +0200 Subject: [PATCH 13/16] haskell.compiler.ghc96: fix incorrect unlit path for cross compilers Hadrian started installing unlit with a targetPrefix (if applicable) which wasn't the case with make before. Unfortunately, the logic to generate the settings file wasn't updated, so GHC 9.6.* cross compilers expect to find an unlit binary without a target prefix. Upstream issue: https://gitlab.haskell.org/ghc/ghc/-/issues/23317 --- pkgs/development/compilers/ghc/common-hadrian.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index efdf6865bea03..a2fddfc53764f 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -617,6 +617,15 @@ stdenv.mkDerivation ({ "Merge objects command" "${toolPath "ld${lib.optionalString useLdGold ".gold"}" installCC}" \ "ar command" "${toolPath "ar" installCC}" \ "ranlib command" "${toolPath "ranlib" installCC}" + '' + # 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 From a7d8b9302e56d3a96996974c653caa4e99e8e3e5 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 5 Sep 2024 18:56:06 +0200 Subject: [PATCH 14/16] haskell.compiler.ghc9{6,8,10}: update comment about stage selection The build platform doesn't matter for checking which stage is our final stage! Stage2 means host and target are sufficiently similar, Stage1 means host and target may differ. --- pkgs/development/compilers/ghc/common-hadrian.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index a2fddfc53764f..644481bb3081b 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -124,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 From 6e07628b76df251a4ee594ba6f1680db7f79a485 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 5 Sep 2024 23:41:28 +0200 Subject: [PATCH 15/16] haskell.compiler.*: set cctools tools in settings if applicable --- pkgs/development/compilers/ghc/8.10.7.nix | 7 +++++++ pkgs/development/compilers/ghc/common-hadrian.nix | 5 +++++ .../compilers/ghc/common-make-native-bignum.nix | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index 294ec4d8c3c84..3fe17f620d074 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -466,6 +466,13 @@ stdenv.mkDerivation (rec { "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}" + '' + + '' # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index 644481bb3081b..7ccd781544848 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -617,6 +617,11 @@ stdenv.mkDerivation ({ "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}" + '' # 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 diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index b3f04952de77c..d121baf21c24c 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -483,6 +483,13 @@ stdenv.mkDerivation (rec { "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}" + '' + + '' # Install the bash completion file. install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc From df169027cf74f93e90173f555c07a5534df91908 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Thu, 5 Sep 2024 23:44:11 +0200 Subject: [PATCH 16/16] haskell.compiler.*: set correct runtime LLVM tools in settings Note that the clang command should be adapted in the future as done for CLANG in #338782. --- pkgs/development/compilers/ghc/8.10.7.nix | 10 ++++++++++ pkgs/development/compilers/ghc/common-hadrian.nix | 10 ++++++++++ .../compilers/ghc/common-make-native-bignum.nix | 10 ++++++++++ 3 files changed, 30 insertions(+) diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index 3fe17f620d074..bf1c27f2a812e 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -472,6 +472,16 @@ stdenv.mkDerivation (rec { "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. diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index 7ccd781544848..f9b24f291aaa0 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -622,6 +622,16 @@ stdenv.mkDerivation ({ "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 diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index d121baf21c24c..03d7697e2de39 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -489,6 +489,16 @@ stdenv.mkDerivation (rec { "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.