Unverified Commit a80f2c1e authored by Tristan Ross's avatar Tristan Ross
Browse files

llvmPackages_19.libclc: fix building

parent db45f307
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
From e8b910246d0c7c3d9fff994f71c6f8a48ec09a50 Mon Sep 17 00:00:00 2001
From: Tristan Ross <tristan.ross@midstall.com>
Date: Sat, 24 Aug 2024 19:56:24 -0700
Subject: [PATCH] [libclc] use default paths with find_program when possible

---
 libclc/CMakeLists.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 02bb859ae8590b..6bcd8ae52a5794 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -55,7 +55,7 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DI
   # Import required tools
   if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} )
     foreach( tool IN ITEMS clang llvm-as llvm-link opt )
-      find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
+      find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} )
       set( ${tool}_exe ${LLVM_TOOL_${tool}} )
       set( ${tool}_target )
     endforeach()
@@ -104,7 +104,7 @@ foreach( tool IN ITEMS clang opt llvm-as llvm-link )
 endforeach()
 
 # llvm-spirv is an optional dependency, used to build spirv-* targets.
-find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )
+find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} )
 
 if( LLVM_SPIRV )
   add_executable( libclc::llvm-spirv IMPORTED GLOBAL )
+6 −0
Original line number Diff line number Diff line
@@ -279,6 +279,12 @@ let
                  path = ../14;
                }
              ];
              "libclc/use-default-paths.patch" = [
                {
                  after = "19";
                  path = ../19;
                }
              ];
            };

            constraints = patches."${p}" or null;
+16 −6
Original line number Diff line number Diff line
{ lib, stdenv, version, runCommand, monorepoSrc, llvm, buildPackages, buildLlvmTools, ninja, cmake, python3 }:

{ 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; };
in
stdenv.mkDerivation rec {
  pname = "libclc";
  inherit version;
@@ -16,10 +18,14 @@ stdenv.mkDerivation rec {

  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");

  # cmake expects all required binaries to be in the same place, so it will not be able to find clang without the patch
  postPatch = ''
  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 )' \
@@ -30,13 +36,17 @@ stdenv.mkDerivation rec {
      --replace 'find_program( LLVM_OPT opt PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \
                '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 "${buildPackages.spirv-llvm-translator.override { inherit (buildLlvmTools) llvm; }}/bin" NO_DEFAULT_PATH )'
                'find_program( LLVM_SPIRV llvm-spirv PATHS "${spirv-llvm-translator}/bin" NO_DEFAULT_PATH )'
  '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
    substituteInPlace CMakeLists.txt \
      --replace 'COMMAND prepare_builtins' 'COMMAND ${buildLlvmTools.libclc.dev}/bin/prepare_builtins'
  '';

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