mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-22 05:33:23 +00:00
a9fd593f39
This reverts commit 69a71a0ec2
.
Previously, the only use for spirv-tools was its commands being used
to run tests, but now, spirv-llvm-translator also links against its
libraries. Tests won't be run when cross compiling to a
non-compatible architecture anyway, so to keep spirv-llvm-translator
cross compiling, we should move spirv-tools back to being a build
input so that the libraries can be found. We could try to convince
CMake to use SPIRV-Tools.cmake from the host spirv-tools and
SPIRV-Tools-tools.cmake from the build spirv-tools, but since we never
actually need both when cross compiling it's not worth it.
This fixes the cross build LLVM/SPIRV-LLVM-Translator 16.
95 lines
3.0 KiB
Nix
95 lines
3.0 KiB
Nix
{ lib, stdenv
|
|
, fetchFromGitHub
|
|
, fetchpatch
|
|
, cmake
|
|
, pkg-config
|
|
, lit
|
|
, llvm
|
|
, spirv-headers
|
|
, spirv-tools
|
|
}:
|
|
|
|
let
|
|
llvmMajor = lib.versions.major llvm.version;
|
|
isROCm = lib.hasPrefix "rocm" llvm.pname;
|
|
|
|
# ROCm, if actively updated will always be at the latest version
|
|
branch =
|
|
if llvmMajor == "17" || isROCm then rec {
|
|
version = "17.0.0";
|
|
rev = "v${version}";
|
|
hash = "sha256-Rzm5Py9IPFtS9G7kME+uSwZ/0gPGW6MlL35ZWk4LfHM=";
|
|
} else if llvmMajor == "16" then rec {
|
|
version = "16.0.0";
|
|
rev = "v${version}";
|
|
hash = "sha256-EUabcYqSjXshbPmcs1DRLvCSL1nd9rEdpqELBrItCW8=";
|
|
} else if llvmMajor == "15" then rec {
|
|
version = "15.0.0";
|
|
rev = "v${version}";
|
|
hash = "sha256-OsDohXRxovtEXaWiRGp8gJ0dXmoALyO+ZimeSO8aPVI=";
|
|
} 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";
|
|
rev = "4ef524240833abfeee1c5b9fff6b1bd53f4806b3"; # 267 commits ahead of v11.0.0
|
|
hash = "sha256-NoIoa20+2sH41rEnr8lsMhtfesrtdPINiXtUnxYVm8s=";
|
|
} else throw "Incompatible LLVM version.";
|
|
in
|
|
stdenv.mkDerivation {
|
|
pname = "SPIRV-LLVM-Translator";
|
|
inherit (branch) version;
|
|
|
|
src = fetchFromGitHub {
|
|
owner = "KhronosGroup";
|
|
repo = "SPIRV-LLVM-Translator";
|
|
inherit (branch) rev hash;
|
|
};
|
|
|
|
patches = lib.optionals (llvmMajor == "16")[
|
|
# 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=";
|
|
})
|
|
];
|
|
|
|
nativeBuildInputs = [ pkg-config cmake ]
|
|
++ (if isROCm then [ llvm ] else [ llvm.dev ]);
|
|
|
|
buildInputs = [ spirv-headers spirv-tools ]
|
|
++ lib.optionals (!isROCm) [ llvm ];
|
|
|
|
nativeCheckInputs = [ lit ];
|
|
|
|
cmakeFlags = [
|
|
"-DLLVM_INCLUDE_TESTS=ON"
|
|
"-DLLVM_DIR=${(if isROCm then llvm else llvm.dev)}"
|
|
"-DBUILD_SHARED_LIBS=YES"
|
|
"-DLLVM_SPIRV_BUILD_EXTERNAL=YES"
|
|
# RPATH of binary /nix/store/.../bin/llvm-spirv contains a forbidden reference to /build/
|
|
"-DCMAKE_SKIP_BUILD_RPATH=ON"
|
|
] ++ lib.optionals (llvmMajor != "11") [ "-DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=${spirv-headers.src}" ];
|
|
|
|
# FIXME: CMake tries to run "/llvm-lit" which of course doesn't exist
|
|
doCheck = false;
|
|
|
|
makeFlags = [ "all" "llvm-spirv" ];
|
|
|
|
postInstall = ''
|
|
install -D tools/llvm-spirv/llvm-spirv $out/bin/llvm-spirv
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
install_name_tool $out/bin/llvm-spirv \
|
|
-change @rpath/libLLVMSPIRVLib.dylib $out/lib/libLLVMSPIRVLib.dylib
|
|
'';
|
|
|
|
meta = with lib; {
|
|
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;
|
|
platforms = platforms.unix;
|
|
maintainers = with maintainers; [ gloaming ];
|
|
};
|
|
}
|