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