25 , llvmTargetsToBuild ? [ "NATIVE" ] # "NATIVE" resolves into x86 or aarch64 depending on stdenv
26 , llvmProjectsToBuild ? [ "llvm" "mlir" ]
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)
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";
52 ] ++ lib.optionals buildDocs [
54 ] ++ lib.optionals buildMan [
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 {
62 repo = "llvm-project";
63 rev = "c5dede880d175f7229c9b2923f4753e12702305d";
64 hash = "sha256-v4r3+7XVFK+Dzxt/rErZNJ9REqFO3JmGN4X4vZ+77ew=";
73 ] ++ lib.optionals (buildDocs || buildMan) [
76 python3Packages.recommonmark
88 propagatedBuildInputs = [
93 sourceRoot = "${finalAttrs.src.name}/llvm";
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;
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")
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")
136 (lib.cmakeBool "CMAKE_CROSSCOMPILING" true)
137 (lib.cmakeFeature "CROSS_TOOLCHAIN_FLAGS_NATIVE" (lib.concatStringsSep ";"
138 (lib.concatLists [ nativeToolchainFlags nativeInstallFlags ])))
142 # `CMake Error: cannot write to file "/build/source/llvm/build/lib/cmake/mlir/MLIRTargets.cmake": Permission denied`
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
157 postInstall = lib.optionalString (!isNative) ''
158 cp -a NATIVE/bin/llvm-config $out/bin/llvm-config-native
161 doCheck = buildTests;
163 nativeCheckInputs = [ which ]
164 ++ lib.optionals stdenv.hostPlatform.isDarwin [ sysctl ];
166 checkTarget = "check-all";
167 requiredSystemFeatures = [ "big-parallel" ];
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;