{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.
This commit is contained in:
sternenseemann
2025-09-11 15:45:26 +02:00
parent a9e965e0f6
commit a2b6624139
2 changed files with 14 additions and 3 deletions
@@ -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
];
});
}
@@ -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