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