nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at netboot-syslinux-multiplatform 287 lines 9.4 kB view raw
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 = "7.1.0"; 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://releases.llvm.org/${release_version}/${name}-${version}.src.tar.xz"; 27 inherit sha256; 28 }; 29 30 clang-tools-extra_src = fetch "clang-tools-extra" "0lb4kdh7j2fhfz8kd6iv5df7m3pikiryk1vvwsf87spc90n09q0w"; 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 llvm-manpages = lowPrio (tools.libllvm.override { 101 enableManpages = true; 102 python3 = pkgs.python3; # don't use python-boot 103 }); 104 105 clang-manpages = lowPrio (tools.libclang.override { 106 enableManpages = true; 107 python3 = pkgs.python3; # don't use python-boot 108 }); 109 110 # pick clang appropriate for package set we are targeting 111 clang = 112 /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc 113 else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM 114 else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang 115 else tools.libcxxClang; 116 117 libstdcxxClang = wrapCCWith rec { 118 cc = tools.clang-unwrapped; 119 # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. 120 libcxx = null; 121 extraPackages = [ 122 targetLlvmLibraries.compiler-rt 123 ]; 124 extraBuildCommands = mkExtraBuildCommands cc; 125 }; 126 127 libcxxClang = wrapCCWith rec { 128 cc = tools.clang-unwrapped; 129 libcxx = targetLlvmLibraries.libcxx; 130 extraPackages = [ 131 libcxx.cxxabi 132 targetLlvmLibraries.compiler-rt 133 ]; 134 extraBuildCommands = mkExtraBuildCommands cc; 135 }; 136 137 lld = callPackage ./lld { 138 inherit llvm_meta; 139 }; 140 141 lldb = callPackage ./lldb { 142 inherit llvm_meta; 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 = 252 if stdenv.hostPlatform.isAndroid || (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isDarwin) 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 inherit (buildLlvmTools) llvm; 277 stdenv = if stdenv.hostPlatform.useLLVM or false 278 then overrideCC stdenv buildLlvmTools.clangNoLibcxx 279 else stdenv; 280 }; 281 282 openmp = callPackage ./openmp { 283 inherit llvm_meta targetLlvm; 284 }; 285 }); 286 287in { inherit tools libraries release_version; } // libraries // tools