27 , llvmTargetsToBuild ? [ "NATIVE" ] # "NATIVE" resolves into x86 or aarch64 depending on stdenv
28 , llvmProjectsToBuild ? [ "llvm" "mlir" ]
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)
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
54 ] ++ lib.optionals buildDocs [
56 ] ++ lib.optionals buildMan [
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 {
64 repo = "llvm-project";
65 rev = "10dc3a8e916d73291269e5e2b82dd22681489aa1";
66 hash = "sha256-9DPvcFmhzw6MipQeCQnr35LktW0uxtEL8axMMPXIfWw=";
70 # [llvm-exegesis] Use correct rseq struct size #100804
71 # https://github.com/llvm/llvm-project/issues/100791
73 url = "https://github.com/llvm/llvm-project//commit/84837e3cc1cf17ed71580e3ea38299ed2bfaa5f6.patch";
74 hash = "sha256-QKa+kyXjjGXwTQTEpmKZx5yYjOyBX8A8NQoIYUaGcIw=";
84 ] ++ lib.optionals (buildDocs || buildMan) [
87 python3Packages.recommonmark
88 python3Packages.myst-parser
100 propagatedBuildInputs = [
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;
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")
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")
150 (lib.cmakeBool "CMAKE_CROSSCOMPILING" true)
151 (lib.cmakeFeature "CROSS_TOOLCHAIN_FLAGS_NATIVE" (lib.concatStringsSep ";"
152 (lib.concatLists [ nativeToolchainFlags nativeInstallFlags ])))
156 # `CMake Error: cannot write to file "/build/source/llvm/build/lib/cmake/mlir/MLIRTargets.cmake": Permission denied`
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
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
177 doCheck = buildTests;
179 nativeCheckInputs = [ which ]
180 ++ lib.optionals stdenv.hostPlatform.isDarwin [ sysctl ];
182 checkTarget = "check-all";
183 requiredSystemFeatures = [ "big-parallel" ];
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;