From bc6ffb69f03c16a739711086daa23c01e80232fb Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Tue, 4 Feb 2025 16:45:19 +0100 Subject: [PATCH] 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 c0d9e2b371f7..ed14b48743b0 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 3a6ea450f37e..7974cba0824c 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 000000000000..1b92a0700ac2 --- /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 412e8d7d4671..b204a1c70363 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.