summaryrefslogtreecommitdiff
path: root/pkgs/by-name/in/intel-graphics-compiler/package.nix
blob: 7f43e9edbb907a68c62483fd804c2b55b137ed93 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
{
  lib,
  stdenv,
  fetchFromGitHub,
  bash,
  cmake,
  runCommandLocal,
  bison,
  flex,
  intel-compute-runtime,
  llvmPackages_15,
  opencl-clang,
  python3,
  spirv-tools,
  spirv-headers,
  spirv-llvm-translator,

  buildWithPatches ? true,
}:

let
  vc_intrinsics_src = fetchFromGitHub {
    owner = "intel";
    repo = "vc-intrinsics";
    rev = "v0.23.1";
    hash = "sha256-7coQegLcgIKiqnonZmgrKlw6FCB3ltSh6oMMvdopeQc=";
  };

  inherit (llvmPackages_15) lld llvm;
  inherit (if buildWithPatches then opencl-clang else llvmPackages_15) clang libclang;
  spirv-llvm-translator' = spirv-llvm-translator.override { inherit llvm; };

  # 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 ${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/
  '';
in
stdenv.mkDerivation rec {
  pname = "intel-graphics-compiler";
  version = "2.14.1";

  src = fetchFromGitHub {
    owner = "intel";
    repo = "intel-graphics-compiler";
    tag = "v${version}";
    hash = "sha256-PBUKLvP9h7AhYbaxjAC749sQqYJLAjNpWfME8t84D0k=";
  };

  postPatch = ''
    substituteInPlace IGC/AdaptorOCL/igc-opencl.pc.in \
      --replace-fail '/@CMAKE_INSTALL_INCLUDEDIR@' "/include" \
      --replace-fail '/@CMAKE_INSTALL_LIBDIR@' "/lib"

    chmod +x IGC/Scripts/igc_create_linker_script.sh
    patchShebangs --build IGC/Scripts/igc_create_linker_script.sh
  '';

  nativeBuildInputs = [
    bash
    bison
    cmake
    flex
    (python3.withPackages (
      ps: with ps; [
        mako
        pyyaml
      ]
    ))
  ];

  buildInputs = [
    lld
    llvm
    spirv-headers
    spirv-llvm-translator'
    spirv-tools
  ];

  strictDeps = true;

  # testing is done via intel-compute-runtime
  doCheck = false;

  cmakeFlags = [
    "-DVC_INTRINSICS_SRC=${vc_intrinsics_src}"
    "-DCCLANG_BUILD_PREBUILDS=ON"
    "-DCCLANG_BUILD_PREBUILDS_DIR=${prebuilds}"
    "-DIGC_OPTION__SPIRV_TOOLS_MODE=Prebuilds"
    "-DIGC_OPTION__VC_INTRINSICS_MODE=Source"
    "-Wno-dev"
  ];

  passthru.tests = {
    inherit intel-compute-runtime;
  };

  meta = with lib; {
    description = "LLVM-based compiler for OpenCL targeting Intel Gen graphics hardware";
    homepage = "https://github.com/intel/intel-graphics-compiler";
    changelog = "https://github.com/intel/intel-graphics-compiler/releases/tag/${src.rev}";
    license = licenses.mit;
    platforms = platforms.linux;
    maintainers = with maintainers; [ SuperSandro2000 ];
  };
}