blob: c40fb9c1203a0907a6b6f65740d83cfb729ddcce (
plain) (
blame)
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
|
{ lib
, stdenv
, fetchFromGitHub
, fetchpatch
, cmake
, git
, llvmPackages_8
, spirv-llvm-translator
, buildWithPatches ? true
}:
let
llvmPkgs = llvmPackages_8 // {
inherit spirv-llvm-translator;
};
inherit (lib) getVersion;
addPatches = component: pkg:
with builtins; with lib;
let path = "${passthru.patchesOut}/${component}";
in pkg.overrideAttrs (super: {
postPatch = (if super ? postPatch then super.postPatch + "\n" else "") + ''
for p in ${path}/*
do
patch -p1 -i "$p"
done
'';
});
passthru = rec {
libclang = addPatches "clang" llvmPkgs.libclang;
clang-unwrapped = libclang.out;
clang = llvmPkgs.clang.override {
cc = clang-unwrapped;
};
patchesOut = stdenv.mkDerivation rec {
pname = "opencl-clang-patches";
inherit (library) version src patches;
installPhase = ''
[ -d patches ] && cp -r patches/ $out || mkdir $out
mkdir -p $out/clang $out/spirv
'';
};
spirv-llvm-translator = addPatches "spirv" llvmPkgs.spirv-llvm-translator;
};
library = let
inherit (llvmPkgs) llvm;
inherit (if buildWithPatches then passthru else llvmPkgs) libclang spirv-llvm-translator;
in
stdenv.mkDerivation rec {
pname = "opencl-clang";
version = "unstable-2019-08-16";
inherit passthru;
src = fetchFromGitHub {
owner = "intel";
repo = "opencl-clang";
rev = "94af090661d7c953c516c97a25ed053c744a0737";
sha256 = "05cg89m62nqjqm705h7gpdz4jd4hiczg8944dcjsvaybrqv3hcm5";
};
patches = [
# Build script tries to find Clang OpenCL headers under ${llvm}
# Work around it by specifying that directory manually.
./opencl-headers-dir.patch
];
nativeBuildInputs = [ cmake git llvm.dev ];
buildInputs = [ libclang llvm spirv-llvm-translator ];
cmakeFlags = [
"-DPREFERRED_LLVM_VERSION=${getVersion llvm}"
"-DOPENCL_HEADERS_DIR=${libclang.lib}/lib/clang/${getVersion libclang}/include/"
"-DLLVMSPIRV_INCLUDED_IN_LLVM=OFF"
"-DSPIRV_TRANSLATOR_DIR=${spirv-llvm-translator}"
];
meta = with lib; {
homepage = "https://github.com/intel/opencl-clang/";
description = "A clang wrapper library with an OpenCL-oriented API and the ability to compile OpenCL C kernels to SPIR-V modules";
license = licenses.ncsa;
platforms = platforms.all;
maintainers = with maintainers; [ gloaming ];
};
};
in
library
|