2021-01-22 11:25:31 +00:00
|
|
|
{ lib, stdenv
|
2019-07-27 11:48:07 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, cmake
|
2021-05-08 23:08:50 +00:00
|
|
|
, pkg-config
|
2019-07-27 11:48:07 +00:00
|
|
|
, lit
|
2022-10-22 14:43:23 +00:00
|
|
|
, llvm
|
2022-05-05 12:42:44 +00:00
|
|
|
, spirv-headers
|
|
|
|
, spirv-tools
|
2019-07-27 11:48:07 +00:00
|
|
|
}:
|
|
|
|
|
2022-10-22 14:43:23 +00:00
|
|
|
let
|
|
|
|
llvmMajor = lib.versions.major llvm.version;
|
2022-12-12 10:42:41 +00:00
|
|
|
isROCm = lib.hasPrefix "rocm" llvm.pname;
|
2022-10-22 14:43:23 +00:00
|
|
|
|
2022-12-12 10:42:41 +00:00
|
|
|
# ROCm will always be at the latest version
|
2022-10-22 14:43:23 +00:00
|
|
|
branch =
|
2022-12-12 10:42:41 +00:00
|
|
|
if llvmMajor == "15" || isROCm then rec {
|
2022-10-22 14:46:23 +00:00
|
|
|
version = "15.0.0";
|
|
|
|
rev = "v${version}";
|
2022-12-12 10:42:41 +00:00
|
|
|
hash = "sha256-OsDohXRxovtEXaWiRGp8gJ0dXmoALyO+ZimeSO8aPVI=";
|
2022-10-22 14:46:23 +00:00
|
|
|
} else if llvmMajor == "14" then rec{
|
|
|
|
version = "14.0.0";
|
|
|
|
rev = "v${version}";
|
|
|
|
hash = "sha256-BhNAApgZ/w/92XjpoDY6ZEIhSTwgJ4D3/EfNvPmNM2o=";
|
|
|
|
} else if llvmMajor == "11" then {
|
2022-10-22 14:43:23 +00:00
|
|
|
version = "unstable-2022-05-04";
|
2022-12-05 22:00:14 +00:00
|
|
|
rev = "4ef524240833abfeee1c5b9fff6b1bd53f4806b3"; # 267 commits ahead of v11.0.0
|
|
|
|
hash = "sha256-NoIoa20+2sH41rEnr8lsMhtfesrtdPINiXtUnxYVm8s=";
|
2022-10-22 14:43:23 +00:00
|
|
|
} else throw "Incompatible LLVM version.";
|
|
|
|
in
|
2022-11-28 04:21:17 +00:00
|
|
|
stdenv.mkDerivation {
|
2019-07-27 11:48:07 +00:00
|
|
|
pname = "SPIRV-LLVM-Translator";
|
2022-10-22 14:43:23 +00:00
|
|
|
inherit (branch) version;
|
2019-07-27 11:48:07 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "KhronosGroup";
|
|
|
|
repo = "SPIRV-LLVM-Translator";
|
2022-10-22 14:43:23 +00:00
|
|
|
inherit (branch) rev hash;
|
2019-07-27 11:48:07 +00:00
|
|
|
};
|
|
|
|
|
2022-12-12 10:42:41 +00:00
|
|
|
nativeBuildInputs = [ pkg-config cmake spirv-tools ]
|
|
|
|
++ (if isROCm then [ llvm ] else [ llvm.dev ]);
|
2019-07-27 11:48:07 +00:00
|
|
|
|
2022-12-12 10:42:41 +00:00
|
|
|
buildInputs = [ spirv-headers ]
|
|
|
|
++ lib.optionals (!isROCm) [ llvm ];
|
2019-07-27 11:48:07 +00:00
|
|
|
|
|
|
|
checkInputs = [ lit ];
|
|
|
|
|
2021-10-23 20:24:06 +00:00
|
|
|
cmakeFlags = [
|
|
|
|
"-DLLVM_INCLUDE_TESTS=ON"
|
2022-12-12 10:42:41 +00:00
|
|
|
"-DLLVM_DIR=${(if isROCm then llvm else llvm.dev)}"
|
2022-05-05 12:42:44 +00:00
|
|
|
"-DBUILD_SHARED_LIBS=YES"
|
|
|
|
"-DLLVM_SPIRV_BUILD_EXTERNAL=YES"
|
2022-07-12 15:20:45 +00:00
|
|
|
# RPATH of binary /nix/store/.../bin/llvm-spirv contains a forbidden reference to /build/
|
|
|
|
"-DCMAKE_SKIP_BUILD_RPATH=ON"
|
2022-10-22 14:46:23 +00:00
|
|
|
] ++ lib.optionals (llvmMajor != "11") [ "-DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=${spirv-headers.src}" ];
|
2019-07-27 11:48:07 +00:00
|
|
|
|
|
|
|
# FIXME: CMake tries to run "/llvm-lit" which of course doesn't exist
|
|
|
|
doCheck = false;
|
|
|
|
|
2022-03-03 08:57:05 +00:00
|
|
|
makeFlags = [ "all" "llvm-spirv" ];
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
install -D tools/llvm-spirv/llvm-spirv $out/bin/llvm-spirv
|
|
|
|
'';
|
|
|
|
|
2021-01-22 11:25:31 +00:00
|
|
|
meta = with lib; {
|
2020-04-01 01:11:51 +00:00
|
|
|
homepage = "https://github.com/KhronosGroup/SPIRV-LLVM-Translator";
|
2019-07-27 11:48:07 +00:00
|
|
|
description = "A tool and a library for bi-directional translation between SPIR-V and LLVM IR";
|
|
|
|
license = licenses.ncsa;
|
2022-11-28 04:21:17 +00:00
|
|
|
platforms = platforms.unix;
|
2019-07-27 11:48:07 +00:00
|
|
|
maintainers = with maintainers; [ gloaming ];
|
|
|
|
};
|
|
|
|
}
|