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