Commit a2b66241 authored by sternenseemann's avatar sternenseemann
Browse files

{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.
parent a9e965e0
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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
      ];
  });
}
+6 −2
Original line number Diff line number Diff line
@@ -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