evcc: 0.131.4 -> 0.131.5
[NixPkgs.git] / pkgs / by-name / tr / triton-llvm / package.nix
blob829f0c912afd24e3e12c363603b57b2c0530c119
1 { lib
2 , stdenv
3 , fetchFromGitHub
4 , fetchpatch
5 , pkgsBuildBuild
6 , pkg-config
7 , cmake
8 , ninja
9 , git
10 , libxml2
11 , libxcrypt
12 , libedit
13 , libffi
14 , libpfm
15 , lit
16 , mpfr
17 , zlib
18 , ncurses
19 , doxygen
20 , sphinx
21 , which
22 , sysctl
23 , python3Packages
24 , buildDocs ? true
25 , buildMan ? true
26 , buildTests ? true
27 , llvmTargetsToBuild ? [ "NATIVE" ] # "NATIVE" resolves into x86 or aarch64 depending on stdenv
28 , llvmProjectsToBuild ? [ "llvm" "mlir" ]
31 let
32   llvmNativeTarget =
33     if stdenv.hostPlatform.isx86_64 then "X86"
34     else if stdenv.hostPlatform.isAarch64 then "AArch64"
35     else throw "Currently unsupported LLVM platform '${stdenv.hostPlatform.config}'";
37   inferNativeTarget = t: if t == "NATIVE" then llvmNativeTarget else t;
38   llvmTargetsToBuild' = [ "AMDGPU" "NVPTX" ] ++ builtins.map inferNativeTarget llvmTargetsToBuild;
40   # This LLVM version can't seem to find pygments/pyyaml,
41   # but a later update will likely fix this (triton-2.1.0)
42   python =
43     if buildTests
44     then python3Packages.python.withPackages (p: with p; [ psutil pygments pyyaml ])
45     else python3Packages.python;
47   isNative = stdenv.hostPlatform == stdenv.buildPlatform;
48 in stdenv.mkDerivation (finalAttrs: {
49   pname = "triton-llvm";
50   version = "19.1.0-rc1"; # One of the tags at https://github.com/llvm/llvm-project/commit/10dc3a8e916d73291269e5e2b82dd22681489aa1
52   outputs = [
53     "out"
54   ] ++ lib.optionals buildDocs [
55     "doc"
56   ] ++ lib.optionals buildMan [
57     "man"
58   ];
60   # See https://github.com/triton-lang/triton/blob/main/python/setup.py
61   # and https://github.com/ptillet/triton-llvm-releases/releases
62   src = fetchFromGitHub {
63     owner = "llvm";
64     repo = "llvm-project";
65     rev = "10dc3a8e916d73291269e5e2b82dd22681489aa1";
66     hash = "sha256-9DPvcFmhzw6MipQeCQnr35LktW0uxtEL8axMMPXIfWw=";
67   };
68   patches = [
69     # glibc-2.40 support
70     # [llvm-exegesis] Use correct rseq struct size #100804
71     # https://github.com/llvm/llvm-project/issues/100791
72     (fetchpatch {
73       url = "https://github.com/llvm/llvm-project//commit/84837e3cc1cf17ed71580e3ea38299ed2bfaa5f6.patch";
74       hash = "sha256-QKa+kyXjjGXwTQTEpmKZx5yYjOyBX8A8NQoIYUaGcIw=";
75     })
76   ];
78   nativeBuildInputs = [
79     pkg-config
80     cmake
81     ninja
82     git
83     python
84   ] ++ lib.optionals (buildDocs || buildMan) [
85     doxygen
86     sphinx
87     python3Packages.recommonmark
88     python3Packages.myst-parser
89   ];
91   buildInputs = [
92     libxml2
93     libxcrypt
94     libedit
95     libffi
96     libpfm
97     mpfr
98   ];
100   propagatedBuildInputs = [
101     zlib
102     ncurses
103   ];
105   preConfigure = ''
106     cd llvm
107   '';
109   cmakeFlags = [
110     (lib.cmakeFeature "LLVM_TARGETS_TO_BUILD" (lib.concatStringsSep ";" llvmTargetsToBuild'))
111     (lib.cmakeFeature "LLVM_ENABLE_PROJECTS" (lib.concatStringsSep ";" llvmProjectsToBuild))
112     (lib.cmakeFeature "LLVM_HOST_TRIPLE" stdenv.hostPlatform.config)
113     (lib.cmakeFeature "LLVM_DEFAULT_TARGET_TRIPLE" stdenv.hostPlatform.config)
114     (lib.cmakeBool "LLVM_INSTALL_UTILS" true)
115     (lib.cmakeBool "LLVM_INCLUDE_DOCS" (buildDocs || buildMan))
116     (lib.cmakeBool "MLIR_INCLUDE_DOCS" (buildDocs || buildMan))
117     (lib.cmakeBool "LLVM_BUILD_DOCS" (buildDocs || buildMan))
118     # Way too slow, only uses one core
119     # (lib.cmakeBool "LLVM_ENABLE_DOXYGEN" (buildDocs || buildMan))
120     (lib.cmakeBool "LLVM_ENABLE_SPHINX" (buildDocs || buildMan))
121     (lib.cmakeBool "SPHINX_OUTPUT_HTML" buildDocs)
122     (lib.cmakeBool "SPHINX_OUTPUT_MAN" buildMan)
123     (lib.cmakeBool "SPHINX_WARNINGS_AS_ERRORS" false)
124     (lib.cmakeBool "LLVM_INCLUDE_TESTS" buildTests)
125     (lib.cmakeBool "MLIR_INCLUDE_TESTS" buildTests)
126     (lib.cmakeBool "LLVM_BUILD_TESTS" buildTests)
127   # Cross compilation code taken/modified from LLVM 16 derivation
128   ] ++ lib.optionals (!isNative) (let
129     nativeToolchainFlags = let
130       nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc;
131       nativeBintools = nativeCC.bintools.bintools;
132     in [
133       (lib.cmakeFeature "CMAKE_C_COMPILER" "${nativeCC}/bin/${nativeCC.targetPrefix}cc")
134       (lib.cmakeFeature "CMAKE_CXX_COMPILER" "${nativeCC}/bin/${nativeCC.targetPrefix}c++")
135       (lib.cmakeFeature "CMAKE_AR" "${nativeBintools}/bin/${nativeBintools.targetPrefix}ar")
136       (lib.cmakeFeature "CMAKE_STRIP" "${nativeBintools}/bin/${nativeBintools.targetPrefix}strip")
137       (lib.cmakeFeature "CMAKE_RANLIB" "${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib")
138     ];
140     # We need to repass the custom GNUInstallDirs values, otherwise CMake
141     # will choose them for us, leading to wrong results in llvm-config-native
142     nativeInstallFlags = [
143       (lib.cmakeFeature "CMAKE_INSTALL_PREFIX" (placeholder "out"))
144       (lib.cmakeFeature "CMAKE_INSTALL_BINDIR" "${placeholder "out"}/bin")
145       (lib.cmakeFeature "CMAKE_INSTALL_INCLUDEDIR" "${placeholder "out"}/include")
146       (lib.cmakeFeature "CMAKE_INSTALL_LIBDIR" "${placeholder "out"}/lib")
147       (lib.cmakeFeature "CMAKE_INSTALL_LIBEXECDIR" "${placeholder "out"}/libexec")
148     ];
149   in [
150     (lib.cmakeBool "CMAKE_CROSSCOMPILING" true)
151     (lib.cmakeFeature "CROSS_TOOLCHAIN_FLAGS_NATIVE" (lib.concatStringsSep ";"
152       (lib.concatLists [ nativeToolchainFlags nativeInstallFlags ])))
153   ]);
155   postPatch = ''
156     # `CMake Error: cannot write to file "/build/source/llvm/build/lib/cmake/mlir/MLIRTargets.cmake": Permission denied`
157     chmod +w -R ./mlir
158     patchShebangs ./mlir/test/mlir-reduce
160     # FileSystem permissions tests fail with various special bits
161     rm llvm/test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
162     rm llvm/unittests/Support/Path.cpp
164     substituteInPlace llvm/unittests/Support/CMakeLists.txt \
165       --replace "Path.cpp" ""
166   '' + lib.optionalString stdenv.hostPlatform.isAarch64 ''
167     # Not sure why this fails
168     rm llvm/test/tools/llvm-exegesis/AArch64/latency-by-opcode-name.s
169   '';
171   postInstall = ''
172     cp ${lib.getExe lit} $out/bin/llvm-lit
173   '' + (lib.optionalString (!isNative) ''
174     cp -a NATIVE/bin/llvm-config $out/bin/llvm-config-native
175   '');
177   doCheck = buildTests;
179   nativeCheckInputs = [ which ]
180     ++ lib.optionals stdenv.hostPlatform.isDarwin [ sysctl ];
182   checkTarget = "check-all";
183   requiredSystemFeatures = [ "big-parallel" ];
185   meta = with lib; {
186     description = "Collection of modular and reusable compiler and toolchain technologies";
187     homepage = "https://github.com/llvm/llvm-project";
188     license = with licenses; [ ncsa ];
189     maintainers = with maintainers; [ SomeoneSerge Madouura ];
190     platforms = with platforms; aarch64 ++ x86;
191   };