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