nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lib
2, stdenv
3, fetchFromGitHub
4, rocmUpdateScript
5, pkg-config
6, cmake
7, ninja
8, git
9, doxygen
10, sphinx
11, lit
12, libxml2
13, libxcrypt
14, libedit
15, libffi
16, mpfr
17, zlib
18, ncurses
19, python3Packages
20, buildDocs ? true
21, buildMan ? true
22, buildTests ? true
23, targetName ? "llvm"
24, targetDir ? "llvm"
25, targetProjects ? [ ]
26, targetRuntimes ? [ ]
27# "NATIVE" resolves into x86 or aarch64 depending on stdenv
28, llvmTargetsToBuild ? [ "NATIVE" ]
29, extraPatches ? [ ]
30, extraNativeBuildInputs ? [ ]
31, extraBuildInputs ? [ ]
32, extraCMakeFlags ? [ ]
33, extraPostPatch ? ""
34, checkTargets ? [(
35 lib.optionalString buildTests (
36 if targetDir == "runtimes"
37 then "check-runtimes"
38 else "check-all"
39 )
40)]
41, extraPostInstall ? ""
42, requiredSystemFeatures ? [ ]
43, extraLicenses ? [ ]
44, isBroken ? false
45}:
46
47let
48 llvmNativeTarget =
49 if stdenv.isx86_64 then "X86"
50 else if stdenv.isAarch64 then "AArch64"
51 else throw "Unsupported ROCm LLVM platform";
52 inferNativeTarget = t: if t == "NATIVE" then llvmNativeTarget else t;
53 llvmTargetsToBuild' = [ "AMDGPU" ] ++ builtins.map inferNativeTarget llvmTargetsToBuild;
54in stdenv.mkDerivation (finalAttrs: {
55 pname = "rocm-llvm-${targetName}";
56 version = "5.4.4";
57
58 outputs = [
59 "out"
60 ] ++ lib.optionals buildDocs [
61 "doc"
62 ] ++ lib.optionals buildMan [
63 "man"
64 "info" # Avoid `attribute 'info' missing` when using with wrapCC
65 ];
66
67 patches = extraPatches;
68
69 src = fetchFromGitHub {
70 owner = "RadeonOpenCompute";
71 repo = "llvm-project";
72 rev = "rocm-${finalAttrs.version}";
73 hash = "sha256-BDvC6QFDFtahA9hmJDLiM6K4mrO3j9E9rEXm7KulcuA=";
74 };
75
76 nativeBuildInputs = [
77 pkg-config
78 cmake
79 ninja
80 git
81 python3Packages.python
82 ] ++ lib.optionals (buildDocs || buildMan) [
83 doxygen
84 sphinx
85 python3Packages.recommonmark
86 ] ++ lib.optionals (buildTests && !finalAttrs.passthru.isLLVM) [
87 lit
88 ] ++ extraNativeBuildInputs;
89
90 buildInputs = [
91 libxml2
92 libxcrypt
93 libedit
94 libffi
95 mpfr
96 ] ++ extraBuildInputs;
97
98 propagatedBuildInputs = lib.optionals finalAttrs.passthru.isLLVM [
99 zlib
100 ncurses
101 ];
102
103 sourceRoot = "${finalAttrs.src.name}/${targetDir}";
104
105 cmakeFlags = [
106 "-DLLVM_TARGETS_TO_BUILD=${builtins.concatStringsSep ";" llvmTargetsToBuild'}"
107 ] ++ lib.optionals (finalAttrs.passthru.isLLVM && targetProjects != [ ]) [
108 "-DLLVM_ENABLE_PROJECTS=${lib.concatStringsSep ";" targetProjects}"
109 ] ++ lib.optionals ((finalAttrs.passthru.isLLVM || targetDir == "runtimes") && targetRuntimes != [ ]) [
110 "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" targetRuntimes}"
111 ] ++ lib.optionals (finalAttrs.passthru.isLLVM || finalAttrs.passthru.isClang) [
112 "-DLLVM_ENABLE_RTTI=ON"
113 "-DLLVM_ENABLE_EH=ON"
114 ] ++ lib.optionals (buildDocs || buildMan) [
115 "-DLLVM_INCLUDE_DOCS=ON"
116 "-DLLVM_BUILD_DOCS=ON"
117 # "-DLLVM_ENABLE_DOXYGEN=ON" Way too slow, only uses one core
118 "-DLLVM_ENABLE_SPHINX=ON"
119 "-DLLVM_ENABLE_OCAMLDOC=OFF"
120 "-DSPHINX_OUTPUT_HTML=ON"
121 "-DSPHINX_OUTPUT_MAN=ON"
122 "-DSPHINX_WARNINGS_AS_ERRORS=OFF"
123 ] ++ lib.optionals buildTests [
124 "-DLLVM_INCLUDE_TESTS=ON"
125 "-DLLVM_BUILD_TESTS=ON"
126 ] ++ lib.optionals (buildTests && !finalAttrs.passthru.isLLVM) [
127 "-DLLVM_EXTERNAL_LIT=${lit}/bin/.lit-wrapped"
128 ] ++ extraCMakeFlags;
129
130 postPatch = lib.optionalString finalAttrs.passthru.isLLVM ''
131 patchShebangs lib/OffloadArch/make_generated_offload_arch_h.sh
132 '' + lib.optionalString (buildTests && finalAttrs.passthru.isLLVM) ''
133 # FileSystem permissions tests fail with various special bits
134 rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
135 rm unittests/Support/Path.cpp
136
137 substituteInPlace unittests/Support/CMakeLists.txt \
138 --replace "Path.cpp" ""
139 '' + extraPostPatch;
140
141 doCheck = buildTests;
142 checkTarget = lib.concatStringsSep " " checkTargets;
143
144 postInstall = lib.optionalString finalAttrs.passthru.isLLVM ''
145 # `lit` expects these for some test suites
146 mv bin/{FileCheck,not,count,yaml2obj,obj2yaml} $out/bin
147 '' + lib.optionalString buildMan ''
148 mkdir -p $info
149 '' + extraPostInstall;
150
151 passthru = {
152 isLLVM = targetDir == "llvm";
153 isClang = targetDir == "clang" || builtins.elem "clang" targetProjects;
154
155 updateScript = rocmUpdateScript {
156 name = finalAttrs.pname;
157 owner = finalAttrs.src.owner;
158 repo = finalAttrs.src.repo;
159 };
160 };
161
162 inherit requiredSystemFeatures;
163
164 meta = with lib; {
165 description = "ROCm fork of the LLVM compiler infrastructure";
166 homepage = "https://github.com/RadeonOpenCompute/llvm-project";
167 license = with licenses; [ ncsa ] ++ extraLicenses;
168 maintainers = with maintainers; [ acowley lovesegfault ] ++ teams.rocm.members;
169 platforms = platforms.linux;
170 broken = isBroken;
171 };
172})