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 = "10.0.1";
22 version = release_version; # differentiating these (variables) is important for RCs
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" "06n1yp638rh24xdxv9v2df0qajxbjz4w59b7dd4ky36drwmpi4yh";
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 libclang = callPackage ./clang {
81 inherit clang-tools-extra_src llvm_meta;
82 };
83
84 clang-unwrapped = tools.libclang;
85
86 # disabled until recommonmark supports sphinx 3
87 #Llvm-manpages = lowPrio (tools.libllvm.override {
88 # enableManpages = true;
89 # python3 = pkgs.python3; # don't use python-boot
90 #});
91
92 clang-manpages = lowPrio (tools.libclang.override {
93 enableManpages = true;
94 python3 = pkgs.python3; # don't use python-boot
95 });
96
97 # disabled until recommonmark supports sphinx 3
98 # lldb-manpages = lowPrio (tools.lldb.override {
99 # enableManpages = true;
100 # python3 = pkgs.python3; # don't use python-boot
101 # });
102
103 # pick clang appropriate for package set we are targeting
104 clang =
105 /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc
106 else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM
107 else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang
108 else tools.libcxxClang;
109
110 libstdcxxClang = wrapCCWith rec {
111 cc = tools.clang-unwrapped;
112 # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper.
113 libcxx = null;
114 extraPackages = [
115 targetLlvmLibraries.compiler-rt
116 ];
117 extraBuildCommands = mkExtraBuildCommands cc;
118 };
119
120 libcxxClang = wrapCCWith rec {
121 cc = tools.clang-unwrapped;
122 libcxx = targetLlvmLibraries.libcxx;
123 extraPackages = [
124 libcxx.cxxabi
125 targetLlvmLibraries.compiler-rt
126 ];
127 extraBuildCommands = mkExtraBuildCommands cc;
128 };
129
130 lld = callPackage ./lld {
131 inherit llvm_meta;
132 };
133
134 lldb = callPackage ./lldb {
135 inherit llvm_meta;
136 };
137
138 # Below, is the LLVM bootstrapping logic. It handles building a
139 # fully LLVM toolchain from scratch. No GCC toolchain should be
140 # pulled in. As a consequence, it is very quick to build different
141 # targets provided by LLVM and we can also build for what GCC
142 # doesn’t support like LLVM. Probably we should move to some other
143 # file.
144
145 bintools-unwrapped = callPackage ./bintools {};
146
147 bintoolsNoLibc = wrapBintoolsWith {
148 bintools = tools.bintools-unwrapped;
149 libc = preLibcCrossHeaders;
150 };
151
152 bintools = wrapBintoolsWith {
153 bintools = tools.bintools-unwrapped;
154 };
155
156 clangUseLLVM = wrapCCWith rec {
157 cc = tools.clang-unwrapped;
158 libcxx = targetLlvmLibraries.libcxx;
159 bintools = bintools';
160 extraPackages = [
161 libcxx.cxxabi
162 targetLlvmLibraries.compiler-rt
163 ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [
164 targetLlvmLibraries.libunwind
165 ];
166 extraBuildCommands = ''
167 echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags
168 echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
169 '' + lib.optionalString (!stdenv.targetPlatform.isWasm) ''
170 echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags
171 '' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) ''
172 echo "-lunwind" >> $out/nix-support/cc-ldflags
173 '' + lib.optionalString stdenv.targetPlatform.isWasm ''
174 echo "-fno-exceptions" >> $out/nix-support/cc-cflags
175 '' + mkExtraBuildCommands cc;
176 };
177
178 clangNoLibcxx = wrapCCWith rec {
179 cc = tools.clang-unwrapped;
180 libcxx = null;
181 bintools = bintools';
182 extraPackages = [
183 targetLlvmLibraries.compiler-rt
184 ];
185 extraBuildCommands = ''
186 echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
187 echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
188 echo "-nostdlib++" >> $out/nix-support/cc-cflags
189 '' + mkExtraBuildCommands cc;
190 };
191
192 clangNoLibc = wrapCCWith rec {
193 cc = tools.clang-unwrapped;
194 libcxx = null;
195 bintools = bintoolsNoLibc';
196 extraPackages = [
197 targetLlvmLibraries.compiler-rt
198 ];
199 extraBuildCommands = ''
200 echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags
201 echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags
202 '' + mkExtraBuildCommands cc;
203 };
204
205 clangNoCompilerRt = wrapCCWith rec {
206 cc = tools.clang-unwrapped;
207 libcxx = null;
208 bintools = bintoolsNoLibc';
209 extraPackages = [ ];
210 extraBuildCommands = ''
211 echo "-nostartfiles" >> $out/nix-support/cc-cflags
212 '' + mkExtraBuildCommands0 cc;
213 };
214
215 clangNoCompilerRtWithLibc = wrapCCWith rec {
216 cc = tools.clang-unwrapped;
217 libcxx = null;
218 bintools = bintools';
219 extraPackages = [ ];
220 extraBuildCommands = mkExtraBuildCommands0 cc;
221 };
222
223 });
224
225 libraries = lib.makeExtensible (libraries: let
226 callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch; });
227 in {
228
229 compiler-rt-libc = callPackage ./compiler-rt {
230 inherit llvm_meta;
231 stdenv = if stdenv.hostPlatform.useLLVM or false
232 then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc
233 else stdenv;
234 };
235
236 compiler-rt-no-libc = callPackage ./compiler-rt {
237 inherit llvm_meta;
238 stdenv = if stdenv.hostPlatform.useLLVM or false
239 then overrideCC stdenv buildLlvmTools.clangNoCompilerRt
240 else stdenv;
241 };
242
243 # N.B. condition is safe because without useLLVM both are the same.
244 compiler-rt = if stdenv.hostPlatform.isAndroid
245 then libraries.compiler-rt-libc
246 else libraries.compiler-rt-no-libc;
247
248 stdenv = overrideCC stdenv buildLlvmTools.clang;
249
250 libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang;
251
252 libcxx = callPackage ./libcxx {
253 inherit llvm_meta;
254 stdenv = if stdenv.hostPlatform.useLLVM or false
255 then overrideCC stdenv buildLlvmTools.clangNoLibcxx
256 else stdenv;
257 };
258
259 libcxxabi = callPackage ./libcxxabi {
260 inherit llvm_meta;
261 stdenv = if stdenv.hostPlatform.useLLVM or false
262 then overrideCC stdenv buildLlvmTools.clangNoLibcxx
263 else stdenv;
264 };
265
266 libunwind = callPackage ./libunwind {
267 inherit llvm_meta;
268 stdenv = if stdenv.hostPlatform.useLLVM or false
269 then overrideCC stdenv buildLlvmTools.clangNoLibcxx
270 else stdenv;
271 };
272
273 openmp = callPackage ./openmp {
274 inherit llvm_meta targetLlvm;
275 };
276 });
277
278in { inherit tools libraries release_version; } // libraries // tools