Unverified Commit 6bb12aca authored by Tristan Ross's avatar Tristan Ross
Browse files

llvmPackages_19.libclc: fix formatting

parent a80f2c1e
Loading
Loading
Loading
Loading
+58 −29
Original line number Diff line number Diff line
{ lib, stdenv, version, runCommand, monorepoSrc, llvm, buildPackages, buildLlvmTools, ninja, cmake, python3, release_version, getVersionFile }:
{
  lib,
  stdenv,
  version,
  runCommand,
  monorepoSrc,
  llvm,
  buildPackages,
  buildLlvmTools,
  ninja,
  cmake,
  python3,
  release_version,
  getVersionFile,
}:
let
  spirv-llvm-translator = buildPackages.spirv-llvm-translator.override { inherit (buildLlvmTools) llvm; };
  spirv-llvm-translator = buildPackages.spirv-llvm-translator.override {
    inherit (buildLlvmTools) llvm;
  };
in
stdenv.mkDerivation rec {
  pname = "libclc";
@@ -14,18 +30,24 @@ stdenv.mkDerivation rec {

  sourceRoot = "${src.name}/${pname}";

  outputs = [ "out" "dev" ];
  outputs = [
    "out"
    "dev"
  ];

  patches = [
    ./libclc/libclc-gnu-install-dirs.patch
  ] # LLVM 19 changes how host tools are looked up.
  patches =
    [ ./libclc/libclc-gnu-install-dirs.patch ]
    # LLVM 19 changes how host tools are looked up.
    # Need to remove NO_DEFAULT_PATH and the PATHS arguments for find_program
    # so CMake can actually find the tools in nativeBuildInputs.
    # https://github.com/llvm/llvm-project/pull/105969
    ++ lib.optional (lib.versionAtLeast release_version "19") (getVersionFile "libclc/use-default-paths.patch");
    ++ lib.optional (lib.versionAtLeast release_version "19") (
      getVersionFile "libclc/use-default-paths.patch"
    );

  # cmake expects all required binaries to be in the same place, so it will not be able to find clang without the patch
  postPatch = lib.optionalString (lib.versionOlder release_version "19") ''
  postPatch =
    lib.optionalString (lib.versionOlder release_version "19") ''
      substituteInPlace CMakeLists.txt \
        --replace 'find_program( LLVM_CLANG clang PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
                  'find_program( LLVM_CLANG clang PATHS "${buildLlvmTools.clang.cc}/bin" NO_DEFAULT_PATH )' \
@@ -37,12 +59,19 @@ stdenv.mkDerivation rec {
                  'find_program( LLVM_OPT opt PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \
        --replace 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
                  'find_program( LLVM_SPIRV llvm-spirv PATHS "${spirv-llvm-translator}/bin" NO_DEFAULT_PATH )'
  '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
    ''
    + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
      substituteInPlace CMakeLists.txt \
        --replace 'COMMAND prepare_builtins' 'COMMAND ${buildLlvmTools.libclc.dev}/bin/prepare_builtins'
    '';

  nativeBuildInputs = [ cmake ninja python3 ] ++ lib.optional (lib.versionAtLeast release_version "19") [
  nativeBuildInputs =
    [
      cmake
      ninja
      python3
    ]
    ++ lib.optional (lib.versionAtLeast release_version "19") [
      buildLlvmTools.clang.cc
      buildLlvmTools.llvm
      spirv-llvm-translator