nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 596 lines 16 kB view raw
1# afaik the longest dependency chain is stdenv -> stdenv-1#coreutils -> stdenv-1#gmp -> stdenv-0#libcxx -> stdenv-0#libc 2# this is only possible through aggressive hacking to make libcxx build with stdenv-0#libc instead of bootstrapTools.libc. 3{ 4 lib, 5 localSystem, 6 crossSystem, 7 config, 8 overlays, 9 crossOverlays ? [ ], 10 bootstrapFiles ? 11 let 12 table = { 13 x86_64-freebsd = import ./bootstrap-files/x86_64-unknown-freebsd.nix; 14 }; 15 files = 16 table.${localSystem.system} 17 or (throw "unsupported platform ${localSystem.system} for the pure FreeBSD stdenv"); 18 in 19 files, 20}: 21 22assert crossSystem == localSystem; 23let 24 inherit (localSystem) system; 25 mkExtraBuildCommands0 = cc: '' 26 rsrc="$out/resource-root" 27 mkdir "$rsrc" 28 ln -s "${lib.getLib cc}/lib/clang/${lib.versions.major cc.version}/include" "$rsrc" 29 echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags 30 ''; 31 mkExtraBuildCommands = 32 cc: compiler-rt: 33 mkExtraBuildCommands0 cc 34 + '' 35 ln -s "${compiler-rt.out}/lib" "$rsrc/lib" 36 ln -s "${compiler-rt.out}/share" "$rsrc/share" 37 ''; 38 39 bootstrapArchive = ( 40 derivation { 41 inherit system; 42 name = "bootstrap-archive"; 43 pname = "bootstrap-archive"; 44 version = "9.9.9"; 45 builder = "${bootstrapFiles.unpack}/libexec/ld-elf.so.1"; 46 args = [ 47 "${bootstrapFiles.unpack}/bin/bash" 48 ./unpack-bootstrap-files.sh 49 ]; 50 LD_LIBRARY_PATH = "${bootstrapFiles.unpack}/lib"; 51 src = bootstrapFiles.unpack; 52 inherit (bootstrapFiles) bootstrapTools; 53 } 54 ); 55 56 linkBootstrap = ( 57 attrs: 58 derivation ( 59 attrs 60 // { 61 inherit system; 62 name = attrs.name or (baseNameOf (builtins.elemAt attrs.paths 0)); 63 src = bootstrapArchive; 64 builder = "${bootstrapArchive}/bin/bash"; 65 # this script will prefer to link files instead of copying them. 66 # this prevents clang in particular, but possibly others, from calling readlink(argv[0]) 67 # and obtaining dependencies, ld(1) in particular, from there instead of $PATH. 68 args = [ ./linkBootstrap.sh ]; 69 PATH = "${bootstrapArchive}/bin"; 70 paths = attrs.paths; 71 } 72 ) 73 ); 74 75 # commented linkBootstrap entries are provided but unused 76 bootstrapTools = { 77 expand-response-params = ""; 78 bsdcp = linkBootstrap { paths = [ "bin/bsdcp" ]; }; 79 patchelf = linkBootstrap { paths = [ "bin/patchelf" ]; }; 80 bashNonInteractive = linkBootstrap { 81 paths = [ 82 "bin/bash" 83 "bin/sh" 84 ]; 85 shell = "bin/bash"; 86 shellPath = "/bin/bash"; 87 }; 88 curl = linkBootstrap { 89 paths = [ 90 "bin/curl" 91 ]; 92 }; 93 llvmPackages = { 94 clang-unwrapped = linkBootstrap { 95 paths = [ 96 "bin/clang" 97 "bin/clang++" 98 "bin/cpp" 99 "lib/clang" 100 ]; 101 # SYNCME: this version number must be synced with the one in make-bootstrap-tools.nix 102 version = "18"; 103 }; 104 libunwind = linkBootstrap { 105 name = "libunwind"; 106 paths = [ 107 "lib/libunwind.a" 108 "lib/libunwind.so" 109 "lib/libunwind.so.1" 110 "lib/libunwind.so.1.0" 111 "lib/libunwind_shared.so" 112 ]; 113 }; 114 }; 115 coreutils = linkBootstrap { 116 name = "coreutils"; 117 paths = map (str: "bin/" + str) [ 118 "base64" 119 "basename" 120 "cat" 121 "chcon" 122 "chgrp" 123 "chmod" 124 "chown" 125 "chroot" 126 "cksum" 127 "comm" 128 "cp" 129 "csplit" 130 "cut" 131 "date" 132 "dd" 133 "df" 134 "dir" 135 "dircolors" 136 "dirname" 137 "du" 138 "echo" 139 "env" 140 "expand" 141 "expr" 142 "factor" 143 "false" 144 "fmt" 145 "fold" 146 "groups" 147 "head" 148 "hostid" 149 "id" 150 "install" 151 "join" 152 "kill" 153 "link" 154 "ln" 155 "logname" 156 "ls" 157 "md5sum" 158 "mkdir" 159 "mkfifo" 160 "mknod" 161 "mktemp" 162 "mv" 163 "nice" 164 "nl" 165 "nohup" 166 "nproc" 167 "numfmt" 168 "od" 169 "paste" 170 "pathchk" 171 "pinky" 172 "pr" 173 "printenv" 174 "printf" 175 "ptx" 176 "pwd" 177 "readlink" 178 "realpath" 179 "rm" 180 "rmdir" 181 "runcon" 182 "seq" 183 "shred" 184 "shuf" 185 "sleep" 186 "sort" 187 "split" 188 "stat" 189 "stdbuf" 190 "stty" 191 "sum" 192 "tac" 193 "tail" 194 "tee" 195 "test" 196 "timeout" 197 "touch" 198 "tr" 199 "true" 200 "truncate" 201 "tsort" 202 "tty" 203 "uname" 204 "unexpand" 205 "uniq" 206 "unlink" 207 "users" 208 "vdir" 209 "wc" 210 "who" 211 "whoami" 212 "yes" 213 "[" 214 ]; 215 }; 216 diffutils = linkBootstrap { 217 name = "diffutils"; 218 paths = map (str: "bin/" + str) [ 219 "diff" 220 "cmp" 221 #"diff3" 222 #"sdiff" 223 ]; 224 }; 225 findutils = linkBootstrap { 226 name = "findutils"; 227 paths = [ 228 "bin/find" 229 "bin/xargs" 230 ]; 231 }; 232 iconv = linkBootstrap { paths = [ "bin/iconv" ]; }; 233 libiconv = linkBootstrap { paths = [ "include/iconv.h" ]; }; 234 patch = linkBootstrap { paths = [ "bin/patch" ]; }; 235 gnutar = linkBootstrap { paths = [ "bin/tar" ]; }; 236 gawk = linkBootstrap { 237 paths = [ 238 "bin/awk" 239 "bin/gawk" 240 ]; 241 }; 242 gnumake = linkBootstrap { paths = [ "bin/make" ]; }; 243 gnugrep = linkBootstrap { 244 paths = [ 245 "bin/grep" 246 "bin/egrep" 247 "bin/fgrep" 248 ]; 249 }; 250 gnused = linkBootstrap { paths = [ "bin/sed" ]; }; 251 gzip = linkBootstrap { 252 paths = [ 253 "bin/gzip" 254 #"bin/gunzip" 255 ]; 256 }; 257 bzip2 = linkBootstrap { 258 paths = [ 259 "bin/bzip2" 260 "lib/libbz2.so" 261 "lib/libbz2.so.1" 262 ]; 263 }; 264 xz = linkBootstrap { 265 paths = [ 266 "bin/xz" 267 "bin/unxz" 268 "lib/liblzma.so" 269 "lib/liblzma.so.5" 270 ]; 271 }; 272 binutils-unwrapped = linkBootstrap { 273 name = "binutils"; 274 paths = map (str: "bin/" + str) [ 275 "ld" 276 #"as" 277 #"addr2line" 278 "ar" 279 #"c++filt" 280 #"elfedit" 281 #"gprof" 282 #"objdump" 283 "nm" 284 "objcopy" 285 "ranlib" 286 "readelf" 287 "size" 288 "strings" 289 "strip" 290 ]; 291 }; 292 freebsd = { 293 locales = linkBootstrap { paths = [ "share/locale" ]; }; 294 libc = linkBootstrap { 295 name = "bootstrapLibs"; 296 paths = [ 297 "lib/Scrt1.o" 298 "lib/crt1.o" 299 "lib/crtbegin.o" 300 "lib/crtbeginS.o" 301 "lib/crtbeginT.o" 302 "lib/crtend.o" 303 "lib/crtendS.o" 304 "lib/crti.o" 305 "lib/crtn.o" 306 "lib/libc++.a" 307 "lib/libc++.so" 308 "lib/libc++.so.1" 309 "lib/libc.a" 310 "lib/libc.so" 311 "lib/libc.so.7" 312 "lib/libc_nonshared.a" 313 "lib/libcrypt.so" 314 "lib/libcrypt.so.5" 315 "lib/libcxxrt.a" 316 "lib/libcxxrt.so" 317 "lib/libcxxrt.so.1" 318 "lib/libdevstat.so" 319 "lib/libdevstat.so.7" 320 "lib/libdl.so" 321 "lib/libdl.so.1" 322 "lib/libelf.so" 323 "lib/libelf.so.2" 324 "lib/libexecinfo.so" 325 "lib/libexecinfo.so.1" 326 "lib/libgcc.a" 327 "lib/libgcc_eh.a" 328 "lib/libgcc_s.so" 329 "lib/libgcc_s.so.1" 330 "lib/libkvm.so" 331 "lib/libkvm.so.7" 332 "lib/libm.a" 333 "lib/libm.so" 334 "lib/libm.so.5" 335 "lib/libmd.so" 336 "lib/libmd.so.6" 337 "lib/libncurses.so" 338 "lib/libncurses.so.6" 339 "lib/libncursesw.so" 340 "lib/libncursesw.so.6" 341 "lib/libpthread.so" 342 "lib/librt.so" 343 "lib/librt.so.1" 344 "lib/libthr.so" 345 "lib/libthr.so.3" 346 "lib/libutil.so" 347 "lib/libutil.so.9" 348 "lib/libxnet.so" 349 "include" 350 "share" 351 "libexec" 352 ]; 353 pname = "libs"; 354 version = "bootstrap"; 355 }; 356 }; 357 }; 358 359 mkStdenv = 360 { 361 name ? "freebsd", 362 overrides ? 363 prevStage: super: self: 364 { }, 365 hascxx ? true, 366 }: 367 prevStage: 368 let 369 bsdcp = 370 prevStage.bsdcp or (prevStage.runCommand "bsdcp" { } 371 "mkdir -p $out/bin; cp ${prevStage.freebsd.cp}/bin/cp $out/bin/bsdcp" 372 ); 373 initialPath = with prevStage; [ 374 coreutils 375 gnutar 376 findutils 377 gnumake 378 gnused 379 patchelf 380 gnugrep 381 gawk 382 diffutils 383 patch 384 bashNonInteractive 385 xz 386 gzip 387 bzip2 388 bsdcp 389 ]; 390 shell = "${prevStage.bashNonInteractive}/bin/bash"; 391 stdenvNoCC = import ../generic { 392 inherit 393 config 394 initialPath 395 shell 396 fetchurlBoot 397 ; 398 name = "stdenvNoCC-${name}"; 399 buildPlatform = localSystem; 400 hostPlatform = localSystem; 401 targetPlatform = localSystem; 402 cc = null; 403 }; 404 fetchurlBoot = import ../../build-support/fetchurl { 405 inherit lib stdenvNoCC; 406 inherit (prevStage) curl; 407 inherit (config) hashedMirrors rewriteURL; 408 }; 409 stdenv = import ../generic { 410 inherit 411 config 412 initialPath 413 shell 414 fetchurlBoot 415 ; 416 name = "stdenv-${name}"; 417 buildPlatform = localSystem; 418 hostPlatform = localSystem; 419 targetPlatform = localSystem; 420 extraNativeBuildInputs = [ 421 ./unpack-source.sh 422 ./always-patchelf.sh 423 ]; 424 cc = lib.makeOverridable (import ../../build-support/cc-wrapper) { 425 inherit lib stdenvNoCC; 426 name = "${name}-cc"; 427 inherit (prevStage.freebsd) libc; 428 inherit (prevStage) gnugrep coreutils expand-response-params; 429 libcxx = prevStage.llvmPackages.libcxx or null; 430 runtimeShell = shell; 431 propagateDoc = false; 432 nativeTools = false; 433 nativeLibc = false; 434 cc = prevStage.llvmPackages.clang-unwrapped; 435 isClang = true; 436 extraPackages = lib.optionals hascxx [ 437 prevStage.llvmPackages.compiler-rt 438 ]; 439 nixSupport = { 440 libcxx-cxxflags = lib.optionals (!hascxx) [ "-isystem ${prevStage.freebsd.libc}/include/c++/v1" ]; 441 }; 442 extraBuildCommands = lib.optionalString hascxx ( 443 mkExtraBuildCommands prevStage.llvmPackages.clang-unwrapped prevStage.llvmPackages.compiler-rt 444 ); 445 bintools = lib.makeOverridable (import ../../build-support/bintools-wrapper) { 446 inherit lib stdenvNoCC; 447 name = "${name}-bintools"; 448 inherit (prevStage.freebsd) libc; 449 inherit (prevStage) gnugrep coreutils expand-response-params; 450 runtimeShell = shell; 451 bintools = (prevStage.llvmPackages or { }).bintools-unwrapped or prevStage.binutils-unwrapped; 452 propagateDoc = false; 453 nativeTools = false; 454 nativeLibc = false; 455 }; 456 }; 457 overrides = overrides prevStage; 458 preHook = '' 459 export NIX_ENFORCE_PURITY="''${NIX_ENFORCE_PURITY-1}" 460 export NIX_ENFORCE_NO_NATIVE="''${NIX_ENFORCE_NO_NATIVE-1}" 461 export PATH_LOCALE=${prevStage.freebsd.localesReal or prevStage.freebsd.locales}/share/locale 462 '' 463 + lib.optionalString (prevStage.freebsd ? libiconvModules) '' 464 export PATH_I18NMODULE=${prevStage.freebsd.libiconvModules}/lib/i18n 465 ''; 466 }; 467 in 468 { 469 inherit config overlays stdenv; 470 }; 471in 472[ 473 ( 474 { }: 475 mkStdenv { 476 name = "freebsd-boot-0"; 477 hascxx = false; 478 overrides = prevStage: self: super: { 479 # this one's goal is to build foundational libs like libc and libcxx. we want to override literally every possible bin package we can with bootstrap tools 480 # we CAN'T import LLVM because the compiler built here is used to build the final compiler and the final compiler must not be built by the bootstrap compiler 481 inherit (bootstrapTools) 482 patchelf 483 bashNonInteractive 484 curl 485 coreutils 486 diffutils 487 findutils 488 iconv 489 libiconv 490 patch 491 gnutar 492 gawk 493 gnumake 494 gnugrep 495 gnused 496 gzip 497 bzip2 498 xz 499 ; 500 binutils-unwrapped = removeAttrs bootstrapTools.binutils-unwrapped [ "src" ]; 501 fetchurl = import ../../build-support/fetchurl { 502 inherit lib; 503 inherit (self) stdenvNoCC; 504 inherit (prevStage) curl; 505 inherit (config) hashedMirrors rewriteURL; 506 }; 507 gettext = super.gettext.overrideAttrs { 508 NIX_CFLAGS_COMPILE = "-DHAVE_ICONV=1"; # we clearly have iconv. what do you want? 509 }; 510 curlReal = super.curl; 511 tzdata = super.tzdata.overrideAttrs { NIX_CFLAGS_COMPILE = "-DHAVE_GETTEXT=0"; }; 512 513 # make it so libcxx/libunwind are built in this stdenv and not the next 514 freebsd = super.freebsd.overrideScope ( 515 self': super': { 516 inherit (prevStage.freebsd) locales; 517 stdenvNoLibcxx = self.overrideCC (self.stdenv // { name = "stdenv-freebsd-boot-0.4"; }) ( 518 self.stdenv.cc.override { 519 name = "freebsd-boot-0.4-cc"; 520 libc = self.freebsd.libc; 521 bintools = self.stdenv.cc.bintools.override { 522 name = "freebsd-boot-0.4-bintools"; 523 libc = self.freebsd.libc; 524 }; 525 } 526 ); 527 } 528 ); 529 llvmPackages = super.llvmPackages // { 530 libcxx = 531 (super.llvmPackages.libcxx.override { 532 stdenv = self.overrideCC (self.stdenv // { name = "stdenv-freebsd-boot-0.5"; }) ( 533 self.stdenv.cc.override { 534 name = "freebsd-boot-0.5-cc"; 535 libc = self.freebsd.libc; 536 bintools = self.stdenv.cc.bintools.override { 537 name = "freebsd-boot-0.5-bintools"; 538 libc = self.freebsd.libc; 539 }; 540 extraPackages = [ 541 self.llvmPackages.compiler-rt 542 ]; 543 extraBuildCommands = mkExtraBuildCommands self.llvmPackages.clang-unwrapped self.llvmPackages.compiler-rt; 544 } 545 ); 546 }).overrideAttrs 547 ( 548 self': super': { 549 NIX_CFLAGS_COMPILE = "-nostdlib++"; 550 NIX_LDFLAGS = "--allow-shlib-undefined"; 551 cmakeFlags = builtins.filter (x: x != "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib") super'.cmakeFlags; 552 } 553 ); 554 }; 555 }; 556 } bootstrapTools 557 ) 558 (mkStdenv { 559 name = "freebsd-boot-1"; 560 overrides = prevStage: self: super: { 561 # this one's goal is to build all the tools that get imported into the final stdenv. 562 # we can import the foundational libs from boot-0 563 # we can import bins and libs that DON'T get imported OR LINKED into the final stdenv from boot-0 564 curl = prevStage.curlReal; 565 inherit (prevStage) 566 fetchurl 567 python3 568 bison 569 perl 570 cmake 571 ninja 572 ; 573 fetchurlReal = super.fetchurl; 574 freebsd = super.freebsd.overrideScope ( 575 self': super': { 576 locales = prevStage.freebsd.locales; 577 localesReal = super'.locales; 578 libc = prevStage.freebsd.libc; 579 } 580 ); 581 llvmPackages = super.llvmPackages // { 582 libcxx = prevStage.llvmPackages.libcxx; 583 }; 584 }; 585 }) 586 (mkStdenv { 587 name = "freebsd"; 588 overrides = prevStage: self: super: { 589 __bootstrapArchive = bootstrapArchive; 590 fetchurl = prevStage.fetchurlReal; 591 freebsd = super.freebsd.overrideScope ( 592 self': super': { localesPrev = prevStage.freebsd.localesReal; } 593 ); 594 }; 595 }) 596]