From 6c4ce0d913550fbd1c0cbb95a69c40aa632910f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Bon=C3=A9?= Date: Fri, 13 Mar 2026 13:00:56 +0100 Subject: [PATCH] Enable libdevice in llvm-intel This requires a wrapper stub to set up the flags, since libdevice is built using the built compiler. Reviewed-by: Rodrigo Arias Mallo --- pkgs/llvm-intel/default.nix | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/pkgs/llvm-intel/default.nix b/pkgs/llvm-intel/default.nix index 1537d81d..b6841c6d 100644 --- a/pkgs/llvm-intel/default.nix +++ b/pkgs/llvm-intel/default.nix @@ -3,6 +3,7 @@ lib, ninja, autoAddDriverRunpath, + wrapCC, cmake, emhash, fetchFromGitHub, @@ -23,6 +24,8 @@ }: let + + llvmMajorVersion = "21"; version = "6.2.1"; src = fetchFromGitHub { owner = "intel"; @@ -140,6 +143,7 @@ stdenv.mkDerivation { "xptifw" "compiler-rt" "sycl-jit" + "libdevice" ] ++ lib.optionals enableCuda [ "libclc" @@ -187,6 +191,43 @@ stdenv.mkDerivation { (lib.cmakeBool "LIBCLC_NATIVECPU_HOST_TARGET" false) ]; + postPatch = + + let + # See the postPatch phase for details on why this is used + ccWrapperStub = wrapCC ( + stdenv.mkDerivation { + name = "ccWrapperStub"; + dontUnpack = true; + installPhase = '' + mkdir -p $out/bin + cat > $out/bin/clang-${llvmMajorVersion} <<'EOF' + #!/bin/sh + exec "$NIX_BUILD_TOP/source/build/bin/clang-${llvmMajorVersion}" "$@" + EOF + chmod +x $out/bin/clang-${llvmMajorVersion} + cp $out/bin/clang-${llvmMajorVersion} $out/bin/clang + cp $out/bin/clang-${llvmMajorVersion} $out/bin/clang++ + ''; + passthru.isClang = true; + } + ); + in + '' + # Parts of libdevice are built using the freshly-built compiler. + # As it tries to link to system libraries, we need to wrap it with the + # usual nix cc-wrapper. + # Since the compiler to be wrapped is not available at this point, + # we use a stub that points to where it will be later on + # in `$NIX_BUILD_TOP/source/build/bin/clang-${llvmMajorVersion}` + substituteInPlace libdevice/cmake/modules/SYCLLibdevice.cmake \ + --replace-fail "\''${clang_exe}" "${ccWrapperStub}/bin/clang++" + ''; + + passthru = { + inherit llvmMajorVersion; + }; + meta = { homepage = "https://github.com/intel/llvm"; description = "Intel staging area for llvm.org contribution";