nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ lowPrio, newScope, pkgs, lib, stdenv, cmake
2, gccForLibs, preLibcCrossHeaders
3, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith
4, buildLlvmTools # tools, but from the previous stage, for cross
5, targetLlvmLibraries # libraries, but from the next stage, for cross
6, targetLlvm
7# This is the default binutils, but with *this* version of LLD rather
8# than the default LLVM version's, if LLD is the choice. We use these for
9# the `useLLVM` bootstrapping below.
10, bootBintoolsNoLibc ?
11 if stdenv.targetPlatform.linker == "lld"
12 then null
13 else pkgs.bintoolsNoLibc
14, bootBintools ?
15 if stdenv.targetPlatform.linker == "lld"
16 then null
17 else pkgs.bintools
18}:
19
20let
21 release_version = "8.0.1";
22 version = release_version; # differentiating these is important for rc's
23 targetConfig = stdenv.targetPlatform.config;
24
25 fetch = name: sha256: fetchurl {
26 url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${release_version}/${name}-${version}.src.tar.xz";
27 inherit sha256;
28 };
29
30 clang-tools-extra_src = fetch "clang-tools-extra" "1qf3097bc5ia8p6cpmbx985rjr3yaah5s8fc0nv7pw742yv7jw8q";
31
32 llvm_meta = {
33 license = lib.licenses.ncsa;
34 maintainers = lib.teams.llvm.members;
35
36 # See llvm/cmake/config-ix.cmake.
37 platforms =
38 lib.platforms.aarch64 ++
39 lib.platforms.arm ++
40 lib.platforms.mips ++
41 lib.platforms.power ++
42 lib.platforms.riscv ++
43 lib.platforms.s390x ++
44 lib.platforms.wasi ++
45 lib.platforms.x86;
46 };
47
48 tools = lib.makeExtensible (tools: let
49 callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch buildLlvmTools; });
50 mkExtraBuildCommands0 = cc: ''
51 rsrc="$out/resource-root"
52 mkdir "$rsrc"
53 ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc"
54 echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags
55 '';
56 mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + ''
57 ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib"
58 ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share"
59 '';
60
61 bintoolsNoLibc' =
62 if bootBintoolsNoLibc == null
63 then tools.bintoolsNoLibc
64 else bootBintoolsNoLibc;
65 bintools' =
66 if bootBintools == null
67 then tools.bintools
68 else bootBintools;
69
70 in {
71
72 libllvm = callPackage ./llvm {
73 inherit llvm_meta;
74 };
75
76 # `llvm` historically had the binaries. When choosing an output explicitly,
77 # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get*
78 llvm = tools.libllvm;
79
80 libllvm-polly = callPackage ./llvm {
81 inherit llvm_meta;
82 enablePolly = true;
83 };
84
85 llvm-polly = tools.libllvm-polly.lib // { outputSpecified = false; };
86
87 libclang = callPackage ./clang {
88 inherit clang-tools-extra_src llvm_meta;
89 };
90
91 clang-unwrapped = tools.libclang;
92
93 clang-polly-unwrapped = callPackage ./clang {
94 inherit llvm_meta;
95 inherit clang-tools-extra_src;
96 libllvm = tools.libllvm-polly;
97 enablePolly = true;
98 };
99
100 # disabled until recommonmark supports sphinx 3
101 #llvm-manpages = lowPrio (tools.libllvm.override {
102 # enableManpages = true;
103 # python3 = pkgs.python3; # don't use python-boot
104 #});
105
106 clang-manpages = lowPrio (tools.libclang.override {
107 enableManpages = true;
108 python3 = pkgs.python3; # don't use python-boot
109 });
110
111 # pick clang appropriate for package set we are targeting
112 clang =
113 /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc
114 else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM
115 else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang
116 else tools.libcxxClang;
117
118 libstdcxxClang = wrapCCWith rec {
119 cc = tools.clang-unwrapped;
120 # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
121 libcxx = null;
122 extraPackages = [
123 targetLlvmLibraries.compiler-rt
124 ];
125 extraBuildCommands = mkExtraBuildCommands cc;
126 };
127
128 libcxxClang = wrapCCWith rec {
129 cc = tools.clang-unwrapped;
130 libcxx = targetLlvmLibraries.libcxx;
131 extraPackages = [
132 libcxx.cxxabi
133 targetLlvmLibraries.compiler-rt
134 ];
135 extraBuildCommands = mkExtraBuildCommands cc;
136 };
137
138 lld = callPackage ./lld {
139 inherit llvm_meta;
140 };
141
142 lldb = callPackage ./lldb {
143 inherit llvm_meta;
144 };
145
146 # Below, is the LLVM bootstrapping logic. It handles building a
147 # fully LLVM toolchain from scratch. No GCC toolchain should be
148 # pulled in. As a consequence, it is very quick to build different
149 # targets provided by LLVM and we can also build for what GCC
150 # doesn’t support like LLVM. Probably we should move to some other
151 # file.
152
153 bintools-unwrapped = callPackage ./bintools {};
154
155 bintoolsNoLibc = wrapBintoolsWith {
156 bintools = tools.bintools-unwrapped;
157 libc = preLibcCrossHeaders;
158 };
159
160 bintools = wrapBintoolsWith {
161 bintools = tools.bintools-unwrapped;
162 };
163
164 clangUseLLVM = wrapCCWith rec {
165 cc = tools.clang-unwrapped;
166 libcxx = targetLlvmLibraries.libcxx;
167 bintools = bintools';
168 extraPackages = [
169 libcxx.cxxabi
170 targetLlvmLibraries.compiler-rt
171 ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [
172 targetLlvmLibraries.libunwind
173 ];
174 extraBuildCommands = ''
175 echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
176 echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
177 '' + lib.optionalString (!stdenv.targetPlatform.isWasm) ''
178 echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags
179 '' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) ''
180 echo "-lunwind" >> $out/nix-support/cc-ldflags
181 '' + lib.optionalString stdenv.targetPlatform.isWasm ''
182 echo "-fno-exceptions" >> $out/nix-support/cc-cflags
183 '' + mkExtraBuildCommands cc;
184 };
185
186 clangNoLibcxx = wrapCCWith rec {
187 cc = tools.clang-unwrapped;
188 libcxx = null;
189 bintools = bintools';
190 extraPackages = [
191 targetLlvmLibraries.compiler-rt
192 ];
193 extraBuildCommands = ''
194 echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
195 echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
196 echo "-nostdlib++" >> $out/nix-support/cc-cflags
197 '' + mkExtraBuildCommands cc;
198 };
199
200 clangNoLibc = wrapCCWith rec {
201 cc = tools.clang-unwrapped;
202 libcxx = null;
203 bintools = bintoolsNoLibc';
204 extraPackages = [
205 targetLlvmLibraries.compiler-rt
206 ];
207 extraBuildCommands = ''
208 echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
209 echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
210 '' + mkExtraBuildCommands cc;
211 };
212
213 clangNoCompilerRt = wrapCCWith rec {
214 cc = tools.clang-unwrapped;
215 libcxx = null;
216 bintools = bintoolsNoLibc';
217 extraPackages = [ ];
218 extraBuildCommands = ''
219 echo "-nostartfiles" >> $out/nix-support/cc-cflags
220 '' + mkExtraBuildCommands0 cc;
221 };
222
223 clangNoCompilerRtWithLibc = wrapCCWith rec {
224 cc = tools.clang-unwrapped;
225 libcxx = null;
226 bintools = bintools';
227 extraPackages = [ ];
228 extraBuildCommands = mkExtraBuildCommands0 cc;
229 };
230
231 });
232
233 libraries = lib.makeExtensible (libraries: let
234 callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch; });
235 in {
236
237 compiler-rt-libc = callPackage ./compiler-rt {
238 inherit llvm_meta;
239 stdenv = if stdenv.hostPlatform.useLLVM or false
240 then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc
241 else stdenv;
242 };
243
244 compiler-rt-no-libc = callPackage ./compiler-rt {
245 inherit llvm_meta;
246 stdenv = if stdenv.hostPlatform.useLLVM or false
247 then overrideCC stdenv buildLlvmTools.clangNoCompilerRt
248 else stdenv;
249 };
250
251 # N.B. condition is safe because without useLLVM both are the same.
252 compiler-rt = if stdenv.hostPlatform.isAndroid
253 then libraries.compiler-rt-libc
254 else libraries.compiler-rt-no-libc;
255
256 stdenv = overrideCC stdenv buildLlvmTools.clang;
257
258 libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
259
260 libcxx = callPackage ./libcxx {
261 inherit llvm_meta;
262 stdenv = if stdenv.hostPlatform.useLLVM or false
263 then overrideCC stdenv buildLlvmTools.clangNoLibcxx
264 else stdenv;
265 };
266
267 libcxxabi = callPackage ./libcxxabi {
268 inherit llvm_meta;
269 stdenv = if stdenv.hostPlatform.useLLVM or false
270 then overrideCC stdenv buildLlvmTools.clangNoLibcxx
271 else stdenv;
272 };
273
274 libunwind = callPackage ./libunwind {
275 inherit llvm_meta;
276 stdenv = if stdenv.hostPlatform.useLLVM or false
277 then overrideCC stdenv buildLlvmTools.clangNoLibcxx
278 else stdenv;
279 };
280
281 openmp = callPackage ./openmp {
282 inherit llvm_meta targetLlvm;
283 };
284 });
285
286in { inherit tools libraries release_version; } // libraries // tools