2021-02-05 17:12:51 +00:00
|
|
|
{ lib, stdenv
|
2020-04-24 23:36:52 +00:00
|
|
|
, fetchFromGitHub
|
2023-10-09 19:29:22 +00:00
|
|
|
, fetchpatch
|
2020-04-24 23:36:52 +00:00
|
|
|
, 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-10-19 13:55:26 +00:00
|
|
|
# ROCm, if actively updated will always be at the latest version
|
2022-11-04 12:27:35 +00:00
|
|
|
branch =
|
2024-04-21 15:54:59 +00:00
|
|
|
if llvmMajor == "18" then rec {
|
|
|
|
version = "18.1.0";
|
|
|
|
rev = "v${version}";
|
|
|
|
hash = "sha256-64guZiuO7VpaX01wNIjV7cnjEAe6ineMdY44S6sA33k=";
|
|
|
|
} else if llvmMajor == "17" || isROCm then rec {
|
2023-10-19 13:55:26 +00:00
|
|
|
version = "17.0.0";
|
|
|
|
rev = "v${version}";
|
|
|
|
hash = "sha256-Rzm5Py9IPFtS9G7kME+uSwZ/0gPGW6MlL35ZWk4LfHM=";
|
|
|
|
} else if llvmMajor == "16" then rec {
|
2023-10-09 19:29:22 +00:00
|
|
|
version = "16.0.0";
|
|
|
|
rev = "v${version}";
|
|
|
|
hash = "sha256-EUabcYqSjXshbPmcs1DRLvCSL1nd9rEdpqELBrItCW8=";
|
2023-10-19 13:55:26 +00:00
|
|
|
} else if llvmMajor == "15" 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=";
|
2024-02-07 01:22:34 +00:00
|
|
|
} else if llvmMajor == "14" then {
|
2024-04-21 15:54:59 +00:00
|
|
|
version = "14.0.0+unstable-2024-02-14";
|
|
|
|
rev = "2221771c28dc224d5d560faf6a2cd73f8ecf713d";
|
|
|
|
hash = "sha256-J4qOgDdcsPRU1AXXXWN+qe4c47uMCrjmtM8MSrl9NjE=";
|
2022-11-04 12:27:35 +00:00
|
|
|
} else if llvmMajor == "11" then {
|
2024-01-13 08:15:51 +00:00
|
|
|
version = "11.0.0+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
|
2024-04-21 15:54:59 +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
|
|
|
};
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
patches = lib.optionals (llvmMajor == "18") [
|
|
|
|
# Fixes build after SPV_INTEL_maximum_registers breaking change
|
|
|
|
# TODO: remove on next spirv-headers release
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/KhronosGroup/SPIRV-LLVM-Translator/commit/d970c9126c033ebcbb7187bc705eae2e54726b74.patch";
|
|
|
|
revert = true;
|
|
|
|
hash = "sha256-71sJuGqVjTcB549eIiCO0LoqAgxkdEHCoxh8Pd/Qzz8=";
|
|
|
|
})
|
|
|
|
] ++ lib.optionals (lib.versionAtLeast llvmMajor "15" && lib.versionOlder llvmMajor "18") [
|
2024-01-25 14:12:00 +00:00
|
|
|
# Fixes build after spirv-headers breaking change
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/KhronosGroup/SPIRV-LLVM-Translator/commit/0166a0fb86dc6c0e8903436bbc3a89bc3273ebc0.patch";
|
|
|
|
excludes = ["spirv-headers-tag.conf"];
|
|
|
|
hash = "sha256-17JJG8eCFVphElY5fVT/79hj0bByWxo8mVp1ZNjQk/M=";
|
|
|
|
})
|
|
|
|
] ++ lib.optionals (llvmMajor == "16") [
|
2023-10-09 19:29:22 +00:00
|
|
|
# Fixes builds that link against external LLVM dynamic library
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/KhronosGroup/SPIRV-LLVM-Translator/commit/f3b9b604d7eda18d0d1029d94a6eebd33aa3a3fe.patch";
|
|
|
|
hash = "sha256-opDjyZcy7O4wcSfm/A51NCIiDyIvbcmbv9ns1njdJbc=";
|
|
|
|
})
|
2024-01-13 08:15:51 +00:00
|
|
|
] ++ lib.optionals (llvmMajor == "14") [
|
|
|
|
(fetchpatch {
|
|
|
|
# tries to install llvm-spirv into llvm nix store path
|
|
|
|
url = "https://github.com/KhronosGroup/SPIRV-LLVM-Translator/commit/cce9a2f130070d799000cac42fe24789d2b777ab.patch";
|
|
|
|
revert = true;
|
|
|
|
hash = "sha256-GbFacttZRDCgA0jkUoFA4/B3EDn3etweKvM09OwICJ8=";
|
|
|
|
})
|
2023-10-09 19:29:22 +00:00
|
|
|
];
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
nativeBuildInputs = [ pkg-config cmake ]
|
2023-01-20 10:41:00 +00:00
|
|
|
++ (if isROCm then [ llvm ] else [ llvm.dev ]);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
buildInputs = [ spirv-headers spirv-tools ]
|
2023-01-20 10:41:00 +00:00
|
|
|
++ 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"
|
2024-01-13 08:15:51 +00:00
|
|
|
] ++ lib.optional (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
|
2023-10-09 19:29:22 +00:00
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
|
|
install_name_tool $out/bin/llvm-spirv \
|
|
|
|
-change @rpath/libLLVMSPIRVLib.dylib $out/lib/libLLVMSPIRVLib.dylib
|
2022-05-18 14:49:53 +00:00
|
|
|
'';
|
|
|
|
|
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";
|
2024-04-21 15:54:59 +00:00
|
|
|
mainProgram = "llvm-spirv";
|
2020-04-24 23:36:52 +00:00
|
|
|
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 ];
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
}
|