nixpkgs/pkgs/development/compilers/intel-graphics-compiler/default.nix
2022-12-05 23:08:23 +01:00

97 lines
2.9 KiB
Nix

{ lib
, stdenv
, fetchFromGitHub
, cmake
, runCommandLocal
, bison
, flex
, llvmPackages_11
, opencl-clang
, python3
, spirv-tools
, spirv-headers
, spirv-llvm-translator
, buildWithPatches ? true
}:
let
vc_intrinsics_src = fetchFromGitHub {
owner = "intel";
repo = "vc-intrinsics";
rev = "v0.7.1";
sha256 = "sha256-bpi4hLpov1CbFy4jr9Eytc5O4ismYw0J+KgXyZtQYks=";
};
llvmPkgs = llvmPackages_11 // {
spirv-llvm-translator = spirv-llvm-translator.override { llvm = llvm; };
} // lib.optionalAttrs buildWithPatches opencl-clang;
inherit (llvmPackages_11) lld llvm;
inherit (llvmPkgs) clang libclang spirv-llvm-translator;
in
stdenv.mkDerivation rec {
pname = "intel-graphics-compiler";
version = "1.0.12504.5";
src = fetchFromGitHub {
owner = "intel";
repo = "intel-graphics-compiler";
rev = "igc-${version}";
sha256 = "sha256-Ok+cXMTBABrHHM4Vc2yzlou48YHoQnaB3We8mGZhSwI=";
};
nativeBuildInputs = [ cmake bison flex python3 ];
buildInputs = [ spirv-headers spirv-tools spirv-llvm-translator llvm lld ];
strictDeps = true;
# testing is done via intel-compute-runtime
doCheck = false;
postPatch = ''
substituteInPlace external/SPIRV-Tools/CMakeLists.txt \
--replace '$'''{SPIRV-Tools_DIR}../../..' \
'${spirv-tools}' \
--replace 'SPIRV-Headers_INCLUDE_DIR "/usr/include"' \
'SPIRV-Headers_INCLUDE_DIR "${spirv-headers}/include"' \
--replace 'set_target_properties(SPIRV-Tools' \
'set_target_properties(SPIRV-Tools-shared' \
--replace 'IGC_BUILD__PROJ__SPIRV-Tools SPIRV-Tools' \
'IGC_BUILD__PROJ__SPIRV-Tools SPIRV-Tools-shared'
substituteInPlace IGC/AdaptorOCL/igc-opencl.pc.in \
--replace '/@CMAKE_INSTALL_INCLUDEDIR@' "/include" \
--replace '/@CMAKE_INSTALL_LIBDIR@' "/lib"
'';
# Handholding the braindead build script
# cmake requires an absolute path
prebuilds = runCommandLocal "igc-cclang-prebuilds" { } ''
mkdir $out
ln -s ${clang}/bin/clang $out/
ln -s clang $out/clang-${lib.versions.major (lib.getVersion clang)}
ln -s ${opencl-clang}/lib/* $out/
ln -s ${lib.getLib libclang}/lib/clang/${lib.getVersion clang}/include/opencl-c.h $out/
ln -s ${lib.getLib libclang}/lib/clang/${lib.getVersion clang}/include/opencl-c-base.h $out/
'';
cmakeFlags = [
"-Wno-dev"
"-DVC_INTRINSICS_SRC=${vc_intrinsics_src}"
"-DIGC_OPTION__SPIRV_TOOLS_MODE=Prebuilds"
"-DCCLANG_BUILD_PREBUILDS=ON"
"-DCCLANG_BUILD_PREBUILDS_DIR=${prebuilds}"
"-DIGC_PREFERRED_LLVM_VERSION=${lib.getVersion llvm}"
];
meta = with lib; {
homepage = "https://github.com/intel/intel-graphics-compiler";
description = "LLVM-based compiler for OpenCL targeting Intel Gen graphics hardware";
license = licenses.mit;
platforms = platforms.linux;
maintainers = with maintainers; [ SuperSandro2000 ];
};
}