1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, runCommandLocal
6, bison
7, flex
8, intel-compute-runtime
9, llvmPackages_14
10, opencl-clang
11, python3
12, spirv-tools
13, spirv-headers
14, spirv-llvm-translator
15
16, buildWithPatches ? true
17}:
18
19let
20 vc_intrinsics_src = fetchFromGitHub {
21 owner = "intel";
22 repo = "vc-intrinsics";
23 rev = "v0.18.0";
24 hash = "sha256-F2GR3TDUUiygEhdQN+PsMT/CIYBATMQX5wkvwrziS2E=";
25 };
26
27 inherit (llvmPackages_14) lld llvm;
28 inherit (if buildWithPatches then opencl-clang else llvmPackages_14) clang libclang;
29 spirv-llvm-translator' = spirv-llvm-translator.override { inherit llvm; };
30in
31
32stdenv.mkDerivation rec {
33 pname = "intel-graphics-compiler";
34 version = "1.0.17193.4";
35
36 src = fetchFromGitHub {
37 owner = "intel";
38 repo = "intel-graphics-compiler";
39 rev = "igc-${version}";
40 hash = "sha256-OOKj3kfl+0/dgeICFtbiOVE0nsYYvI4v97BLjcExAmc=";
41 };
42
43 nativeBuildInputs = [ bison cmake flex (python3.withPackages (ps : with ps; [ mako ])) ];
44
45 buildInputs = [ lld llvm spirv-headers spirv-llvm-translator' spirv-tools ];
46
47 strictDeps = true;
48
49 # testing is done via intel-compute-runtime
50 doCheck = false;
51
52 postPatch = ''
53 substituteInPlace IGC/AdaptorOCL/igc-opencl.pc.in \
54 --replace '/@CMAKE_INSTALL_INCLUDEDIR@' "/include" \
55 --replace '/@CMAKE_INSTALL_LIBDIR@' "/lib"
56 '';
57
58 # Handholding the braindead build script
59 # cmake requires an absolute path
60 prebuilds = runCommandLocal "igc-cclang-prebuilds" { } ''
61 mkdir $out
62 ln -s ${clang}/bin/clang $out/
63 ln -s ${opencl-clang}/lib/* $out/
64 ln -s ${lib.getLib libclang}/lib/clang/${lib.getVersion clang}/include/opencl-c.h $out/
65 ln -s ${lib.getLib libclang}/lib/clang/${lib.getVersion clang}/include/opencl-c-base.h $out/
66 '';
67
68 cmakeFlags = [
69 "-DVC_INTRINSICS_SRC=${vc_intrinsics_src}"
70 "-DCCLANG_BUILD_PREBUILDS=ON"
71 "-DCCLANG_BUILD_PREBUILDS_DIR=${prebuilds}"
72 "-DIGC_OPTION__SPIRV_TOOLS_MODE=Prebuilds"
73 "-DIGC_OPTION__VC_INTRINSICS_MODE=Source"
74 "-Wno-dev"
75 ];
76
77 passthru.tests = {
78 inherit intel-compute-runtime;
79 };
80
81 meta = with lib; {
82 description = "LLVM-based compiler for OpenCL targeting Intel Gen graphics hardware";
83 homepage = "https://github.com/intel/intel-graphics-compiler";
84 changelog = "https://github.com/intel/intel-graphics-compiler/releases/tag/${src.rev}";
85 license = licenses.mit;
86 platforms = platforms.linux;
87 maintainers = with maintainers; [ SuperSandro2000 ];
88 };
89}