diff --git a/pkgs/llvm-intel/default.nix b/pkgs/llvm-intel/default.nix index d8c3cd94..627360f5 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"; @@ -188,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";