2021-01-21 17:00:13 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2019-07-27 17:33:55 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, fetchpatch
|
|
|
|
, cmake
|
|
|
|
, git
|
2021-10-23 20:24:13 +00:00
|
|
|
, llvmPackages_11
|
2019-07-27 17:33:55 +00:00
|
|
|
, spirv-llvm-translator
|
|
|
|
, buildWithPatches ? true
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2021-10-23 20:24:13 +00:00
|
|
|
llvmPkgs = llvmPackages_11 // {
|
2019-07-27 17:33:55 +00:00
|
|
|
inherit spirv-llvm-translator;
|
|
|
|
};
|
|
|
|
|
2022-11-28 04:22:45 +00:00
|
|
|
addPatches = component: pkg: pkg.overrideAttrs (oldAttrs: {
|
|
|
|
postPatch = oldAttrs.postPatch or "" + ''
|
|
|
|
for p in ${passthru.patchesOut}/${component}/*; do
|
|
|
|
patch -p1 -i "$p"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
});
|
2019-07-27 17:33:55 +00:00
|
|
|
|
|
|
|
passthru = rec {
|
2022-11-28 04:22:45 +00:00
|
|
|
spirv-llvm-translator = llvmPkgs.spirv-llvm-translator.override { llvm = llvmPackages_11.llvm; };
|
2021-10-23 20:24:13 +00:00
|
|
|
llvm = addPatches "llvm" 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 08:23:57 +00:00
|
|
|
libclang = addPatches "clang" llvmPkgs.libclang;
|
|
|
|
|
|
|
|
clang-unwrapped = libclang.out;
|
2019-07-27 17:33:55 +00:00
|
|
|
clang = llvmPkgs.clang.override {
|
|
|
|
cc = clang-unwrapped;
|
|
|
|
};
|
|
|
|
|
2022-11-28 04:22:45 +00:00
|
|
|
patchesOut = stdenv.mkDerivation {
|
2019-07-27 17:33:55 +00:00
|
|
|
pname = "opencl-clang-patches";
|
2021-01-21 17:00:13 +00:00
|
|
|
inherit (library) version src patches;
|
2021-10-23 20:24:13 +00:00
|
|
|
# Clang patches assume the root is the llvm root dir
|
|
|
|
# but clang root in nixpkgs is the clang sub-directory
|
|
|
|
postPatch = ''
|
|
|
|
for filename in patches/clang/*.patch; do
|
|
|
|
substituteInPlace "$filename" \
|
|
|
|
--replace "a/clang/" "a/" \
|
|
|
|
--replace "b/clang/" "b/"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
2019-07-27 17:33:55 +00:00
|
|
|
installPhase = ''
|
|
|
|
[ -d patches ] && cp -r patches/ $out || mkdir $out
|
2021-10-23 20:24:13 +00:00
|
|
|
mkdir -p $out/clang $out/llvm
|
2019-07-27 17:33:55 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-01-21 17:00:13 +00:00
|
|
|
library = let
|
2022-11-28 04:22:45 +00:00
|
|
|
inherit (llvmPackages_11) 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 08:23:57 +00:00
|
|
|
inherit (if buildWithPatches then passthru else llvmPkgs) libclang spirv-llvm-translator;
|
2019-07-27 17:33:55 +00:00
|
|
|
in
|
2022-11-28 04:22:45 +00:00
|
|
|
stdenv.mkDerivation {
|
2019-07-27 17:33:55 +00:00
|
|
|
pname = "opencl-clang";
|
2022-05-05 12:43:39 +00:00
|
|
|
version = "unstable-2022-03-16";
|
2019-07-27 17:33:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "intel";
|
|
|
|
repo = "opencl-clang";
|
2022-05-05 12:43:39 +00:00
|
|
|
rev = "bbdd1587f577397a105c900be114b56755d1f7dc";
|
|
|
|
sha256 = "sha256-qEZoQ6h4XAvSnJ7/gLXBb1qrzeYa6Jp6nij9VFo8MwQ=";
|
2019-07-27 17:33:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
patches = [
|
2022-11-28 04:22:45 +00:00
|
|
|
# Build script tries to find Clang OpenCL headers under ${llvm}
|
|
|
|
# Work around it by specifying that directory manually.
|
2019-07-27 17:33:55 +00:00
|
|
|
./opencl-headers-dir.patch
|
|
|
|
];
|
|
|
|
|
2021-05-18 09:10:39 +00: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 00:26:37 +00:00
|
|
|
nativeBuildInputs = [ cmake git llvm.dev ];
|
2019-07-27 17:33:55 +00: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 08:23:57 +00:00
|
|
|
buildInputs = [ libclang llvm spirv-llvm-translator ];
|
2019-07-27 17:33:55 +00:00
|
|
|
|
|
|
|
cmakeFlags = [
|
2022-11-28 04:22:45 +00:00
|
|
|
"-DPREFERRED_LLVM_VERSION=${lib.getVersion llvm}"
|
|
|
|
"-DOPENCL_HEADERS_DIR=${libclang.lib}/lib/clang/${lib.getVersion libclang}/include/"
|
2019-07-27 17:33:55 +00:00
|
|
|
|
|
|
|
"-DLLVMSPIRV_INCLUDED_IN_LLVM=OFF"
|
|
|
|
"-DSPIRV_TRANSLATOR_DIR=${spirv-llvm-translator}"
|
|
|
|
];
|
|
|
|
|
2022-11-28 04:22:45 +00:00
|
|
|
inherit passthru;
|
|
|
|
|
2021-01-21 17:00:13 +00:00
|
|
|
meta = with lib; {
|
2020-04-01 01:11:51 +00:00
|
|
|
homepage = "https://github.com/intel/opencl-clang/";
|
2019-07-27 17:33:55 +00: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;
|
2022-11-28 04:22:45 +00:00
|
|
|
maintainers = with maintainers; [ SuperSandro2000 ];
|
2019-07-27 17:33:55 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
2021-01-21 17:00:13 +00:00
|
|
|
library
|