2021-01-21 17:00:13 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2019-07-27 18:33:55 +01:00
|
|
|
, fetchFromGitHub
|
|
|
|
, fetchpatch
|
|
|
|
, cmake
|
|
|
|
, git
|
|
|
|
|
|
|
|
, llvmPackages_8
|
|
|
|
, spirv-llvm-translator
|
|
|
|
|
|
|
|
, buildWithPatches ? true
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
llvmPkgs = llvmPackages_8 // {
|
|
|
|
inherit spirv-llvm-translator;
|
|
|
|
};
|
|
|
|
|
2021-01-21 17:00:13 +00:00
|
|
|
inherit (lib) getVersion;
|
2019-07-27 18:33:55 +01:00
|
|
|
|
|
|
|
addPatches = component: pkg:
|
2021-01-21 17:00:13 +00:00
|
|
|
with builtins; with lib;
|
2019-07-27 18:33:55 +01:00
|
|
|
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 {
|
|
|
|
|
llvmPackages: Multuple outputs for everythting
Also begin to start work on cross compilation, though that will have to
be finished later.
The patches are based on the first version of
https://reviews.llvm.org/D99484. It's very annoying to do the
back-porting but the review has uncovered nothing super major so I'm
fine sticking with what I've got.
Beyond making the outputs work, I also strove to re-sync the packages,
as they have been drifting pointlessly apart for some time.
----
Other misc notes, highly incomplete
- lvm-config-native and llvm-config are put in `dev` because they are
tools just for build time.
- Clang no longer has an lld dep. That was introduced in
db29857eb391ed002046090851a44c452b80bdbd, but if clang needs help
finding lld when it is used we should just pass it flags / put in the
resource dir. Providing it at build time increases critical path
length for no good reason.
----
A note on `nativeCC`:
`stdenv` takes tools from the previous stage, so:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.stdenv.cc`: `(?0, ?1, x)`
while:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.targetPackages`: `(x, x, ?2)`
3. `pkgsBuildBuild.targetPackages.stdenv.cc`: `(?1, x, x)`
2020-10-15 09:23:57 +01:00
|
|
|
libclang = addPatches "clang" llvmPkgs.libclang;
|
|
|
|
|
|
|
|
clang-unwrapped = libclang.out;
|
2019-07-27 18:33:55 +01:00
|
|
|
|
|
|
|
clang = llvmPkgs.clang.override {
|
|
|
|
cc = clang-unwrapped;
|
|
|
|
};
|
|
|
|
|
|
|
|
patchesOut = stdenv.mkDerivation rec {
|
|
|
|
pname = "opencl-clang-patches";
|
2021-01-21 17:00:13 +00:00
|
|
|
inherit (library) version src patches;
|
2019-07-27 18:33:55 +01:00
|
|
|
installPhase = ''
|
|
|
|
[ -d patches ] && cp -r patches/ $out || mkdir $out
|
|
|
|
mkdir -p $out/clang $out/spirv
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
spirv-llvm-translator = addPatches "spirv" llvmPkgs.spirv-llvm-translator;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-01-21 17:00:13 +00:00
|
|
|
library = let
|
2019-07-27 18:33:55 +01:00
|
|
|
inherit (llvmPkgs) llvm;
|
llvmPackages: Multuple outputs for everythting
Also begin to start work on cross compilation, though that will have to
be finished later.
The patches are based on the first version of
https://reviews.llvm.org/D99484. It's very annoying to do the
back-porting but the review has uncovered nothing super major so I'm
fine sticking with what I've got.
Beyond making the outputs work, I also strove to re-sync the packages,
as they have been drifting pointlessly apart for some time.
----
Other misc notes, highly incomplete
- lvm-config-native and llvm-config are put in `dev` because they are
tools just for build time.
- Clang no longer has an lld dep. That was introduced in
db29857eb391ed002046090851a44c452b80bdbd, but if clang needs help
finding lld when it is used we should just pass it flags / put in the
resource dir. Providing it at build time increases critical path
length for no good reason.
----
A note on `nativeCC`:
`stdenv` takes tools from the previous stage, so:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.stdenv.cc`: `(?0, ?1, x)`
while:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.targetPackages`: `(x, x, ?2)`
3. `pkgsBuildBuild.targetPackages.stdenv.cc`: `(?1, x, x)`
2020-10-15 09:23:57 +01:00
|
|
|
inherit (if buildWithPatches then passthru else llvmPkgs) libclang spirv-llvm-translator;
|
2019-07-27 18:33:55 +01:00
|
|
|
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
|
|
|
|
];
|
|
|
|
|
2021-05-18 10:10:39 +01:00
|
|
|
# Uses linker flags that are not supported on Darwin.
|
|
|
|
postPatch = lib.optionalString stdenv.isDarwin ''
|
|
|
|
sed -i -e '/SET_LINUX_EXPORTS_FILE/d' CMakeLists.txt
|
|
|
|
substituteInPlace CMakeLists.txt \
|
|
|
|
--replace '-Wl,--no-undefined' ""
|
|
|
|
'';
|
|
|
|
|
2021-05-09 01:26:37 +01:00
|
|
|
nativeBuildInputs = [ cmake git llvm.dev ];
|
2019-07-27 18:33:55 +01:00
|
|
|
|
llvmPackages: Multuple outputs for everythting
Also begin to start work on cross compilation, though that will have to
be finished later.
The patches are based on the first version of
https://reviews.llvm.org/D99484. It's very annoying to do the
back-porting but the review has uncovered nothing super major so I'm
fine sticking with what I've got.
Beyond making the outputs work, I also strove to re-sync the packages,
as they have been drifting pointlessly apart for some time.
----
Other misc notes, highly incomplete
- lvm-config-native and llvm-config are put in `dev` because they are
tools just for build time.
- Clang no longer has an lld dep. That was introduced in
db29857eb391ed002046090851a44c452b80bdbd, but if clang needs help
finding lld when it is used we should just pass it flags / put in the
resource dir. Providing it at build time increases critical path
length for no good reason.
----
A note on `nativeCC`:
`stdenv` takes tools from the previous stage, so:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.stdenv.cc`: `(?0, ?1, x)`
while:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.targetPackages`: `(x, x, ?2)`
3. `pkgsBuildBuild.targetPackages.stdenv.cc`: `(?1, x, x)`
2020-10-15 09:23:57 +01:00
|
|
|
buildInputs = [ libclang llvm spirv-llvm-translator ];
|
2019-07-27 18:33:55 +01:00
|
|
|
|
|
|
|
cmakeFlags = [
|
|
|
|
"-DPREFERRED_LLVM_VERSION=${getVersion llvm}"
|
llvmPackages: Multuple outputs for everythting
Also begin to start work on cross compilation, though that will have to
be finished later.
The patches are based on the first version of
https://reviews.llvm.org/D99484. It's very annoying to do the
back-porting but the review has uncovered nothing super major so I'm
fine sticking with what I've got.
Beyond making the outputs work, I also strove to re-sync the packages,
as they have been drifting pointlessly apart for some time.
----
Other misc notes, highly incomplete
- lvm-config-native and llvm-config are put in `dev` because they are
tools just for build time.
- Clang no longer has an lld dep. That was introduced in
db29857eb391ed002046090851a44c452b80bdbd, but if clang needs help
finding lld when it is used we should just pass it flags / put in the
resource dir. Providing it at build time increases critical path
length for no good reason.
----
A note on `nativeCC`:
`stdenv` takes tools from the previous stage, so:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.stdenv.cc`: `(?0, ?1, x)`
while:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.targetPackages`: `(x, x, ?2)`
3. `pkgsBuildBuild.targetPackages.stdenv.cc`: `(?1, x, x)`
2020-10-15 09:23:57 +01:00
|
|
|
"-DOPENCL_HEADERS_DIR=${libclang.lib}/lib/clang/${getVersion libclang}/include/"
|
2019-07-27 18:33:55 +01:00
|
|
|
|
|
|
|
"-DLLVMSPIRV_INCLUDED_IN_LLVM=OFF"
|
|
|
|
"-DSPIRV_TRANSLATOR_DIR=${spirv-llvm-translator}"
|
|
|
|
];
|
|
|
|
|
2021-01-21 17:00:13 +00:00
|
|
|
meta = with lib; {
|
2020-04-01 02:11:51 +01:00
|
|
|
homepage = "https://github.com/intel/opencl-clang/";
|
2019-07-27 18:33:55 +01:00
|
|
|
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
|
2021-01-21 17:00:13 +00:00
|
|
|
library
|