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