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