From a2b66241392827e69ce1bee92a0836ed3b3e36a1 Mon Sep 17 00:00:00 2001 From: sternenseemann Date: Tue, 9 Sep 2025 01:36:40 +0200 Subject: [PATCH] {forceLlvmCodegenBackend,ghcWithPackages}: update clang -fllvm logic - The LLVM backend always needs an LLVM specific assembler, i.e. clang that ideally matches the version of LLVM actually used for codegen. - The LLVM backend on Darwin requires some version of clang to be available. In light of LLVMAS, using a matching version seems to be best though this does risk messing with clang used for compiling C in the derivation. This mess can be avoided by compiling GHC with useLLVM = true which sets absolute paths in GHC's settings file. Due to closure size constraints, we can't really do that if NCG is available. --- pkgs/development/haskell-modules/make-package-set.nix | 9 ++++++++- .../haskell-modules/with-packages-wrapper.nix | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pkgs/development/haskell-modules/make-package-set.nix b/pkgs/development/haskell-modules/make-package-set.nix index d53c092ed022..320b331fc25d 100644 --- a/pkgs/development/haskell-modules/make-package-set.nix +++ b/pkgs/development/haskell-modules/make-package-set.nix @@ -734,6 +734,13 @@ package-set { inherit pkgs lib callPackage; } self */ forceLlvmCodegenBackend = overrideCabal (drv: { configureFlags = drv.configureFlags or [ ] ++ [ "--ghc-option=-fllvm" ]; - buildTools = drv.buildTools or [ ] ++ [ self.ghc.llvmPackages.llvm ]; + buildTools = + drv.buildTools or [ ] + ++ [ self.ghc.llvmPackages.llvm ] + # GHC >= 9.10 needs LLVM specific assembler, i.e. clang + # On Darwin clang is always required + ++ lib.optionals (lib.versionAtLeast self.ghc.version "9.10" || stdenv.hostPlatform.isDarwin) [ + self.ghc.llvmPackages.clang + ]; }); } diff --git a/pkgs/development/haskell-modules/with-packages-wrapper.nix b/pkgs/development/haskell-modules/with-packages-wrapper.nix index 0df9ec093ef7..20b9a0803d3e 100644 --- a/pkgs/development/haskell-modules/with-packages-wrapper.nix +++ b/pkgs/development/haskell-modules/with-packages-wrapper.nix @@ -68,10 +68,14 @@ let ) ); hasLibraries = lib.any (x: x.isHaskellLibrary) paths; - # CLang is needed on Darwin for -fllvm to work: + # Clang is needed on Darwin for -fllvm to work. + # GHC >= 9.10 needs an LLVM specific assembler which we use clang for. # https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm llvm = lib.makeBinPath ( - [ ghc.llvmPackages.llvm ] ++ lib.optional stdenv.targetPlatform.isDarwin ghc.llvmPackages.clang + [ ghc.llvmPackages.llvm ] + ++ lib.optionals (lib.versionAtLeast ghc.version "9.10" || stdenv.targetPlatform.isDarwin) [ + ghc.llvmPackages.clang + ] ); in