From bc6ffb69f03c16a739711086daa23c01e80232fb Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Tue, 4 Feb 2025 16:45:19 +0100 Subject: [PATCH 1/2] haskell.compiler: unify logic determining whether NCG is available This change only consolidates the logic for the source built GHCs which have used the same logic (at least as long as you'd only use the respective supported version ranges of the expressions as inputs). --- pkgs/development/compilers/ghc/8.10.7.nix | 9 ++++++--- pkgs/development/compilers/ghc/common-hadrian.nix | 6 +----- pkgs/development/compilers/ghc/common-have-ncg.nix | 14 ++++++++++++++ .../compilers/ghc/common-make-native-bignum.nix | 9 ++------- 4 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 pkgs/development/compilers/ghc/common-have-ncg.nix diff --git a/pkgs/development/compilers/ghc/8.10.7.nix b/pkgs/development/compilers/ghc/8.10.7.nix index c0d9e2b371f76..ed14b48743b01 100644 --- a/pkgs/development/compilers/ghc/8.10.7.nix +++ b/pkgs/development/compilers/ghc/8.10.7.nix @@ -1,3 +1,7 @@ +let + version = "8.10.7"; +in + { lib, stdenv, @@ -32,8 +36,7 @@ libffi ? null, libffi_3_3 ? null, - useLLVM ? - !(stdenv.targetPlatform.isx86 || stdenv.targetPlatform.isPower || stdenv.targetPlatform.isSparc), + useLLVM ? !(import ./common-have-ncg.nix { inherit lib stdenv version; }), # LLVM is conceptually a run-time-only dependency, but for # non-x86, we need LLVM to bootstrap later stages, so it becomes a # build-time dependency too. @@ -271,7 +274,7 @@ in stdenv.mkDerivation ( rec { - version = "8.10.7"; + inherit version; pname = "${targetPrefix}ghc${variantSuffix}"; src = fetchurl { diff --git a/pkgs/development/compilers/ghc/common-hadrian.nix b/pkgs/development/compilers/ghc/common-hadrian.nix index 3a6ea450f37ed..7974cba0824c9 100644 --- a/pkgs/development/compilers/ghc/common-hadrian.nix +++ b/pkgs/development/compilers/ghc/common-hadrian.nix @@ -39,11 +39,7 @@ , # GHC can be built with system libffi or a bundled one. libffi ? null -, useLLVM ? !(stdenv.targetPlatform.isx86 - || stdenv.targetPlatform.isPower - || stdenv.targetPlatform.isAarch64 - || stdenv.targetPlatform.isGhcjs - || (lib.versionAtLeast version "9.12" && stdenv.targetPlatform.isRiscV64)) +, useLLVM ? !(import ./common-have-ncg.nix { inherit lib stdenv version; }) , # LLVM is conceptually a run-time-only dependency, but for # non-x86, we need LLVM to bootstrap later stages, so it becomes a # build-time dependency too. diff --git a/pkgs/development/compilers/ghc/common-have-ncg.nix b/pkgs/development/compilers/ghc/common-have-ncg.nix new file mode 100644 index 0000000000000..1b92a0700ac2e --- /dev/null +++ b/pkgs/development/compilers/ghc/common-have-ncg.nix @@ -0,0 +1,14 @@ +# Determines whether the Native Code Generation (NCG) backend of the given +# GHC `version` is supported for compiling to `stdenv.targetPlatform`. +{ + version, + stdenv, + lib, +}: + +stdenv.targetPlatform.isx86 +|| stdenv.targetPlatform.isPower +|| (lib.versionOlder version "9.4" && stdenv.targetPlatform.isSparc) +|| (lib.versionAtLeast version "9.2" && stdenv.targetPlatform.isAarch64) +|| (lib.versionAtLeast version "9.6" && stdenv.targetPlatform.isGhcjs) +|| (lib.versionAtLeast version "9.12" && stdenv.targetPlatform.isRiscV64) diff --git a/pkgs/development/compilers/ghc/common-make-native-bignum.nix b/pkgs/development/compilers/ghc/common-make-native-bignum.nix index 412e8d7d4671c..b204a1c703638 100644 --- a/pkgs/development/compilers/ghc/common-make-native-bignum.nix +++ b/pkgs/development/compilers/ghc/common-make-native-bignum.nix @@ -34,13 +34,8 @@ # GHC can be built with system libffi or a bundled one. libffi ? null, - useLLVM ? - !( - stdenv.targetPlatform.isx86 - || stdenv.targetPlatform.isPower - || (lib.versionOlder version "9.4" && stdenv.targetPlatform.isSparc) - || (lib.versionAtLeast version "9.2" && stdenv.targetPlatform.isAarch64) - ), + useLLVM ? !(import ./common-have-ncg.nix { inherit lib stdenv version; }), + # LLVM is conceptually a run-time-only dependency, but for # non-x86, we need LLVM to bootstrap later stages, so it becomes a # build-time dependency too. From d0d7d525be063af2a34f1897cb36fc6aed828a6e Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Tue, 4 Feb 2025 16:48:54 +0100 Subject: [PATCH 2/2] haskell.compiler.ghc*Binary: use common NCG/useLLVM logic See bc6ffb69f03c16a739711086daa23c01e80232fb for context. --- pkgs/development/compilers/ghc/8.10.7-binary.nix | 2 +- pkgs/development/compilers/ghc/9.2.4-binary.nix | 7 +------ pkgs/development/compilers/ghc/9.6.3-binary.nix | 7 +------ 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/pkgs/development/compilers/ghc/8.10.7-binary.nix b/pkgs/development/compilers/ghc/8.10.7-binary.nix index c4a20e7af4bcf..6137777f27470 100644 --- a/pkgs/development/compilers/ghc/8.10.7-binary.nix +++ b/pkgs/development/compilers/ghc/8.10.7-binary.nix @@ -204,7 +204,7 @@ let ghcBinDists.${distSetName}.${stdenv.hostPlatform.system} or (throw "cannot bootstrap GHC on this platform ('${stdenv.hostPlatform.system}' with libc '${distSetName}')"); - useLLVM = !stdenv.targetPlatform.isx86; + useLLVM = !(import ./common-have-ncg.nix { inherit lib stdenv version; }); libPath = lib.makeLibraryPath ( # Add arch-specific libraries. diff --git a/pkgs/development/compilers/ghc/9.2.4-binary.nix b/pkgs/development/compilers/ghc/9.2.4-binary.nix index c5a704e8ad869..e5e21a91b611a 100644 --- a/pkgs/development/compilers/ghc/9.2.4-binary.nix +++ b/pkgs/development/compilers/ghc/9.2.4-binary.nix @@ -193,12 +193,7 @@ let ) binDistUsed.archSpecificLibraries )).nixPackage; - # GHC has other native backends (like PowerPC), but here only the ones - # we ship bindists for matter. - useLLVM = - !( - stdenv.targetPlatform.isx86 || (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin) - ); + useLLVM = !(import ./common-have-ncg.nix { inherit lib stdenv version; }); libPath = lib.makeLibraryPath ( # Add arch-specific libraries. diff --git a/pkgs/development/compilers/ghc/9.6.3-binary.nix b/pkgs/development/compilers/ghc/9.6.3-binary.nix index ef4828814854a..e392fdd02f5bf 100644 --- a/pkgs/development/compilers/ghc/9.6.3-binary.nix +++ b/pkgs/development/compilers/ghc/9.6.3-binary.nix @@ -192,12 +192,7 @@ let ) binDistUsed.archSpecificLibraries )).nixPackage; - # GHC has other native backends (like PowerPC), but here only the ones - # we ship bindists for matter. - useLLVM = - !( - stdenv.targetPlatform.isx86 || (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin) - ); + useLLVM = !(import ./common-have-ncg.nix { inherit lib stdenv version; }); libPath = lib.makeLibraryPath ( # Add arch-specific libraries.