diff options
Diffstat (limited to 'pkgs/os-specific/linux/minimal-bootstrap')
50 files changed, 1842 insertions, 797 deletions
diff --git a/pkgs/os-specific/linux/minimal-bootstrap/bash/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/bash/default.nix index 9c9682fdf9d5..35c4da7acf93 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/bash/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/bash/default.nix @@ -4,15 +4,14 @@ , fetchurl , bootBash , gnumake +, gnupatch , gnused , gnugrep , gnutar , gawk , gzip -, gcc -, glibc -, binutils -, linux-headers +, diffutils +, tinycc , derivationWithMeta , bash , coreutils @@ -25,19 +24,26 @@ let url = "mirror://gnu/bash/bash-${version}.tar.gz"; sha256 = "132qng0jy600mv1fs95ylnlisx2wavkkgpb19c6kmz7lnmjhjwhk"; }; + + patches = [ + # flush output for generated code + ./mksignames-flush.patch + ]; in bootBash.runCommand "${pname}-${version}" { inherit pname version; nativeBuildInputs = [ - gcc - binutils + coreutils + tinycc.compiler gnumake + gnupatch gnused gnugrep gnutar gawk gzip + diffutils ]; passthru.runCommand = name: env: buildCommand: @@ -78,21 +84,23 @@ bootBash.runCommand "${pname}-${version}" { tar xzf ${src} cd bash-${version} + # Patch + ${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches} + # Configure - export CC="gcc -I${glibc}/include -I${linux-headers}/include" - export LIBRARY_PATH="${glibc}/lib" - export LIBS="-lc -lnss_files -lnss_dns -lresolv" - export ac_cv_func_dlopen=no + export CC="tcc -B ${tinycc.libs}/lib" + export AR="tcc -ar" + export LD=tcc bash ./configure \ --prefix=$out \ --build=${buildPlatform.config} \ --host=${hostPlatform.config} \ - --disable-nls \ - --disable-net-redirections + --without-bash-malloc # Build - make SHELL=bash + make -j $NIX_BUILD_CORES SHELL=bash # Install - make install + make -j $NIX_BUILD_CORES install + ln -s bash $out/bin/sh '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/bash/mksignames-flush.patch b/pkgs/os-specific/linux/minimal-bootstrap/bash/mksignames-flush.patch new file mode 100644 index 000000000000..6e64dfa7fa3a --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/bash/mksignames-flush.patch @@ -0,0 +1,10 @@ +--- a/support/mksignames.c ++++ b/support/mksignames.c +@@ -68,6 +68,7 @@ write_signames (stream) + fprintf (stream, "};\n\n"); + fprintf (stream, "#define initialize_signames()\n\n"); + #endif ++ fflush(stream); + } + + int diff --git a/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix index f386ebbaf8e9..71e391efb550 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix @@ -3,35 +3,29 @@ , hostPlatform , fetchurl , bash +, coreutils , gnumake , gnupatch +, gnused , gnugrep -, gnutar , gawk -, bzip2 -, sed -, mesBootstrap ? false, tinycc ? null -, gcc ? null, glibc ? null, binutils ? null, linux-headers +, diffutils +, gnutar +, xz +, tinycc }: -assert mesBootstrap -> tinycc != null; -assert !mesBootstrap -> gcc != null && glibc != null && binutils != null; + let - pname = "binutils" + lib.optionalString mesBootstrap "-mes"; - version = "2.20.1"; - rev = "a"; + # Based on https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a1-static-binutils.nix + pname = "binutils"; + version = "2.41"; src = fetchurl { - url = "mirror://gnu/binutils/binutils-${version}${rev}.tar.bz2"; - sha256 = "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi"; + url = "mirror://gnu/binutils/binutils-${version}.tar.xz"; + hash = "sha256-rppXieI0WeWWBuZxRyPy0//DHAMXQZHvDQFb3wYAdFA="; }; patches = [ - # Enables building binutils using TCC and Mes C Library - (fetchurl { - url = "https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/patches/binutils-boot-2.20.1a.patch?id=50249cab3a98839ade2433456fe618acc6f804a5"; - sha256 = "086sf6an2k56axvs4jlky5n3hs2l3rq8zq5d37h0b69cdyh7igpn"; - }) - # Make binutils output deterministic by default. ./deterministic.patch ]; @@ -40,10 +34,10 @@ let "--prefix=${placeholder "out"}" "--build=${buildPlatform.config}" "--host=${hostPlatform.config}" - "--disable-nls" - "--disable-shared" - "--disable-werror" "--with-sysroot=/" + "--enable-deterministic-archives" + # depends on bison + "--disable-gprofng" # Turn on --enable-new-dtags by default to make the linker set # RUNPATH instead of RPATH on binaries. This is important because @@ -60,15 +54,16 @@ bash.runCommand "${pname}-${version}" { inherit pname version; nativeBuildInputs = [ - (if mesBootstrap then tinycc.compiler else gcc) + tinycc.compiler gnumake gnupatch + gnused gnugrep - gnutar gawk - bzip2 - sed - ] ++ lib.optional (!mesBootstrap) binutils; + diffutils + gnutar + xz + ]; passthru.tests.get-version = result: bash.runCommand "${pname}-get-version-${version}" {} '' @@ -85,32 +80,35 @@ bash.runCommand "${pname}-${version}" { }; } '' # Unpack - cp ${src} binutils.tar.bz2 - bunzip2 binutils.tar.bz2 + cp ${src} binutils.tar.xz + unxz binutils.tar.xz tar xf binutils.tar rm binutils.tar cd binutils-${version} # Patch ${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches} + sed -i 's|/bin/sh|${bash}/bin/bash|' \ + missing install-sh mkinstalldirs + # see libtool's 74c8993c178a1386ea5e2363a01d919738402f30 + sed -i 's/| \$NL2SP/| sort | $NL2SP/' ltmain.sh + # alias makeinfo to true + mkdir aliases + ln -s ${coreutils}/bin/true aliases/makeinfo + export PATH="$(pwd)/aliases/:$PATH" # Configure - ${if mesBootstrap then '' - export CC="tcc -B ${tinycc.libs}/lib -D __GLIBC_MINOR__=6 -D MES_BOOTSTRAP=1" - export AR="tcc -ar" - '' else '' - export CC="gcc -B ${glibc}/lib -I${glibc}/include -I${linux-headers}/include" - export CPP="gcc -E -I${glibc}/include -I${linux-headers}/include" - export AR="ar" - export LIBRARY_PATH="${glibc}/lib" - export LIBS="-lc -lnss_files -lnss_dns -lresolv" - ''} - export SED=sed + export CC="tcc -B ${tinycc.libs}/lib" + export AR="tcc -ar" + export lt_cv_sys_max_cmd_len=32768 + export CFLAGS="-D__LITTLE_ENDIAN__=1" bash ./configure ${lib.concatStringsSep " " configureFlags} # Build - make + make -j $NIX_BUILD_CORES all-libiberty all-gas all-bfd all-libctf all-zlib all-gprof + make all-ld # race condition on ld/.deps/ldwrite.Po, serialize + make -j $NIX_BUILD_CORES # Install - make install + make -j $NIX_BUILD_CORES install '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/bzip2/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/bzip2/default.nix index 84fb7a0a1b73..05da061ac263 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/bzip2/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/bzip2/default.nix @@ -3,7 +3,7 @@ , bash , tinycc , gnumake -, gnupatch +, gnutar , gzip }: let @@ -14,16 +14,6 @@ let url = "https://sourceware.org/pub/bzip2/bzip2-${version}.tar.gz"; sha256 = "0s92986cv0p692icqlw1j42y9nld8zd83qwhzbqd61p1dqbh6nmb"; }; - - patches = [ - # mes libc has no time support, so we remove that. - # It also does not have fch{own,mod}, which we don't care about in the bootstrap - # anyway, so we can null-op those calls. - (fetchurl { - url = "https://github.com/fosslinux/live-bootstrap/raw/87e9d7db9d22b400d1c05247254ac39ee2577e80/sysa/bzip2-1.0.8/patches/mes-libc.patch"; - sha256 = "14dciwib28h413skzfkh7samzh8x87dmwhldyxxphff04pvl1j3c"; - }) - ]; in bash.runCommand "${pname}-${version}" { inherit pname version; @@ -31,13 +21,13 @@ bash.runCommand "${pname}-${version}" { nativeBuildInputs = [ tinycc.compiler gnumake - gnupatch + gnutar gzip ]; passthru.tests.get-version = result: bash.runCommand "${pname}-get-version-${version}" {} '' - ${result}/bin/bzip2 --version --help + ${result}/bin/bzip2 --help mkdir $out ''; @@ -50,21 +40,16 @@ bash.runCommand "${pname}-${version}" { }; } '' # Unpack - cp ${src} bzip2.tar.gz - gunzip bzip2.tar.gz - untar --file bzip2.tar - rm bzip2.tar + tar xzf ${src} cd bzip2-${version} - # Patch - ${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches} - # Build make \ - CC="tcc -B ${tinycc.libs}/lib -I ." \ + -j $NIX_BUILD_CORES \ + CC="tcc -B ${tinycc.libs}/lib" \ AR="tcc -ar" \ bzip2 bzip2recover # Install - make install PREFIX=$out + make install -j $NIX_BUILD_CORES PREFIX=$out '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/coreutils/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/coreutils/default.nix index eb4fe9bcf993..9d7480d239f2 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/coreutils/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/coreutils/default.nix @@ -6,7 +6,7 @@ , gnupatch }: let - pname = "coreutils"; + pname = "bootstrap-coreutils"; version = "5.0"; src = fetchurl { diff --git a/pkgs/os-specific/linux/minimal-bootstrap/coreutils/musl.nix b/pkgs/os-specific/linux/minimal-bootstrap/coreutils/musl.nix new file mode 100644 index 000000000000..14584e0a7e6d --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/coreutils/musl.nix @@ -0,0 +1,74 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, tinycc +, gnumake +, gnugrep +, gnused +, gawk +, gnutar +, gzip +}: +let + pname = "bootstrap-coreutils-musl"; + version = "9.4"; + + src = fetchurl { + url = "mirror://gnu/coreutils/coreutils-${version}.tar.gz"; + hash = "sha256-X2ANkJOXOwr+JTk9m8GMRPIjJlf0yg2V6jHHAutmtzk="; + }; + + configureFlags = [ + "--prefix=${placeholder "out"}" + "--build=${buildPlatform.config}" + "--host=${hostPlatform.config}" + # musl 1.1.x doesn't use 64bit time_t + "--disable-year2038" + # libstdbuf.so fails in static builds + "--enable-no-install-program=stdbuf" + ]; +in +bash.runCommand "${pname}-${version}" { + inherit pname version; + + nativeBuildInputs = [ + tinycc.compiler + gnumake + gnused + gnugrep + gawk + gnutar + gzip + ]; + + passthru.tests.get-version = result: + bash.runCommand "${pname}-get-version-${version}" {} '' + ${result}/bin/cat --version + mkdir $out + ''; + + meta = with lib; { + description = "The GNU Core Utilities"; + homepage = "https://www.gnu.org/software/coreutils"; + license = licenses.gpl3Plus; + maintainers = teams.minimal-bootstrap.members; + platforms = platforms.unix; + }; +} '' + # Unpack + tar xzf ${src} + cd coreutils-${version} + + # Configure + export CC="tcc -B ${tinycc.libs}/lib" + export LD=tcc + bash ./configure ${lib.concatStringsSep " " configureFlags} + + # Build + make -j $NIX_BUILD_CORES AR="tcc -ar" MAKEINFO="true" + + # Install + make -j $NIX_BUILD_CORES install MAKEINFO="true" +'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/default.nix index 2a10a3395ba7..11b7f5b11a6f 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/default.nix @@ -17,71 +17,92 @@ lib.makeScope bash = callPackage ./bash { bootBash = bash_2_05; - gcc = gcc2; - glibc = glibc22; + tinycc = tinycc-musl; + coreutils = coreutils-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; }; binutils = callPackage ./binutils { bash = bash_2_05; - gcc = gcc2; - binutils = binutils-mes; - glibc = glibc22; - sed = heirloom.sed; - }; - binutils-mes = callPackage ./binutils { - bash = bash_2_05; - tinycc = tinycc-mes; - sed = heirloom.sed; - mesBootstrap = true; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; }; bzip2 = callPackage ./bzip2 { bash = bash_2_05; - tinycc = tinycc-mes; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; }; coreutils = callPackage ./coreutils { tinycc = tinycc-mes; }; + coreutils-musl = callPackage ./coreutils/musl.nix { + bash = bash_2_05; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; + }; diffutils = callPackage ./diffutils { bash = bash_2_05; - gcc = gcc2; - glibc = glibc22; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; }; findutils = callPackage ./findutils { bash = bash_2_05; - gcc = gcc2; - glibc = glibc22; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; }; - gawk = callPackage ./gawk { + gawk-mes = callPackage ./gawk/mes.nix { bash = bash_2_05; tinycc = tinycc-mes; gnused = gnused-mes; }; - gcc2 = callPackage ./gcc/2.nix { - bash = bash_2_05; - gcc = gcc2-mes; - binutils = binutils-mes; - glibc = glibc22; - }; - gcc2-mes = callPackage ./gcc/2.nix { + gawk = callPackage ./gawk { bash = bash_2_05; - tinycc = tinycc-mes; - binutils = binutils-mes; - mesBootstrap = true; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; + bootGawk = gawk-mes; }; gcc46 = callPackage ./gcc/4.6.nix { - gcc = gcc2; - glibc = glibc22; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; + # FIXME: not sure why new gawk doesn't work + gawk = gawk-mes; + }; + gcc46-cxx = callPackage ./gcc/4.6.cxx.nix { + gcc = gcc46; + gnumake = gnumake-musl; + gnutar = gnutar-musl; + # FIXME: not sure why new gawk doesn't work + gawk = gawk-mes; }; - inherit (callPackage ./glibc { - bash = bash_2_05; - gnused = gnused-mes; - }) glibc22; + gcc8 = callPackage ./gcc/8.nix { + gcc = gcc46-cxx; + gnumake = gnumake-musl; + gnutar = gnutar-latest; + # FIXME: not sure why new gawk doesn't work + gawk = gawk-mes; + }; + + gcc-latest = callPackage ./gcc/latest.nix { + gcc = gcc8; + gnumake = gnumake-musl; + gnutar = gnutar-latest; + # FIXME: not sure why new gawk doesn't work + gawk = gawk-mes; + }; gnugrep = callPackage ./gnugrep { bash = bash_2_05; @@ -90,26 +111,44 @@ lib.makeScope gnumake = callPackage ./gnumake { tinycc = tinycc-mes; }; + gnumake-musl = callPackage ./gnumake/musl.nix { + bash = bash_2_05; + tinycc = tinycc-musl; + gawk = gawk-mes; + gnumakeBoot = gnumake; + }; + gnupatch = callPackage ./gnupatch { tinycc = tinycc-mes; }; gnused = callPackage ./gnused { bash = bash_2_05; - gcc = gcc2; - glibc = glibc22; + tinycc = tinycc-musl; gnused = gnused-mes; }; - gnused-mes = callPackage ./gnused { + gnused-mes = callPackage ./gnused/mes.nix { bash = bash_2_05; tinycc = tinycc-mes; - mesBootstrap = true; }; - gnutar = callPackage ./gnutar { + gnutar = callPackage ./gnutar/mes.nix { bash = bash_2_05; tinycc = tinycc-mes; gnused = gnused-mes; }; + gnutar-musl = callPackage ./gnutar/musl.nix { + bash = bash_2_05; + tinycc = tinycc-musl; + gnused = gnused-mes; + }; + + # FIXME: better package naming scheme + gnutar-latest = callPackage ./gnutar/latest.nix { + gcc = gcc46; + gnumake = gnumake-musl; + gnutarBoot = gnutar-musl; + }; + gzip = callPackage ./gzip { bash = bash_2_05; tinycc = tinycc-mes; @@ -130,17 +169,33 @@ lib.makeScope mes = lib.recurseIntoAttrs (callPackage ./mes { }); mes-libc = callPackage ./mes/libc.nix { }; + musl11 = callPackage ./musl/1.1.nix { + bash = bash_2_05; + tinycc = tinycc-mes; + gnused = gnused-mes; + }; + + musl = callPackage ./musl { + gcc = gcc46; + gnumake = gnumake-musl; + }; + stage0-posix = callPackage ./stage0-posix { }; inherit (self.stage0-posix) kaem m2libc mescc-tools mescc-tools-extra; tinycc-bootstrappable = lib.recurseIntoAttrs (callPackage ./tinycc/bootstrappable.nix { }); tinycc-mes = lib.recurseIntoAttrs (callPackage ./tinycc/mes.nix { }); + tinycc-musl = lib.recurseIntoAttrs (callPackage ./tinycc/musl.nix { + bash = bash_2_05; + musl = musl11; + }); xz = callPackage ./xz { bash = bash_2_05; - tinycc = tinycc-mes; - inherit (heirloom) sed; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; }; inherit (callPackage ./utils.nix { }) derivationWithMeta writeTextFile writeText; @@ -149,22 +204,28 @@ lib.makeScope echo ${bash.tests.get-version} echo ${bash_2_05.tests.get-version} echo ${binutils.tests.get-version} - echo ${binutils-mes.tests.get-version} echo ${bzip2.tests.get-version} + echo ${coreutils-musl.tests.get-version} echo ${diffutils.tests.get-version} echo ${findutils.tests.get-version} + echo ${gawk-mes.tests.get-version} echo ${gawk.tests.get-version} - echo ${gcc2.tests.get-version} - echo ${gcc2-mes.tests.get-version} echo ${gcc46.tests.get-version} + echo ${gcc46-cxx.tests.hello-world} + echo ${gcc8.tests.hello-world} + echo ${gcc-latest.tests.hello-world} echo ${gnugrep.tests.get-version} echo ${gnused.tests.get-version} echo ${gnused-mes.tests.get-version} echo ${gnutar.tests.get-version} + echo ${gnutar-musl.tests.get-version} + echo ${gnutar-latest.tests.get-version} echo ${gzip.tests.get-version} echo ${heirloom.tests.get-version} echo ${mes.compiler.tests.get-version} + echo ${musl.tests.hello-world} echo ${tinycc-mes.compiler.tests.chain} + echo ${tinycc-musl.compiler.tests.hello-world} echo ${xz.tests.get-version} mkdir ''${out} ''; diff --git a/pkgs/os-specific/linux/minimal-bootstrap/diffutils/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/diffutils/default.nix index 7545a52524a3..24cd643b3497 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/diffutils/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/diffutils/default.nix @@ -3,38 +3,35 @@ , hostPlatform , fetchurl , bash -, gcc -, glibc -, binutils -, linux-headers +, tinycc , gnumake , gnugrep , gnused , gawk , gnutar -, gzip +, xz }: let pname = "diffutils"; - version = "2.8.1"; + # last version that can be built by tinycc-musl 0.9.27 + version = "3.8"; src = fetchurl { - url = "mirror://gnu/diffutils/diffutils-${version}.tar.gz"; - sha256 = "0nizs9r76aiymzasmj1jngl7s71jfzl9xfziigcls8k9n141f065"; + url = "mirror://gnu/diffutils/diffutils-${version}.tar.xz"; + hash = "sha256-pr3X0bMSZtEcT03mwbdI1GB6sCMa9RiPwlM9CuJDj+w="; }; in bash.runCommand "${pname}-${version}" { inherit pname version; nativeBuildInputs = [ - gcc - binutils + tinycc.compiler gnumake gnused gnugrep gawk gnutar - gzip + xz ]; passthru.tests.get-version = result: @@ -52,21 +49,23 @@ bash.runCommand "${pname}-${version}" { }; } '' # Unpack - tar xzf ${src} + cp ${src} diffutils.tar.xz + unxz diffutils.tar.xz + tar xf diffutils.tar + rm diffutils.tar cd diffutils-${version} # Configure - export C_INCLUDE_PATH="${glibc}/include:${linux-headers}/include" - export LIBRARY_PATH="${glibc}/lib" - export LIBS="-lc -lnss_files -lnss_dns -lresolv" + export CC="tcc -B ${tinycc.libs}/lib" + export LD=tcc bash ./configure \ --prefix=$out \ --build=${buildPlatform.config} \ --host=${hostPlatform.config} # Build - make + make -j $NIX_BUILD_CORES AR="tcc -ar" # Install - make install + make -j $NIX_BUILD_CORES install '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/findutils/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/findutils/default.nix index cf26abd21383..97418d218fb9 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/findutils/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/findutils/default.nix @@ -3,38 +3,34 @@ , hostPlatform , fetchurl , bash -, gcc -, glibc -, binutils -, linux-headers +, tinycc , gnumake , gnugrep , gnused , gawk , gnutar -, gzip +, xz }: let pname = "findutils"; - version = "4.4.2"; + version = "4.9.0"; src = fetchurl { - url = "mirror://gnu/findutils/findutils-${version}.tar.gz"; - sha256 = "0amn0bbwqvsvvsh6drfwz20ydc2czk374lzw5kksbh6bf78k4ks3"; + url = "mirror://gnu/findutils/findutils-${version}.tar.xz"; + hash = "sha256-or+4wJ1DZ3DtxZ9Q+kg+eFsWGjt7nVR1c8sIBl/UYv4="; }; in bash.runCommand "${pname}-${version}" { inherit pname version; nativeBuildInputs = [ - gcc - binutils + tinycc.compiler gnumake gnused gnugrep gawk gnutar - gzip + xz ]; passthru.tests.get-version = result: @@ -52,21 +48,28 @@ bash.runCommand "${pname}-${version}" { }; } '' # Unpack - tar xzf ${src} + cp ${src} findutils.tar.xz + unxz findutils.tar.xz + tar xf findutils.tar + rm findutils.tar cd findutils-${version} + # Patch + # configure fails to accurately detect PATH_MAX support + sed -i 's/chdir_long/chdir/' gl/lib/save-cwd.c + # Configure - export C_INCLUDE_PATH="${glibc}/include:${linux-headers}/include" - export LIBRARY_PATH="${glibc}/lib" - export LIBS="-lc -lnss_files -lnss_dns -lresolv" + export CC="tcc -B ${tinycc.libs}/lib" + export AR="tcc -ar" + export LD=tcc bash ./configure \ --prefix=$out \ --build=${buildPlatform.config} \ --host=${hostPlatform.config} # Build - make + make -j $NIX_BUILD_CORES # Install - make install + make -j $NIX_BUILD_CORES install '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gawk/common.nix b/pkgs/os-specific/linux/minimal-bootstrap/gawk/common.nix new file mode 100644 index 000000000000..d95c66d86337 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gawk/common.nix @@ -0,0 +1,11 @@ +{ lib }: + +{ + meta = with lib; { + description = "GNU implementation of the Awk programming language"; + homepage = "https://www.gnu.org/software/gawk"; + license = licenses.gpl3Plus; + maintainers = teams.minimal-bootstrap.members; + platforms = platforms.unix; + }; +} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gawk/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/gawk/default.nix index d840a204416d..879b98bf00c5 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/gawk/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/gawk/default.nix @@ -5,34 +5,33 @@ , bash , tinycc , gnumake -, gnupatch -, gnused , gnugrep +, gnused +, gnutar +, gzip +, bootGawk }: let + inherit (import ./common.nix { inherit lib; }) meta; pname = "gawk"; - # >=3.1.x is incompatible with mes-libc - version = "3.0.6"; + version = "5.2.2"; src = fetchurl { url = "mirror://gnu/gawk/gawk-${version}.tar.gz"; - sha256 = "1z4bibjm7ldvjwq3hmyifyb429rs2d9bdwkvs0r171vv1khpdwmb"; + hash = "sha256-lFrvfM/xAfILIqEIArwAXplKsrjqPnJMwaGXxi9B9lA="; }; - - patches = [ - # for reproducibility don't generate date stamp - ./no-stamp.patch - ]; in bash.runCommand "${pname}-${version}" { - inherit pname version; + inherit pname version meta; nativeBuildInputs = [ tinycc.compiler gnumake - gnupatch gnused gnugrep + gnutar + gzip + bootGawk ]; passthru.tests.get-version = result: @@ -40,38 +39,23 @@ bash.runCommand "${pname}-${version}" { ${result}/bin/awk --version mkdir $out ''; - - meta = with lib; { - description = "GNU implementation of the Awk programming language"; - homepage = "https://www.gnu.org/software/gawk"; - license = licenses.gpl3Plus; - maintainers = teams.minimal-bootstrap.members; - platforms = platforms.unix; - }; } '' # Unpack - ungz --file ${src} --output gawk.tar - untar --file gawk.tar - rm gawk.tar + tar xzf ${src} cd gawk-${version} - # Patch - ${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches} - # Configure export CC="tcc -B ${tinycc.libs}/lib" - export ac_cv_func_getpgrp_void=yes - export ac_cv_func_tzset=yes + export AR="tcc -ar" + export LD=tcc bash ./configure \ + --prefix=$out \ --build=${buildPlatform.config} \ - --host=${hostPlatform.config} \ - --disable-nls \ - --prefix=$out + --host=${hostPlatform.config} # Build - make gawk + make -j $NIX_BUILD_CORES # Install - install -D gawk $out/bin/gawk - ln -s gawk $out/bin/awk + make -j $NIX_BUILD_CORES install '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gawk/mes.nix b/pkgs/os-specific/linux/minimal-bootstrap/gawk/mes.nix new file mode 100644 index 000000000000..c14399309306 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gawk/mes.nix @@ -0,0 +1,70 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, tinycc +, gnumake +, gnupatch +, gnused +, gnugrep +}: +let + inherit (import ./common.nix { inherit lib; }) meta; + pname = "gawk-mes"; + # >=3.1.x is incompatible with mes-libc + version = "3.0.6"; + + src = fetchurl { + url = "mirror://gnu/gawk/gawk-${version}.tar.gz"; + sha256 = "1z4bibjm7ldvjwq3hmyifyb429rs2d9bdwkvs0r171vv1khpdwmb"; + }; + + patches = [ + # for reproducibility don't generate date stamp + ./no-stamp.patch + ]; +in +bash.runCommand "${pname}-${version}" { + inherit pname version meta; + + nativeBuildInputs = [ + tinycc.compiler + gnumake + gnupatch + gnused + gnugrep + ]; + + passthru.tests.get-version = result: + bash.runCommand "${pname}-get-version-${version}" {} '' + ${result}/bin/awk --version + mkdir $out + ''; +} '' + # Unpack + ungz --file ${src} --output gawk.tar + untar --file gawk.tar + rm gawk.tar + cd gawk-${version} + + # Patch + ${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches} + + # Configure + export CC="tcc -B ${tinycc.libs}/lib" + export ac_cv_func_getpgrp_void=yes + export ac_cv_func_tzset=yes + bash ./configure \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} \ + --disable-nls \ + --prefix=$out + + # Build + make gawk + + # Install + install -D gawk $out/bin/gawk + ln -s gawk $out/bin/awk +'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gcc/2.nix b/pkgs/os-specific/linux/minimal-bootstrap/gcc/2.nix deleted file mode 100644 index c879fd30aaf6..000000000000 --- a/pkgs/os-specific/linux/minimal-bootstrap/gcc/2.nix +++ /dev/null @@ -1,140 +0,0 @@ -{ lib -, buildPlatform -, hostPlatform -, fetchurl -, bash -, gnumake -, gnupatch -, gnugrep -, gnutar -, gzip -, heirloom -, binutils -, mesBootstrap ? false, tinycc ? null, mes-libc -, gcc ? null, glibc ? null, linux-headers -}: -assert mesBootstrap -> tinycc != null; -assert !mesBootstrap -> gcc != null && glibc != null; -let - # Gcc-2.95.3 is the most recent GCC that is supported by what the Mes C - # Library v0.16 offers. Gcc-3.x (and 4.x) place higher demands on a C - # library, such as dir.h/struct DIR/readdir, locales, signals... Also, - # with gcc-2.95.3, binutils (2.14.0, 2.20.1a) and glibc-2.2.5 we found a - # GNU toolchain triplet "that works". - # - from guix/gnu/packages/commencement.scm - pname = "gcc" + lib.optionalString mesBootstrap "-mes"; - version = "2.95.3"; - - src = fetchurl { - url = "mirror://gnu/gcc/gcc-${version}/gcc-core-${version}.tar.gz"; - sha256 = "1xvfy4pqhrd5v2cv8lzf63iqg92k09g6z9n2ah6ndd4h17k1x0an"; - }; - - patches = [ - # This patch enables building gcc-2.95.3 using TCC and Mes C Library. - # * Disable building DOC - # * Avoid running `fixproto'. - # * Force running `fixinc'. - # * Replace Makefile trickery of creating an libgcc1.a archive, then - # extracting the .o files later to create a new libgcc2.a archive. - # Instead, keep temporary .o files. - (fetchurl { - url = "https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/patches/gcc-boot-2.95.3.patch?id=50249cab3a98839ade2433456fe618acc6f804a5"; - sha256 = "03l3jaxch6d76mx4zkn6ky64paj58jk0biddck01qd4bnw9z8hiw"; - }) - ]; - - makeFlags = [ - "LANGUAGES=c" - ] ++ lib.optionals mesBootstrap [ - "LIBGCC2_INCLUDES=\"-I ${mes-libc}/include\"" - "BOOT_LDFLAGS=\" -B ${tinycc.libs}/lib\"" - ] ++ lib.optionals (!mesBootstrap) [ - "LIBGCC2_INCLUDES=\"-I ${glibc}/include -I ${linux-headers}/include\"" - ]; -in -bash.runCommand "${pname}-${version}" { - inherit pname version; - - nativeBuildInputs = [ - (if mesBootstrap then tinycc.compiler else gcc) - gnumake - gnupatch - gnugrep - gnutar - gzip - heirloom.sed - binutils - ]; - - passthru.tests.get-version = result: - bash.runCommand "${pname}-get-version-${version}" {} '' - ${result}/bin/gcc --version - mkdir $out - ''; - - meta = with lib; { - description = "GNU Compiler Collection, version ${version}"; - homepage = "https://gcc.gnu.org"; - license = licenses.gpl3Plus; - maintainers = teams.minimal-bootstrap.members; - platforms = platforms.unix; - }; -} '' - # Unpack - tar xzf ${src} - cd gcc-${version} - - # Patch - ${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches} - # /build/glibc-2.2.5/intl/loadmsgcat.c:334: multiple definition of `_nl_load_domain' - # ../intl/libintl.a(loadmsgcat.o):/build/gcc-2.95.3/texinfo/intl/loadmsgcat.c:66: first defined here - rm -R texinfo - mkdir -p texinfo - echo 'all:'>texinfo/Makefile.in - echo 'install:'>>texinfo/Makefile.in - - # Configure - ${if mesBootstrap then '' - export CC="tcc -B ${tinycc.libs}/lib -D __GLIBC_MINOR__=6" - export CPP="tcc -E" - export ac_cv_func_setlocale=no - '' else '' - export CC="gcc -I${glibc}/include -I${linux-headers}/include -I${gcc}/lib/gcc-lib/${hostPlatform.config}/${version}/include" - export CPP="gcc -E -I${glibc}/include -I${linux-headers}/include -I${gcc}/lib/gcc-lib/${hostPlatform.config}/${version}/include" - export LIBRARY_PATH="${glibc}/lib" - export LIBS="-lc -lnss_files -lnss_dns -lresolv" - ''} - export OLDCC="$CC" - export CC_FOR_BUILD="$CC" - export AR=ar - export RANLIB=ranlib - export ac_cv_c_float_format='IEEE (little-endian)' - bash ./configure \ - --build=${buildPlatform.config} \ - --host=${hostPlatform.config} \ - --enable-static \ - --disable-shared \ - --disable-werror \ - --prefix=$out - # no info at this stage - touch gcc/cpp.info gcc/gcc.info - - # Build - make ${lib.concatStringsSep " " makeFlags} - - # Install - make install - mkdir tmp - cd tmp - ar x ../gcc/libgcc2.a - ${lib.optionalString mesBootstrap "ar x ${tinycc.libs}/lib/libtcc1.a"} - ar r $out/lib/gcc-lib/${hostPlatform.config}/${version}/libgcc.a *.o - cd .. - cp gcc/libgcc2.a $out/lib/libgcc2.a - ${lib.optionalString mesBootstrap '' - ar x ${tinycc.libs}/lib/libtcc1.a - ar x ${tinycc.libs}/lib/libc.a - ar r $out/lib/gcc-lib/${hostPlatform.config}/${version}/libc.a libc.o libtcc1.o - ''} -'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gcc/4.6.cxx.nix b/pkgs/os-specific/linux/minimal-bootstrap/gcc/4.6.cxx.nix new file mode 100644 index 000000000000..277c5e82cc3d --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gcc/4.6.cxx.nix @@ -0,0 +1,140 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, coreutils +, gcc +, musl +, binutils +, gnumake +, gnupatch +, gnused +, gnugrep +, gawk +, diffutils +, findutils +, gnutar +, gzip +}: +let + pname = "gcc-cxx"; + version = "4.6.4"; + + src = fetchurl { + url = "mirror://gnu/gcc/gcc-${version}/gcc-core-${version}.tar.gz"; + sha256 = "173kdb188qg79pcz073cj9967rs2vzanyjdjyxy9v0xb0p5sad75"; + }; + + ccSrc = fetchurl { + url = "mirror://gnu/gcc/gcc-${version}/gcc-g++-${version}.tar.gz"; + sha256 = "1fqqk5zkmdg4vmqzdmip9i42q6b82i3f6yc0n86n9021cr7ms2k9"; + }; + + gmpVersion = "4.3.2"; + gmp = fetchurl { + url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.gz"; + sha256 = "15rwq54fi3s11izas6g985y9jklm3xprfsmym3v1g6xr84bavqvv"; + }; + + mpfrVersion = "2.4.2"; + mpfr = fetchurl { + url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.gz"; + sha256 = "0dxn4904dra50xa22hi047lj8kkpr41d6vb9sd4grca880c7wv94"; + }; + + mpcVersion = "1.0.3"; + mpc = fetchurl { + url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz"; + sha256 = "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"; + }; + + patches = [ + # Remove hardcoded NATIVE_SYSTEM_HEADER_DIR + ./no-system-headers.patch + ]; +in +bash.runCommand "${pname}-${version}" { + inherit pname version; + + nativeBuildInputs = [ + gcc + binutils + gnumake + gnupatch + gnused + gnugrep + gawk + diffutils + findutils + gnutar + gzip + ]; + + passthru.tests.hello-world = result: + bash.runCommand "${pname}-simple-program-${version}" { + nativeBuildInputs = [ binutils musl result ]; + } '' + cat <<EOF >> test.c + #include <stdio.h> + int main() { + printf("Hello World!\n"); + return 0; + } + EOF + musl-gcc -o test test.c + ./test + mkdir $out + ''; + + meta = with lib; { + description = "GNU Compiler Collection, version ${version}"; + homepage = "https://gcc.gnu.org"; + license = licenses.gpl3Plus; + maintainers = teams.minimal-bootstrap.members; + platforms = platforms.unix; + }; +} '' + # Unpack + tar xzf ${src} + tar xzf ${ccSrc} + tar xzf ${gmp} + tar xzf ${mpfr} + tar xzf ${mpc} + cd gcc-${version} + + ln -s ../gmp-${gmpVersion} gmp + ln -s ../mpfr-${mpfrVersion} mpfr + ln -s ../mpc-${mpcVersion} mpc + + # Patch + ${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches} + # doesn't recognise musl + sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host + + # Configure + export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" + export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" + export C_INCLUDE_PATH="${musl}/include" + export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH" + export LIBRARY_PATH="${musl}/lib" + + bash ./configure \ + --prefix=$out \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} \ + --with-native-system-header-dir=${musl}/include \ + --with-build-sysroot=${musl} \ + --enable-languages=c,c++ \ + --disable-bootstrap \ + --disable-libmudflap \ + --disable-libstdcxx-pch \ + --disable-lto \ + --disable-multilib + + # Build + make -j $NIX_BUILD_CORES + + # Install + make -j $NIX_BUILD_CORES install +'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gcc/4.6.nix b/pkgs/os-specific/linux/minimal-bootstrap/gcc/4.6.nix index ce348352b67e..8b56dff58829 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/gcc/4.6.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/gcc/4.6.nix @@ -3,9 +3,7 @@ , hostPlatform , fetchurl , bash -, gcc -, glibc -, linux-headers +, tinycc , binutils , gnumake , gnupatch @@ -31,24 +29,6 @@ let sha256 = "1fqqk5zkmdg4vmqzdmip9i42q6b82i3f6yc0n86n9021cr7ms2k9"; }; - patches = [ - # This patch enables building gcc-4.6.4 using gcc-2.95.3 and glibc-2.2.5 - # * Tweak Makefile to allow overriding NATIVE_SYSTEM_HEADER_DIR using #:makeflags - # * Add missing limits.h include. - # * Add SSIZE_MAX define. The SSIZE_MAX define has been added to Mes - # upstream and can be removed with the next Mes release. - # * Remove -fbuilding-libgcc flag, it assumes features being present from a - # newer gcc or glibc. - # * [MES_BOOTSTRAP_GCC]: Disable threads harder. - (fetchurl { - url = "https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/patches/gcc-boot-4.6.4.patch?id=50249cab3a98839ade2433456fe618acc6f804a5"; - sha256 = "1zzd8gnihw6znrgb6c6pfsmm0vix89xw3giv1nnsykm57j0v3z0d"; - }) - ./libstdc++-target.patch - ]; - - # To reduce the set of pre-built bootstrap inputs, build - # GMP & co. from GCC. gmpVersion = "4.3.2"; gmp = fetchurl { url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.gz"; @@ -66,12 +46,17 @@ let url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz"; sha256 = "1hzci2zrrd7v3g1jk35qindq05hbl0bhjcyyisq9z209xb3fqzb1"; }; + + patches = [ + # Remove hardcoded NATIVE_SYSTEM_HEADER_DIR + ./no-system-headers.patch + ]; in bash.runCommand "${pname}-${version}" { inherit pname version; nativeBuildInputs = [ - gcc + tinycc.compiler binutils gnumake gnupatch @@ -84,10 +69,6 @@ bash.runCommand "${pname}-${version}" { gzip ]; - # condition in ./libcpp/configure requires `env` which is not available in this coreutils - am_cv_CXX_dependencies_compiler_type = "gcc"; - am_cv_CC_dependencies_compiler_type = "gcc"; - passthru.tests.get-version = result: bash.runCommand "${pname}-get-version-${version}" {} '' ${result}/bin/gcc --version @@ -118,18 +99,21 @@ bash.runCommand "${pname}-${version}" { ${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches} # Configure - export C_INCLUDE_PATH="${gcc}/lib/gcc-lib/${hostPlatform.config}/${gcc.version}/include:${linux-headers}/include:${glibc}/include:$(pwd)/mpfr/src" + export CC="tcc -B ${tinycc.libs}/lib" + export C_INCLUDE_PATH="${tinycc.libs}/include:$(pwd)/mpfr/src" export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH" - export LDFLAGS="-B${glibc}/lib -Wl,-dynamic-linker -Wl,${glibc}" - export LDFLAGS_FOR_TARGET=$LDFLAGS - export LIBRARY_PATH="${glibc}/lib:${gcc}/lib" - export LIBS="-lc -lnss_files -lnss_dns -lresolv" + + # Avoid "Link tests are not allowed after GCC_NO_EXECUTABLES" + export lt_cv_shlibpath_overrides_runpath=yes + export ac_cv_func_memcpy=yes + export ac_cv_func_strerror=yes + bash ./configure \ --prefix=$out \ --build=${buildPlatform.config} \ --host=${hostPlatform.config} \ - --with-native-system-header-dir=${glibc}/include \ - --with-build-sysroot=${glibc}/include \ + --with-native-system-header-dir=${tinycc.libs}/include \ + --with-build-sysroot=${tinycc.libs}/include \ --disable-bootstrap \ --disable-decimal-float \ --disable-libatomic \ @@ -146,7 +130,7 @@ bash.runCommand "${pname}-${version}" { --disable-multilib \ --disable-plugin \ --disable-threads \ - --enable-languages=c,c++ \ + --enable-languages=c \ --enable-static \ --disable-shared \ --enable-threads=single \ @@ -154,8 +138,8 @@ bash.runCommand "${pname}-${version}" { --disable-build-with-cxx # Build - make + make -j $NIX_BUILD_CORES # Install - make install + make -j $NIX_BUILD_CORES install '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gcc/8.nix b/pkgs/os-specific/linux/minimal-bootstrap/gcc/8.nix new file mode 100644 index 000000000000..ea9fdaf8854a --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gcc/8.nix @@ -0,0 +1,141 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, coreutils +, gcc +, musl +, binutils +, gnumake +, gnused +, gnugrep +, gawk +, diffutils +, findutils +, gnutar +, gzip +, bzip2 +, xz +}: +let + pname = "gcc"; + version = "8.5.0"; + + src = fetchurl { + url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz"; + hash = "sha256-0wiEGlEbuDCmEAOXsAQtskzhH2Qtq26m7kSELlMl7VA="; + }; + + # last version to compile with gcc 4.6 + gmpVersion = "6.2.1"; + gmp = fetchurl { + url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.xz"; + hash = "sha256-/UgpkSzd0S+EGBw0Ucx1K+IkZD6H+sSXtp7d2txJtPI="; + }; + + mpfrVersion = "4.2.1"; + mpfr = fetchurl { + url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.xz"; + hash = "sha256-J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I="; + }; + + mpcVersion = "1.3.1"; + mpc = fetchurl { + url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz"; + hash = "sha256-q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg="; + }; + + islVersion = "0.24"; + isl = fetchurl { + url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${islVersion}.tar.bz2"; + hash = "sha256-/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA="; + }; +in +bash.runCommand "${pname}-${version}" { + inherit pname version; + + nativeBuildInputs = [ + gcc + binutils + gnumake + gnused + gnugrep + gawk + diffutils + findutils + gnutar + gzip + bzip2 + xz + ]; + + passthru.tests.hello-world = result: + bash.runCommand "${pname}-simple-program-${version}" { + nativeBuildInputs = [ binutils musl result ]; + } '' + cat <<EOF >> test.c + #include <stdio.h> + int main() { + printf("Hello World!\n"); + return 0; + } + EOF + musl-gcc -o test test.c + ./test + mkdir $out + ''; + + meta = with lib; { + description = "GNU Compiler Collection, version ${version}"; + homepage = "https://gcc.gnu.org"; + license = licenses.gpl3Plus; + maintainers = teams.minimal-bootstrap.members; + platforms = platforms.unix; + }; +} '' + # Unpack + tar xf ${src} + tar xf ${gmp} + tar xf ${mpfr} + tar xf ${mpc} + tar xf ${isl} + cd gcc-${version} + + ln -s ../gmp-${gmpVersion} gmp + ln -s ../mpfr-${mpfrVersion} mpfr + ln -s ../mpc-${mpcVersion} mpc + ln -s ../isl-${islVersion} isl + + # Patch + # doesn't recognise musl + sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host + + # Configure + export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" + export CXX="g++ -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" + export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" + export C_INCLUDE_PATH="${musl}/include" + export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH" + export LIBRARY_PATH="${musl}/lib" + + bash ./configure \ + --prefix=$out \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} \ + --with-native-system-header-dir=/include \ + --with-sysroot=${musl} \ + --enable-languages=c,c++ \ + --disable-bootstrap \ + --disable-libmpx \ + --disable-libsanitizer \ + --disable-lto \ + --disable-multilib \ + --disable-plugin + + # Build + make -j $NIX_BUILD_CORES + + # Install + make -j $NIX_BUILD_CORES install-strip +'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gcc/latest.nix b/pkgs/os-specific/linux/minimal-bootstrap/gcc/latest.nix new file mode 100644 index 000000000000..fba3b731a004 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gcc/latest.nix @@ -0,0 +1,137 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, coreutils +, gcc +, musl +, binutils +, gnumake +, gnused +, gnugrep +, gawk +, diffutils +, findutils +, gnutar +, gzip +, bzip2 +, xz +}: +let + pname = "gcc"; + version = "13.2.0"; + + src = fetchurl { + url = "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz"; + hash = "sha256-4nXnZEKmBnNBon8Exca4PYYTFEAEwEE1KIY9xrXHQ9o="; + }; + + gmpVersion = "6.3.0"; + gmp = fetchurl { + url = "mirror://gnu/gmp/gmp-${gmpVersion}.tar.xz"; + hash = "sha256-o8K4AgG4nmhhb0rTC8Zq7kknw85Q4zkpyoGdXENTiJg="; + }; + + mpfrVersion = "4.2.1"; + mpfr = fetchurl { + url = "mirror://gnu/mpfr/mpfr-${mpfrVersion}.tar.xz"; + hash = "sha256-J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I="; + }; + + mpcVersion = "1.3.1"; + mpc = fetchurl { + url = "mirror://gnu/mpc/mpc-${mpcVersion}.tar.gz"; + hash = "sha256-q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg="; + }; + + islVersion = "0.24"; + isl = fetchurl { + url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${islVersion}.tar.bz2"; + hash = "sha256-/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA="; + }; +in +bash.runCommand "${pname}-${version}" { + inherit pname version; + + nativeBuildInputs = [ + gcc + binutils + gnumake + gnused + gnugrep + gawk + diffutils + findutils + gnutar + gzip + bzip2 + xz + ]; + + passthru.tests.hello-world = result: + bash.runCommand "${pname}-simple-program-${version}" { + nativeBuildInputs = [ binutils musl result ]; + } '' + cat <<EOF >> test.c + #include <stdio.h> + int main() { + printf("Hello World!\n"); + return 0; + } + EOF + musl-gcc -o test test.c + ./test + mkdir $out + ''; + + meta = with lib; { + description = "GNU Compiler Collection, version ${version}"; + homepage = "https://gcc.gnu.org"; + license = licenses.gpl3Plus; + maintainers = teams.minimal-bootstrap.members; + platforms = platforms.unix; + }; +} '' + # Unpack + tar xf ${src} + tar xf ${gmp} + tar xf ${mpfr} + tar xf ${mpc} + tar xf ${isl} + cd gcc-${version} + + ln -s ../gmp-${gmpVersion} gmp + ln -s ../mpfr-${mpfrVersion} mpfr + ln -s ../mpc-${mpcVersion} mpc + ln -s ../isl-${islVersion} isl + + # Patch + # force musl even if host triple is gnu + sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host + + # Configure + export CC="gcc -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" + export CXX="g++ -Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" + export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${musl}/lib/libc.so" + export LIBRARY_PATH="${musl}/lib" + + bash ./configure \ + --prefix=$out \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} \ + --with-native-system-header-dir=/include \ + --with-sysroot=${musl} \ + --enable-languages=c,c++ \ + --disable-bootstrap \ + --disable-libsanitizer \ + --disable-lto \ + --disable-multilib \ + --disable-plugin + + # Build + make -j $NIX_BUILD_CORES + + # Install + make -j $NIX_BUILD_CORES install-strip +'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gcc/libstdc++-target.patch b/pkgs/os-specific/linux/minimal-bootstrap/gcc/libstdc++-target.patch deleted file mode 100644 index fb622b395806..000000000000 --- a/pkgs/os-specific/linux/minimal-bootstrap/gcc/libstdc++-target.patch +++ /dev/null @@ -1,32 +0,0 @@ -Patch to make the target libraries 'configure' scripts find the proper CPP. -I noticed that building the mingw32 cross compiler. -Looking at the build script for mingw in archlinux, I think that only nixos -needs this patch. I don't know why. -diff --git a/Makefile.in b/Makefile.in -index 93f66b6..d691917 100644 ---- a/Makefile.in -+++ b/Makefile.in -@@ -266,6 +266,7 @@ BASE_TARGET_EXPORTS = \ - AR="$(AR_FOR_TARGET)"; export AR; \ - AS="$(COMPILER_AS_FOR_TARGET)"; export AS; \ - CC="$(CC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CC; \ -+ CPP="$(CC_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS -E"; export CC; \ - CFLAGS="$(CFLAGS_FOR_TARGET)"; export CFLAGS; \ - CONFIG_SHELL="$(SHELL)"; export CONFIG_SHELL; \ - CPPFLAGS="$(CPPFLAGS_FOR_TARGET)"; export CPPFLAGS; \ -@@ -291,11 +292,13 @@ BASE_TARGET_EXPORTS = \ - RAW_CXX_TARGET_EXPORTS = \ - $(BASE_TARGET_EXPORTS) \ - CXX_FOR_TARGET="$(RAW_CXX_FOR_TARGET)"; export CXX_FOR_TARGET; \ -- CXX="$(RAW_CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; -+ CXX="$(RAW_CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; \ -+ CXXCPP="$(RAW_CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS -E"; export CXX; - - NORMAL_TARGET_EXPORTS = \ - $(BASE_TARGET_EXPORTS) \ -- CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; -+ CXX="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS"; export CXX; \ -+ CXXCPP="$(CXX_FOR_TARGET) $(XGCC_FLAGS_FOR_TARGET) $$TFLAGS -E"; export CXX; - - # Where to find GMP - HOST_GMPLIBS = @gmplibs@ diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gcc/no-system-headers.patch b/pkgs/os-specific/linux/minimal-bootstrap/gcc/no-system-headers.patch new file mode 100644 index 000000000000..318553bf916b --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gcc/no-system-headers.patch @@ -0,0 +1,11 @@ +--- a/gcc/Makefile.in ++++ b/gcc/Makefile.in +@@ -440,7 +440,7 @@ LINKER_PLUGIN_API_H = $(srcdir)/../include/plugin-api.h + LTO_SYMTAB_H = $(srcdir)/../include/lto-symtab.h + + # Default native SYSTEM_HEADER_DIR, to be overridden by targets. +-NATIVE_SYSTEM_HEADER_DIR = /usr/include ++# NATIVE_SYSTEM_HEADER_DIR = /usr/include + # Default cross SYSTEM_HEADER_DIR, to be overridden by targets. + CROSS_SYSTEM_HEADER_DIR = @CROSS_SYSTEM_HEADER_DIR@ + diff --git a/pkgs/os-specific/linux/minimal-bootstrap/glibc/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/glibc/default.nix deleted file mode 100644 index 5c4ff386add5..000000000000 --- a/pkgs/os-specific/linux/minimal-bootstrap/glibc/default.nix +++ /dev/null @@ -1,121 +0,0 @@ -{ lib -, buildPlatform -, hostPlatform -, fetchurl -, bash -, gcc2-mes -, gnumake -, gnupatch -, gnused -, gnugrep -, gnutar -, gzip -, gawk -, heirloom -, binutils-mes -, linux-headers -}: -let - pname = "glibc"; - - buildGlibc = { version, src, patches, configureFlags, gcc, binutils, CC, CPP }: - bash.runCommand "${pname}-${version}" { - inherit pname version; - - nativeBuildInputs = [ - gcc - gnumake - gnupatch - gnused - gnugrep - gnutar - gzip - gawk - binutils - ]; - - meta = with lib; { - description = "The GNU C Library"; - homepage = "https://www.gnu.org/software/libc"; - license = licenses.lgpl2Plus; - maintainers = teams.minimal-bootstrap.members; - platforms = platforms.linux; - }; - } '' - # Unpack - tar xzf ${src} - cd glibc-${version} - - # Patch - ${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches} - - # Configure - export CC="${CC}" - export CPP="${CPP}" - bash ./configure --prefix=$out ${lib.concatStringsSep " " ( - [ - "--build=${buildPlatform.config}" - "--host=${hostPlatform.config}" - "--with-headers=${linux-headers}/include" - "--enable-static" - "--disable-shared" - ] ++ configureFlags)} - - # Build - make - - # Install - # GNU sed w/ mes-libc crashes on certain stdio actions - export PATH="${heirloom.sed}/bin:$PATH" - make install - ''; -in -{ - glibc22 = buildGlibc rec { - # GNU C Library 2.2.5 is the most recent glibc that we managed to build - # using gcc-2.95.3. Newer versions (2.3.x, 2.6, 2.1x) seem to need a newer - # gcc. - # - from guix/gnu/packages/commencement.scm - version = "2.2.5"; - src = fetchurl { - url = "mirror://gnu/glibc/glibc-${version}.tar.gz"; - sha256 = "1vl48i16gx6h68whjyhgnn1s57vqq32f9ygfa2fls7pdkbsqvp2q"; - }; - - patches = [ - # This patch enables building glibc-2.2.5 using TCC and GNU Make 4.x and Mes C Library. - # * Makefile: Do not assemble from stdin, use file indirection. - # * Makefile: Add new target: install-lib-all. - # * Makefile: Avoid building stub DOC. - # * [_LIBC_REENTRANT]: Add missing guarding. - # * [MES_BOOTSTRAP]: Disable some GCC extensions. - # * [MES_BOOTSTRAP]: Add missing GCC div/mod defines. - (fetchurl { - url = "https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/patches/glibc-boot-${version}.patch?id=50249cab3a98839ade2433456fe618acc6f804a5"; - sha256 = "1nyz2dr9g7scqwwygd6jvbl7xxpwh11ryvgdz8aikkkna02q1pm8"; - }) - # We want to allow builds in chroots that lack /bin/sh. Thus, system(3) - # and popen(3) need to be tweaked to use the right shell. For the bootstrap - # glibc, we just use whatever `sh' can be found in $PATH. The final glibc - # instead uses the hard-coded absolute file name of `bash'. - (fetchurl { - url = "https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/patches/glibc-bootstrap-system-${version}.patch?id=50249cab3a98839ade2433456fe618acc6f804a5"; - sha256 = "1l67w9rysrlsg2i0r210qxxn37h2969ba9lx7pp3ywlnikvi98m8"; - }) - ]; - - configureFlags = [ - "--disable-sanity-checks" - "--enable-static-nss" - "--without-__thread" - "--without-cvs" - "--without-gd" - "--without-tls" - ]; - - gcc = gcc2-mes; - binutils = binutils-mes; - CC = "gcc -D MES_BOOTSTRAP=1 -D BOOTSTRAP_GLIBC=1 -L $(pwd)"; - CPP = "gcc -E -D MES_BOOTSTRAP=1 -D BOOTSTRAP_GLIBC=1"; - }; -} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnumake/musl.nix b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/musl.nix new file mode 100644 index 000000000000..504095732e8c --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/musl.nix @@ -0,0 +1,82 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, tinycc +, gnumakeBoot +, gnupatch +, gnused +, gnugrep +, gawk +, gnutar +, gzip +}: +let + pname = "gnumake-musl"; + version = "4.4.1"; + + src = fetchurl { + url = "mirror://gnu/make/make-${version}.tar.gz"; + hash = "sha256-3Rb7HWe/q3mnL16DkHNcSePo5wtJRaFasfgd23hlj7M="; + }; + + patches = [ + # Replaces /bin/sh with sh, see patch file for reasoning + ./0001-No-impure-bin-sh.patch + # Purity: don't look for library dependencies (of the form `-lfoo') in /lib + # and /usr/lib. It's a stupid feature anyway. Likewise, when searching for + # included Makefiles, don't look in /usr/include and friends. + ./0002-remove-impure-dirs.patch + ]; +in +bash.runCommand "${pname}-${version}" { + inherit pname version; + + nativeBuildInputs = [ + tinycc.compiler + gnumakeBoot + gnupatch + gnused + gnugrep + gawk + gnutar + gzip + ]; + + passthru.tests.get-version = result: + bash.runCommand "${pname}-get-version-${version}" {} '' + ${result}/bin/make --version + mkdir $out + ''; + + meta = with lib; { + description = "A tool to control the generation of non-source files from sources"; + homepage = "https://www.gnu.org/software/make"; + license = licenses.gpl3Plus; + maintainers = teams.minimal-bootstrap.members; + mainProgram = "make"; + platforms = platforms.unix; + }; +} '' + # Unpack + tar xzf ${src} + cd make-${version} + + # Patch + ${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches} + + # Configure + export CC="tcc -B ${tinycc.libs}/lib" + export LD=tcc + bash ./configure \ + --prefix=$out \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} + + # Build + make AR="tcc -ar" + + # Install + make install +'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnused/common.nix b/pkgs/os-specific/linux/minimal-bootstrap/gnused/common.nix new file mode 100644 index 000000000000..658f05923ac3 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnused/common.nix @@ -0,0 +1,12 @@ +{ lib }: + +{ + meta = with lib; { + description = "GNU sed, a batch stream editor"; + homepage = "https://www.gnu.org/software/sed"; + license = licenses.gpl3Plus; + maintainers = teams.minimal-bootstrap.members; + mainProgram = "sed"; + platforms = platforms.unix; + }; +} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnused/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/gnused/default.nix index b5647b96ee3c..ee566f93c164 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/gnused/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnused/default.nix @@ -4,41 +4,34 @@ , fetchurl , bash , gnumake -, mesBootstrap ? false, tinycc ? null -, gcc ? null, glibc ? null, binutils ? null, gnused ? null, linux-headers, gnugrep +, tinycc +, gnused +, gnugrep +, gnutar +, gzip }: -assert mesBootstrap -> tinycc != null; -assert !mesBootstrap -> gcc != null && glibc != null && binutils != null && gnused != null; + let - pname = "gnused" + lib.optionalString mesBootstrap "-mes"; - # last version that can be compiled with mes-libc - version = "4.0.9"; + inherit (import ./common.nix { inherit lib; }) meta; + pname = "gnused"; + # last version that can be bootstrapped with our slightly buggy gnused-mes + version = "4.2"; src = fetchurl { url = "mirror://gnu/sed/sed-${version}.tar.gz"; - sha256 = "0006gk1dw2582xsvgx6y6rzs9zw8b36rhafjwm288zqqji3qfrf3"; - }; - - # Thanks to the live-bootstrap project! - # See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/sed-4.0.9.kaem - makefile = fetchurl { - url = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/mk/main.mk"; - sha256 = "0w1f5ri0g5zla31m6l6xyzbqwdvandqfnzrsw90dd6ak126w3mya"; + hash = "sha256-20XNY/0BDmUFN9ZdXfznaJplJ0UjZgbl5ceCk3Jn2YM="; }; in bash.runCommand "${pname}-${version}" { - inherit pname version; + inherit pname version meta; nativeBuildInputs = [ gnumake - ] ++ lib.optionals mesBootstrap [ tinycc.compiler - ] ++ lib.optionals (!mesBootstrap) [ - gcc - glibc - binutils gnused gnugrep + gnutar + gzip ]; passthru.tests.get-version = result: @@ -46,51 +39,25 @@ bash.runCommand "${pname}-${version}" { ${result}/bin/sed --version mkdir ''${out} ''; - - meta = with lib; { - description = "GNU sed, a batch stream editor"; - homepage = "https://www.gnu.org/software/sed"; - license = licenses.gpl3Plus; - maintainers = teams.minimal-bootstrap.members; - mainProgram = "sed"; - platforms = platforms.unix; - }; } ('' # Unpack - ungz --file ${src} --output sed.tar - untar --file sed.tar - rm sed.tar + tar xzf ${src} cd sed-${version} -'' + lib.optionalString mesBootstrap '' - # Configure - cp ${makefile} Makefile - catm config.h - - # Build - make \ - CC="tcc -B ${tinycc.libs}/lib" \ - LIBC=mes - -'' + lib.optionalString (!mesBootstrap) '' # Configure - export CC="gcc -I${glibc}/include -I${linux-headers}/include" - export LIBRARY_PATH="${glibc}/lib" - export LIBS="-lc -lnss_files -lnss_dns -lresolv" - chmod +x configure + export CC="tcc -B ${tinycc.libs}/lib" + export LD=tcc ./configure \ --build=${buildPlatform.config} \ --host=${hostPlatform.config} \ --disable-shared \ --disable-nls \ --disable-dependency-tracking \ - --without-included-regex \ --prefix=$out # Build - make + make AR="tcc -ar" -'' + '' # Install - make install PREFIX=$out + make install '') diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnused/mes.nix b/pkgs/os-specific/linux/minimal-bootstrap/gnused/mes.nix new file mode 100644 index 000000000000..031b5b5f0db0 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnused/mes.nix @@ -0,0 +1,59 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, gnumake +, tinycc +}: + +let + inherit (import ./common.nix { inherit lib; }) meta; + pname = "gnused-mes"; + # last version that can be compiled with mes-libc + version = "4.0.9"; + + src = fetchurl { + url = "mirror://gnu/sed/sed-${version}.tar.gz"; + sha256 = "0006gk1dw2582xsvgx6y6rzs9zw8b36rhafjwm288zqqji3qfrf3"; + }; + + # Thanks to the live-bootstrap project! + # See https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/sed-4.0.9.kaem + makefile = fetchurl { + url = "https://github.com/fosslinux/live-bootstrap/raw/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/sed-4.0.9/mk/main.mk"; + sha256 = "0w1f5ri0g5zla31m6l6xyzbqwdvandqfnzrsw90dd6ak126w3mya"; + }; +in +bash.runCommand "${pname}-${version}" { + inherit pname version meta; + + nativeBuildInputs = [ + gnumake + tinycc.compiler + ]; + + passthru.tests.get-version = result: + bash.runCommand "${pname}-get-version-${version}" {} '' + ${result}/bin/sed --version + mkdir ''${out} + ''; +} ('' + # Unpack + ungz --file ${src} --output sed.tar + untar --file sed.tar + rm sed.tar + cd sed-${version} + + # Configure + cp ${makefile} Makefile + catm config.h + + # Build + make \ + CC="tcc -B ${tinycc.libs}/lib" \ + LIBC=mes + + # Install + make install PREFIX=$out +'') diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnutar/latest.nix b/pkgs/os-specific/linux/minimal-bootstrap/gnutar/latest.nix new file mode 100644 index 000000000000..717ea9868fd9 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnutar/latest.nix @@ -0,0 +1,71 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, gcc +, musl +, binutils +, gnumake +, gnused +, gnugrep +, gawk +, gzip +, gnutarBoot +}: +let + pname = "gnutar"; + version = "1.35"; + + src = fetchurl { + url = "mirror://gnu/tar/tar-${version}.tar.gz"; + hash = "sha256-FNVeMgY+qVJuBX+/Nfyr1TN452l4fv95GcN1WwLStX4="; + }; +in +bash.runCommand "${pname}-${version}" { + inherit pname version; + + nativeBuildInputs = [ + gcc + musl + binutils + gnumake + gnused + gnugrep + gawk + gzip + gnutarBoot + ]; + + passthru.tests.get-version = result: + bash.runCommand "${pname}-get-version-${version}" {} '' + ${result}/bin/tar --version + mkdir $out + ''; + + meta = with lib; { + description = "GNU implementation of the `tar' archiver"; + homepage = "https://www.gnu.org/software/tar"; + license = licenses.gpl3Plus; + maintainers = teams.minimal-bootstrap.members; + mainProgram = "tar"; + platforms = platforms.unix; + }; +} '' + # Unpack + tar xzf ${src} + cd tar-${version} + + # Configure + bash ./configure \ + --prefix=$out \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} \ + CC=musl-gcc + + # Build + make -j $NIX_BUILD_CORES + + # Install + make -j $NIX_BUILD_CORES install +'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnutar/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/gnutar/mes.nix index e07561b3e7e5..e07561b3e7e5 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/gnutar/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnutar/mes.nix diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnutar/musl.nix b/pkgs/os-specific/linux/minimal-bootstrap/gnutar/musl.nix new file mode 100644 index 000000000000..0818a0de39a2 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnutar/musl.nix @@ -0,0 +1,70 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, tinycc +, gnumake +, gnugrep +, gnused +}: +let + # gnutar with musl preserves modify times, allowing make to not try + # rebuilding pregenerated files + pname = "gnutar-musl"; + version = "1.12"; + + src = fetchurl { + url = "mirror://gnu/tar/tar-${version}.tar.gz"; + hash = "sha256-xsN+iIsTbM76uQPFEUn0t71lnWnUrqISRfYQU6V6pgo="; + }; +in +bash.runCommand "${pname}-${version}" { + inherit pname version; + + nativeBuildInputs = [ + tinycc.compiler + gnumake + gnused + gnugrep + ]; + + passthru.tests.get-version = result: + bash.runCommand "${pname}-get-version-${version}" {} '' + ${result}/bin/tar --version + mkdir $out + ''; + + meta = with lib; { + description = "GNU implementation of the `tar' archiver"; + homepage = "https://www.gnu.org/software/tar"; + license = licenses.gpl3Plus; + maintainers = teams.minimal-bootstrap.members; + mainProgram = "tar"; + platforms = platforms.unix; + }; +} '' + # Unpack + ungz --file ${src} --output tar.tar + untar --file tar.tar + rm tar.tar + cd tar-${version} + + # Configure + export CC="tcc -B ${tinycc.libs}/lib" + export LD=tcc + export ac_cv_sizeof_unsigned_long=4 + export ac_cv_sizeof_long_long=8 + export ac_cv_header_netdb_h=no + bash ./configure \ + --prefix=$out \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} \ + --disable-nls + + # Build + make AR="tcc -ar" + + # Install + make install +'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/mes/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/mes/default.nix index 04ab2fdbfaf0..0cf66c5bc230 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/mes/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/mes/default.nix @@ -222,7 +222,6 @@ let mkdir -p ''${out}/bin ${srcPost.bin}/bin/mes-m2 -e main ${srcPost.bin}/bin/mescc.scm -- \ - --base-address 0x08048000 \ -L ''${srcPrefix}/lib \ -L ${libs}/lib \ -lc \ diff --git a/pkgs/os-specific/linux/minimal-bootstrap/musl/1.1.nix b/pkgs/os-specific/linux/minimal-bootstrap/musl/1.1.nix new file mode 100644 index 000000000000..704ee42edeb1 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/musl/1.1.nix @@ -0,0 +1,116 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, tinycc +, gnumake +, gnupatch +, gnused +, gnugrep +, gnutar +, gzip +}: + +let + inherit (import ./common.nix { inherit lib; }) pname meta; + version = "1.1.24"; + + src = fetchurl { + url = "https://musl.libc.org/releases/musl-${version}.tar.gz"; + hash = "sha256-E3DJqBKyzyp9koAlEMygBYzDfmanvt1wBR8KNAFQIqM="; + }; + + # Thanks to the live-bootstrap project! + # See https://github.com/fosslinux/live-bootstrap/blob/d98f97e21413efc32c770d0356f1feda66025686/sysa/musl-1.1.24/musl-1.1.24.sh + liveBootstrap = "https://github.com/fosslinux/live-bootstrap/raw/d98f97e21413efc32c770d0356f1feda66025686/sysa/musl-1.1.24"; + patches = [ + (fetchurl { + url = "${liveBootstrap}/patches/avoid_set_thread_area.patch"; + hash = "sha256-TsbBZXk4/KMZG9EKi7cF+sullVXrxlizLNH0UHGXsPs="; + }) + (fetchurl { + url = "${liveBootstrap}/patches/avoid_sys_clone.patch"; + hash = "sha256-/ZmH64J57MmbxdfQ4RNjamAiBdkImMTlHsHdgV4gMj4="; + }) + (fetchurl { + url = "${liveBootstrap}/patches/fenv.patch"; + hash = "sha256-vMVGjoN4deAJW5gsSqA207SJqAbvhrnOsGK49DdEiTI="; + }) + (fetchurl { + url = "${liveBootstrap}/patches/makefile.patch"; + hash = "sha256-03iYBAUnsrEdLIIhhhq5mM6BGnPn2EfUmIHu51opxbw="; + }) + (fetchurl { + url = "${liveBootstrap}/patches/musl_weak_symbols.patch"; + hash = "sha256-/d9a2eUkpe9uyi1ye6T4CiYc9MR3FZ9na0Gb90+g4v0="; + }) + (fetchurl { + url = "${liveBootstrap}/patches/set_thread_area.patch"; + hash = "sha256-RIZYqbbRSx4X/0iFUhriwwBRmoXVR295GNBUjf2UrM0="; + }) + (fetchurl { + url = "${liveBootstrap}/patches/sigsetjmp.patch"; + hash = "sha256-wd2Aev1zPJXy3q933aiup5p1IMKzVJBquAyl3gbK4PU="; + }) + # FIXME: this patch causes the build to fail + # (fetchurl { + # url = "${liveBootstrap}/patches/stdio_flush_on_exit.patch"; + # hash = "sha256-/z5ze3h3QTysay8nRvyvwPv3pmTcKptdkBIaMCoeLDg="; + # }) + # HACK: always flush stdio immediately + ./always-flush.patch + (fetchurl { + url = "${liveBootstrap}/patches/va_list.patch"; + hash = "sha256-UmcMIl+YCi3wIeVvjbsCyqFlkyYsM4ECNwTfXP+s7vg="; + }) + ]; +in +bash.runCommand "${pname}-${version}" { + inherit pname version meta; + + nativeBuildInputs = [ + tinycc.compiler + gnumake + gnupatch + gnused + gnugrep + gnutar + gzip + ]; +} '' + # Unpack + tar xzf ${src} + cd musl-${version} + + # Patch + ${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches} + # tcc does not support complex types + rm -rf src/complex + # Configure fails without this + mkdir -p /dev + # https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a3-intermediate-musl.nix + sed -i 's|/bin/sh|${bash}/bin/bash|' \ + tools/*.sh + chmod 755 tools/*.sh + # patch popen/system to search in PATH instead of hardcoding /bin/sh + sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \ + src/stdio/popen.c src/process/system.c + sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\ + src/misc/wordexp.c + + # Configure + bash ./configure \ + --prefix=$out \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} \ + --disable-shared \ + CC=tcc + + # Build + make AR="tcc -ar" RANLIB=true CFLAGS="-DSYSCALL_NO_TLS" + + # Install + make install + cp ${tinycc.libs}/lib/libtcc1.a $out/lib +'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/musl/always-flush.patch b/pkgs/os-specific/linux/minimal-bootstrap/musl/always-flush.patch new file mode 100644 index 000000000000..cdeddf962d9d --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/musl/always-flush.patch @@ -0,0 +1,12 @@ +diff --git src/env/__libc_start_main.c src/env/__libc_start_main.c +index 8fbe526..9476c22 100644 +--- src/env/__libc_start_main.c ++++ src/env/__libc_start_main.c +@@ -91,6 +91,7 @@ static int libc_start_main_stage2(int (*main)(int,char **,char **), int argc, ch + __libc_start_init(); + + /* Pass control to the application */ ++ setbuf(stdout, NULL); + exit(main(argc, argv, envp)); + return 0; + } diff --git a/pkgs/os-specific/linux/minimal-bootstrap/musl/common.nix b/pkgs/os-specific/linux/minimal-bootstrap/musl/common.nix new file mode 100644 index 000000000000..52db5f947425 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/musl/common.nix @@ -0,0 +1,13 @@ +{ lib }: + +{ + pname = "musl"; + + meta = with lib; { + description = "An efficient, small, quality libc implementation"; + homepage = "https://musl.libc.org"; + license = licenses.mit; + maintainers = teams.minimal-bootstrap.members; + platforms = platforms.unix; + }; +} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/musl/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/musl/default.nix new file mode 100644 index 000000000000..437ef342f6ae --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/musl/default.nix @@ -0,0 +1,81 @@ +{ lib +, buildPlatform +, hostPlatform +, fetchurl +, bash +, gcc +, binutils +, gnumake +, gnugrep +, gnused +, gnutar +, gzip +}: +let + inherit (import ./common.nix { inherit lib; }) pname meta; + version = "1.2.4"; + + src = fetchurl { + url = "https://musl.libc.org/releases/musl-${version}.tar.gz"; + hash = "sha256-ejXq4z1TcqfA2hGI3nmHJvaIJVE7euPr6XqqpSEU8Dk="; + }; +in +bash.runCommand "${pname}-${version}" { + inherit pname version meta; + + nativeBuildInputs = [ + gcc + binutils + gnumake + gnused + gnugrep + gnutar + gzip + ]; + + passthru.tests.hello-world = result: + bash.runCommand "${pname}-simple-program-${version}" { + nativeBuildInputs = [ gcc binutils result ]; + } '' + cat <<EOF >> test.c + #include <stdio.h> + int main() { + printf("Hello World!\n"); + return 0; + } + EOF + musl-gcc -o test test.c + ./test + mkdir $out + ''; +} '' + # Unpack + tar xzf ${src} + cd musl-${version} + + # Patch + # https://github.com/ZilchOS/bootstrap-from-tcc/blob/2e0c68c36b3437386f786d619bc9a16177f2e149/using-nix/2a3-intermediate-musl.nix + sed -i 's|/bin/sh|${bash}/bin/bash|' \ + tools/*.sh + # patch popen/system to search in PATH instead of hardcoding /bin/sh + sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \ + src/stdio/popen.c src/process/system.c + sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\ + src/misc/wordexp.c + + # Configure + bash ./configure \ + --prefix=$out \ + --build=${buildPlatform.config} \ + --host=${hostPlatform.config} \ + --syslibdir=$out/lib \ + --enable-wrapper + + # Build + make -j $NIX_BUILD_CORES + + # Install + make -j $NIX_BUILD_CORES install + sed -i 's|/bin/sh|${bash}/bin/bash|' $out/bin/* + ln -s ../lib/libc.so $out/bin/ldd +'' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/bootstrap-sources.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/bootstrap-sources.nix index 82ee4d12386e..715d261eea4f 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/bootstrap-sources.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/bootstrap-sources.nix @@ -1,4 +1,4 @@ -{ +{ hostPlatform }: rec { @@ -7,15 +7,7 @@ rec { version = "unstable-2023-05-02"; rev = "3189b5f325b7ef8b88e3edec7c1cde4fce73c76c"; outputHashAlgo = "sha256"; - outputHash = "sha256-FpMp7z+B3cR3LkQ+PooH/b1/NlxH8NHVJNWifaPWt4U="; - - # This 256 byte seed is the only pre-compiled binary in the bootstrap chain. - hex0-seed = import <nix/fetchurl.nix> { - name = "hex0-seed-${version}"; - url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/x86/hex0-seed"; - hash = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="; - executable = true; - }; + outputHash = "sha256-7Y9+csTwZIQp0WGbagX+Q4f2zavN7AUk1TSBp/H5Xks="; /* Since `make-minimal-bootstrap-sources` requires nixpkgs and nix it @@ -73,7 +65,7 @@ rec { */ minimal-bootstrap-sources = derivation { inherit name; - system = builtins.currentSystem; + system = hostPlatform.system; outputHashMode = "recursive"; inherit outputHashAlgo outputHash; diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/default.nix index c15223a43d48..9f3d61b92bc9 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/default.nix @@ -3,21 +3,23 @@ }: lib.makeScope newScope (self: with self; { - inherit (self.callPackage ./bootstrap-sources.nix {}) - version hex0-seed minimal-bootstrap-sources; + inherit (callPackage ./platforms.nix { }) platforms stage0Arch m2libcArch m2libcOS baseAddress; + + inherit (self.callPackage ./bootstrap-sources.nix {}) version minimal-bootstrap-sources; src = minimal-bootstrap-sources; m2libc = src + "/M2libc"; hex0 = callPackage ./hex0.nix { }; + inherit (self.hex0) hex0-seed; kaem = callPackage ./kaem { }; kaem-minimal = callPackage ./kaem/minimal.nix { }; - stage0-posix-x86 = callPackage ./stage0-posix-x86.nix { }; + mescc-tools-boot = callPackage ./mescc-tools-boot.nix { }; - inherit (self.stage0-posix-x86) blood-elf-0 hex2 kaem-unwrapped M1 M2; + inherit (self.mescc-tools-boot) blood-elf-0 hex2 kaem-unwrapped M1 M2; mescc-tools = callPackage ./mescc-tools { }; diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/hex0.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/hex0.nix index b85b2f2cac14..9808e25711c1 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/hex0.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/hex0.nix @@ -1,15 +1,34 @@ { lib , derivationWithMeta -, hex0-seed +, hostPlatform , src , version +, platforms +, stage0Arch }: + +let + hash = { + "AArch64" = "sha256-XTPsoKeI6wTZAF0UwEJPzuHelWOJe//wXg4HYO0dEJo="; + "AMD64" = "sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY="; + "x86" = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="; + }.${stage0Arch} or (throw "Unsupported system: ${hostPlatform.system}"); + + # Pinned from https://github.com/oriansj/stage0-posix/commit/3189b5f325b7ef8b88e3edec7c1cde4fce73c76c + # This 256 byte seed is the only pre-compiled binary in the bootstrap chain. + hex0-seed = import <nix/fetchurl.nix> { + name = "hex0-seed"; + url = "https://github.com/oriansj/bootstrap-seeds/raw/b1263ff14a17835f4d12539226208c426ced4fba/POSIX/${stage0Arch}/hex0-seed"; + executable = true; + inherit hash; + }; +in derivationWithMeta { inherit version; pname = "hex0"; builder = hex0-seed; args = [ - "${src}/x86/hex0_x86.hex0" + "${src}/${stage0Arch}/hex0_${stage0Arch}.hex0" (placeholder "out") ]; @@ -18,11 +37,13 @@ derivationWithMeta { homepage = "https://github.com/oriansj/stage0-posix"; license = licenses.gpl3Plus; maintainers = teams.minimal-bootstrap.members; - platforms = [ "i686-linux" ]; + inherit platforms; }; + passthru = { inherit hex0-seed; }; + # Ensure the untrusted hex0-seed binary produces a known-good hex0 outputHashMode = "recursive"; outputHashAlgo = "sha256"; - outputHash = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="; + outputHash = hash; } diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/default.nix index 77e9a8e8d63f..547790835c5d 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/default.nix @@ -6,6 +6,7 @@ , mescc-tools , mescc-tools-extra , version +, platforms }: # Once mescc-tools-extra is available we can install kaem at /bin/kaem @@ -46,6 +47,6 @@ derivationWithMeta { homepage = "https://github.com/oriansj/mescc-tools"; license = licenses.gpl3Plus; maintainers = teams.minimal-bootstrap.members; - platforms = [ "i686-linux" ]; + inherit platforms; }; } diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/minimal.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/minimal.nix index 24fc77f8d345..ae31302894aa 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/minimal.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/minimal.nix @@ -3,13 +3,15 @@ , src , hex0 , version +, platforms +, stage0Arch }: derivationWithMeta { inherit version; pname = "kaem-minimal"; builder = hex0; args = [ - "${src}/x86/kaem-minimal.hex0" + "${src}/${stage0Arch}/kaem-minimal.hex0" (placeholder "out") ]; @@ -18,7 +20,7 @@ derivationWithMeta { homepage = "https://github.com/oriansj/stage0-posix"; license = licenses.gpl3Plus; maintainers = teams.minimal-bootstrap.members; - platforms = [ "i686-linux" ]; + inherit platforms; }; } diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/make-bootstrap-sources.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/make-bootstrap-sources.nix index 2675d055aec6..6cc7cddb82af 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/make-bootstrap-sources.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/make-bootstrap-sources.nix @@ -12,11 +12,13 @@ # { lib +, hostPlatform , fetchFromGitHub +, fetchpatch }: let - expected = import ./bootstrap-sources.nix { }; + expected = import ./bootstrap-sources.nix { inherit hostPlatform; }; in fetchFromGitHub { @@ -37,6 +39,13 @@ fetchFromGitHub { $out/M2-Planet/M2libc \ $out/mescc-tools/M2libc \ $out/mescc-tools-extra/M2libc + + # aarch64: syscall: mkdir -> mkdirat + # https://github.com/oriansj/M2libc/pull/17 + patch -Np1 -d $out/M2libc -i ${(fetchpatch { + url = "https://github.com/oriansj/M2libc/commit/ff7c3023b3ab6cfcffc5364620b25f8d0279e96b.patch"; + hash = "sha256-QAKddv4TixIQHpFa9SVu9fAkeKbzhQaxjaWzW2yJy7A="; + })} ''; meta = with lib; { diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/stage0-posix-x86.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-boot.nix index bcb02537b916..2114ffc707b1 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/stage0-posix-x86.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-boot.nix @@ -1,10 +1,3 @@ -# This is a translation of stage0-posix/stage0-posix/x86/mescc-tools-mini-kaem.kaem to nix -# https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-mini-kaem.kaem -# -# We have access to mini-kaem at this point but it doesn't support substituting -# environment variables. Without variables there's no way of passing in store inputs, -# or the $out path, other than as command line arguments directly - # Mes --- Maxwell Equations of Software # Copyright © 2017,2019 Jan Nieuwenhuizen <janneke@gnu.org> # Copyright © 2017,2019 Jeremiah Orians @@ -24,19 +17,35 @@ # You should have received a copy of the GNU General Public License # along with Mes. If not, see <http://www.gnu.org/licenses/>. +# This is a translation of stage0-posix/stage0-posix/x86/mescc-tools-mini-kaem.kaem to nix +# https://github.com/oriansj/stage0-posix-x86/blob/56e6b8df3e95f4bc04f8b420a4cd8c82c70b9efa/mescc-tools-mini-kaem.kaem +# +# We have access to mini-kaem at this point but it doesn't support substituting +# environment variables. Without variables there's no way of passing in store inputs, +# or the $out path, other than as command line arguments directly + # Warning all binaries prior to the use of blood-elf will not be readable by # Objdump, you may need to use ndism or gdb to view the assembly in the binary. { lib , derivationWithMeta +, hostPlatform , hex0 , m2libc , src , version +, platforms +, stage0Arch +, m2libcArch +, baseAddress }: rec { out = placeholder "out"; + endianFlag = if hostPlatform.isLittleEndian then "--little-endian" else "--big-endian"; + + bloodFlags = lib.optional hostPlatform.is64bit "--64"; + run = pname: builder: args: derivationWithMeta { inherit pname version builder args; @@ -46,7 +55,7 @@ rec { homepage = "https://github.com/oriansj/stage0-posix"; license = licenses.gpl3Plus; maintainers = teams.minimal-bootstrap.members; - platforms = [ "i686-linux" ]; + inherit platforms; }; }; @@ -54,7 +63,7 @@ rec { # Phase-1 Build hex1 from hex0 # ################################ - hex1 = run "hex1" hex0 ["${src}/x86/hex1_x86.hex0" out]; + hex1 = run "hex1" hex0 ["${src}/${stage0Arch}/hex1_${stage0Arch}.hex0" out]; # hex1 adds support for single character labels and is available in various forms # in mescc-tools/x86_bootstrap to allow you various ways to verify correctness @@ -63,7 +72,7 @@ rec { # Phase-2 Build hex2 from hex1 # ################################ - hex2-0 = run "hex2" hex1 ["${src}/x86/hex2_x86.hex1" out]; + hex2-0 = run "hex2" hex1 ["${src}/${stage0Arch}/hex2_${stage0Arch}.hex1" out]; # hex2 adds support for long labels and absolute addresses thus allowing it # to function as an effective linker for later stages of the bootstrap @@ -74,7 +83,11 @@ rec { # Phase-2b Build catm from hex2 # ################################# - catm = run "catm" hex2-0 ["${src}/x86/catm_x86.hex2" out]; + catm = + if hostPlatform.isAarch64 then + run "catm" hex1 ["${src}/${stage0Arch}/catm_${stage0Arch}.hex1" out] + else + run "catm" hex2-0 ["${src}/${stage0Arch}/catm_${stage0Arch}.hex2" out]; # catm removes the need for cat or shell support for redirection by providing # equivalent functionality via catm output_file input1 input2 ... inputN @@ -83,27 +96,27 @@ rec { # Phase-3 Build M0 from hex2 # ############################## - M0_hex2 = run "M0.hex2" catm [out "${src}/x86/ELF-i386.hex2" "${src}/x86/M0_x86.hex2"]; + M0_hex2 = run "M0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" "${src}/${stage0Arch}/M0_${stage0Arch}.hex2"]; M0 = run "M0" hex2-0 [M0_hex2 out]; # M0 is the architecture specific version of M1 and is by design single # architecture only and will be replaced by the C code version of M1 ################################ - # Phase-4 Build cc_x86 from M0 # + # Phase-4 Build cc_arch from M0 # ################################ - cc_x86-0_hex2 = run "cc_x86-0.hex2" M0 ["${src}/x86/cc_x86.M1" out]; - cc_x86-1_hex2 = run "cc_x86-1.hex2" catm [out "${src}/x86/ELF-i386.hex2" cc_x86-0_hex2]; - cc_x86 = run "cc_x86" hex2-0 [cc_x86-1_hex2 out]; + cc_arch-0_hex2 = run "cc_arch-0.hex2" M0 ["${src}/${stage0Arch}/cc_${m2libcArch}.M1" out]; + cc_arch-1_hex2 = run "cc_arch-1.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" cc_arch-0_hex2]; + cc_arch = run "cc_arch" hex2-0 [cc_arch-1_hex2 out]; - ####################################### - # Phase-5 Build M2-Planet from cc_x86 # - ####################################### + ######################################## + # Phase-5 Build M2-Planet from cc_arch # + ######################################## M2-0_c = run "M2-0.c" catm [ out - "${m2libc}/x86/linux/bootstrap.c" + "${m2libc}/${m2libcArch}/linux/bootstrap.c" "${src}/M2-Planet/cc.h" "${m2libc}/bootstrappable.c" "${src}/M2-Planet/cc_globals.c" @@ -114,10 +127,10 @@ rec { "${src}/M2-Planet/cc_macro.c" "${src}/M2-Planet/cc.c" ]; - M2-0_M1 = run "M2-0.M1" cc_x86 [M2-0_c out]; - M2-0-0_M1 = run "M2-0-0.M1" catm [out "${src}/x86/x86_defs.M1" "${src}/x86/libc-core.M1" M2-0_M1]; + M2-0_M1 = run "M2-0.M1" cc_arch [M2-0_c out]; + M2-0-0_M1 = run "M2-0-0.M1" catm [out "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" "${m2libc}/${m2libcArch}/libc-core.M1" M2-0_M1]; M2-0_hex2 = run "M2-0.hex2" M0 [M2-0-0_M1 out]; - M2-0-0_hex2 = run "M2-0-0.hex2" catm [out "${src}/x86/ELF-i386.hex2" M2-0_hex2]; + M2-0-0_hex2 = run "M2-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" M2-0_hex2]; M2 = run "M2" hex2-0 [M2-0-0_hex2 out]; ############################################ @@ -125,8 +138,8 @@ rec { ############################################ blood-elf-0_M1 = run "blood-elf-0.M1" M2 [ - "--architecture" "x86" - "-f" "${m2libc}/x86/linux/bootstrap.c" + "--architecture" m2libcArch + "-f" "${m2libc}/${m2libcArch}/linux/bootstrap.c" "-f" "${m2libc}/bootstrappable.c" "-f" "${src}/mescc-tools/stringify.c" "-f" "${src}/mescc-tools/blood-elf.c" @@ -134,9 +147,9 @@ rec { "-o" out ]; - blood-elf-0-0_M1 = run "blood-elf-0-0.M1" catm [out "${m2libc}/x86/x86_defs.M1" "${m2libc}/x86/libc-core.M1" blood-elf-0_M1]; + blood-elf-0-0_M1 = run "blood-elf-0-0.M1" catm [out "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" "${m2libc}/${m2libcArch}/libc-core.M1" blood-elf-0_M1]; blood-elf-0_hex2 = run "blood-elf-0.hex2" M0 [blood-elf-0-0_M1 out]; - blood-elf-0-0_hex2 = run "blood-elf-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86.hex2" blood-elf-0_hex2]; + blood-elf-0-0_hex2 = run "blood-elf-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}.hex2" blood-elf-0_hex2]; blood-elf-0 = run "blood-elf-0" hex2-0 [blood-elf-0-0_hex2 out]; # This is the last stage where the binaries will not have debug info @@ -147,8 +160,8 @@ rec { ##################################### M1-macro-0_M1 = run "M1-macro-0.M1" M2 [ - "--architecture" "x86" - "-f" "${m2libc}/x86/linux/bootstrap.c" + "--architecture" m2libcArch + "-f" "${m2libc}/${m2libcArch}/linux/bootstrap.c" "-f" "${m2libc}/bootstrappable.c" "-f" "${src}/mescc-tools/stringify.c" "-f" "${src}/mescc-tools/M1-macro.c" @@ -157,10 +170,10 @@ rec { "-o" out ]; - M1-macro-0-footer_M1 = run "M1-macro-0-footer.M1" blood-elf-0 ["-f" M1-macro-0_M1 "--little-endian" "-o" out]; - M1-macro-0-0_M1 = run "M1-macro-0-0.M1" catm [out "${m2libc}/x86/x86_defs.M1" "${m2libc}/x86/libc-core.M1" M1-macro-0_M1 M1-macro-0-footer_M1]; + M1-macro-0-footer_M1 = run "M1-macro-0-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" M1-macro-0_M1 endianFlag "-o" out]); + M1-macro-0-0_M1 = run "M1-macro-0-0.M1" catm [out "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" "${m2libc}/${m2libcArch}/libc-core.M1" M1-macro-0_M1 M1-macro-0-footer_M1]; M1-macro-0_hex2 = run "M1-macro-0.hex2" M0 [M1-macro-0-0_M1 out]; - M1-macro-0-0_hex2 = run "M1-macro-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86-debug.hex2" M1-macro-0_hex2]; + M1-macro-0-0_hex2 = run "M1-macro-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" M1-macro-0_hex2]; M1-0 = run "M1-0" hex2-0 [M1-macro-0-0_hex2 out]; # This is the last stage where catm will need to be used and the last stage where @@ -172,13 +185,13 @@ rec { ####################################### hex2_linker-0_M1 = run "hex2_linker-0.M1" M2 [ - "--architecture" "x86" + "--architecture" m2libcArch "-f" "${m2libc}/sys/types.h" "-f" "${m2libc}/stddef.h" - "-f" "${m2libc}/x86/linux/unistd.c" - "-f" "${m2libc}/x86/linux/fcntl.c" + "-f" "${m2libc}/${m2libcArch}/linux/unistd.c" + "-f" "${m2libc}/${m2libcArch}/linux/fcntl.c" "-f" "${m2libc}/fcntl.c" - "-f" "${m2libc}/x86/linux/sys/stat.c" + "-f" "${m2libc}/${m2libcArch}/linux/sys/stat.c" "-f" "${m2libc}/stdlib.c" "-f" "${m2libc}/stdio.h" "-f" "${m2libc}/stdio.c" @@ -191,19 +204,19 @@ rec { "-o" out ]; - hex2_linker-0-footer_M1 = run "hex2_linker-0-footer.M1" blood-elf-0 ["-f" hex2_linker-0_M1 "--little-endian" "-o" out]; + hex2_linker-0-footer_M1 = run "hex2_linker-0-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" hex2_linker-0_M1 endianFlag "-o" out]); hex2_linker-0_hex2 = run "hex2_linker-0.hex2" M1-0 [ - "--architecture" "x86" - "--little-endian" - "-f" "${m2libc}/x86/x86_defs.M1" - "-f" "${m2libc}/x86/libc-full.M1" + "--architecture" m2libcArch + endianFlag + "-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" + "-f" "${m2libc}/${m2libcArch}/libc-full.M1" "-f" hex2_linker-0_M1 "-f" hex2_linker-0-footer_M1 "-o" out ]; - hex2_linker-0-0_hex2 = run "hex2_linker-0-0.hex2" catm [out "${m2libc}/x86/ELF-x86-debug.hex2" hex2_linker-0_hex2]; + hex2_linker-0-0_hex2 = run "hex2_linker-0-0.hex2" catm [out "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" hex2_linker-0_hex2]; hex2-1 = run "hex2-1" hex2-0 [hex2_linker-0-0_hex2 out]; @@ -215,12 +228,12 @@ rec { ################################### M1-macro-1_M1 = run "M1-macro-1.M1" M2 [ - "--architecture" "x86" + "--architecture" m2libcArch "-f" "${m2libc}/sys/types.h" "-f" "${m2libc}/stddef.h" - "-f" "${m2libc}/x86/linux/fcntl.c" + "-f" "${m2libc}/${m2libcArch}/linux/fcntl.c" "-f" "${m2libc}/fcntl.c" - "-f" "${m2libc}/x86/linux/unistd.c" + "-f" "${m2libc}/${m2libcArch}/linux/unistd.c" "-f" "${m2libc}/string.c" "-f" "${m2libc}/stdlib.c" "-f" "${m2libc}/stdio.h" @@ -232,23 +245,23 @@ rec { "-o" out ]; - M1-macro-1-footer_M1 = run "M1-macro-1-footer.M1" blood-elf-0 ["-f" M1-macro-1_M1 "--little-endian" "-o" out]; + M1-macro-1-footer_M1 = run "M1-macro-1-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" M1-macro-1_M1 endianFlag "-o" out]); M1-macro-1_hex2 = run "M1-macro-1.hex2" M1-0 [ - "--architecture" "x86" - "--little-endian" - "-f" "${m2libc}/x86/x86_defs.M1" - "-f" "${m2libc}/x86/libc-full.M1" + "--architecture" m2libcArch + endianFlag + "-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" + "-f" "${m2libc}/${m2libcArch}/libc-full.M1" "-f" M1-macro-1_M1 "-f" M1-macro-1-footer_M1 "-o" out ]; M1 = run "M1" hex2-1 [ - "--architecture" "x86" - "--little-endian" - "--base-address" "0x8048000" - "-f" "${m2libc}/x86/ELF-x86-debug.hex2" + "--architecture" m2libcArch + endianFlag + "--base-address" baseAddress + "-f" "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" "-f" M1-macro-1_hex2 "-o" out ]; @@ -258,13 +271,13 @@ rec { ###################################### hex2_linker-2_M1 = run "hex2_linker-2.M1" M2 [ - "--architecture" "x86" + "--architecture" m2libcArch "-f" "${m2libc}/sys/types.h" "-f" "${m2libc}/stddef.h" - "-f" "${m2libc}/x86/linux/unistd.c" - "-f" "${m2libc}/x86/linux/fcntl.c" + "-f" "${m2libc}/${m2libcArch}/linux/unistd.c" + "-f" "${m2libc}/${m2libcArch}/linux/fcntl.c" "-f" "${m2libc}/fcntl.c" - "-f" "${m2libc}/x86/linux/sys/stat.c" + "-f" "${m2libc}/${m2libcArch}/linux/sys/stat.c" "-f" "${m2libc}/stdlib.c" "-f" "${m2libc}/stdio.h" "-f" "${m2libc}/stdio.c" @@ -277,23 +290,23 @@ rec { "-o" out ]; - hex2_linker-2-footer_M1 = run "hex2_linker-2-footer.M1" blood-elf-0 ["-f" hex2_linker-2_M1 "--little-endian" "-o" out]; + hex2_linker-2-footer_M1 = run "hex2_linker-2-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" hex2_linker-2_M1 endianFlag "-o" out]); hex2_linker-2_hex2 = run "hex2_linker-2.hex2" M1 [ - "--architecture" "x86" - "--little-endian" - "-f" "${m2libc}/x86/x86_defs.M1" - "-f" "${m2libc}/x86/libc-full.M1" + "--architecture" m2libcArch + endianFlag + "-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" + "-f" "${m2libc}/${m2libcArch}/libc-full.M1" "-f" hex2_linker-2_M1 "-f" hex2_linker-2-footer_M1 "-o" out ]; hex2 = run "hex2" hex2-1 [ - "--architecture" "x86" - "--little-endian" - "--base-address" "0x8048000" - "-f" "${m2libc}/x86/ELF-x86-debug.hex2" + "--architecture" m2libcArch + endianFlag + "--base-address" baseAddress + "-f" "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" "-f" hex2_linker-2_hex2 "-o" out ]; @@ -303,12 +316,12 @@ rec { ###################################### kaem_M1 = run "kaem.M1" M2 [ - "--architecture" "x86" + "--architecture" m2libcArch "-f" "${m2libc}/sys/types.h" "-f" "${m2libc}/stddef.h" "-f" "${m2libc}/string.c" - "-f" "${m2libc}/x86/linux/unistd.c" - "-f" "${m2libc}/x86/linux/fcntl.c" + "-f" "${m2libc}/${m2libcArch}/linux/unistd.c" + "-f" "${m2libc}/${m2libcArch}/linux/fcntl.c" "-f" "${m2libc}/fcntl.c" "-f" "${m2libc}/stdlib.c" "-f" "${m2libc}/stdio.h" @@ -322,24 +335,24 @@ rec { "-o" out ]; - kaem-footer_M1 = run "kaem-footer.M1" blood-elf-0 ["-f" kaem_M1 "--little-endian" "-o" out]; + kaem-footer_M1 = run "kaem-footer.M1" blood-elf-0 (bloodFlags ++ ["-f" kaem_M1 endianFlag "-o" out]); kaem_hex2 = run "kaem.hex2" M1 [ - "--architecture" "x86" - "--little-endian" - "-f" "${m2libc}/x86/x86_defs.M1" - "-f" "${m2libc}/x86/libc-full.M1" + "--architecture" m2libcArch + endianFlag + "-f" "${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1" + "-f" "${m2libc}/${m2libcArch}/libc-full.M1" "-f" kaem_M1 "-f" kaem-footer_M1 "-o" out ]; kaem-unwrapped = run "kaem-unwrapped" hex2 [ - "--architecture" "x86" - "--little-endian" - "-f" "${m2libc}/x86/ELF-x86-debug.hex2" + "--architecture" m2libcArch + endianFlag + "-f" "${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2" "-f" kaem_hex2 - "--base-address" "0x8048000" + "--base-address" baseAddress "-o" out ]; } diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-extra/build.kaem b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-extra/build.kaem index e50fc1c68474..fb27eccab830 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-extra/build.kaem +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-extra/build.kaem @@ -19,7 +19,7 @@ ## You should have received a copy of the GNU General Public License ## along with mescc-tools. If not, see <http://www.gnu.org/licenses/>. -alias CC="${mescc-tools}/bin/M2-Mesoplanet --operating-system ${OPERATING_SYSTEM} --architecture ${ARCH} -f" +alias CC="${mescc-tools}/bin/M2-Mesoplanet --operating-system ${m2libcOS} --architecture ${m2libcArch} -f" cd ${src}/mescc-tools-extra # Create output folder diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-extra/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-extra/default.nix index 425a10cfb35a..eee00491c446 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-extra/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-extra/default.nix @@ -4,9 +4,12 @@ , mescc-tools , src , version +, platforms +, m2libcArch +, m2libcOS }: derivationWithMeta { - inherit version src mescc-tools; + inherit version src mescc-tools m2libcArch m2libcOS; pname = "mescc-tools-extra"; builder = kaem-unwrapped; args = [ @@ -16,14 +19,11 @@ derivationWithMeta { ./build.kaem ]; - ARCH = "x86"; - OPERATING_SYSTEM = "linux"; - meta = with lib; { description = "Collection of tools written for use in bootstrapping"; homepage = "https://github.com/oriansj/mescc-tools-extra"; license = licenses.gpl3Plus; maintainers = teams.minimal-bootstrap.members; - platforms = [ "i686-linux" ]; + inherit platforms; }; } diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/build.kaem b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/build.kaem index 3a7ae25fbd82..128ff360fd2c 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/build.kaem +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/build.kaem @@ -46,13 +46,13 @@ ${replace} \ # Phase-12 Build M2-Mesoplanet from M2-Planet # ############################################### -${M2} --architecture ${ARCH} \ +${M2} --architecture ${m2libcArch} \ -f ${m2libc}/sys/types.h \ -f ${m2libc}/stddef.h \ - -f ${m2libc}/${ARCH}/linux/fcntl.c \ + -f ${m2libc}/${m2libcArch}/linux/fcntl.c \ -f ${m2libc}/fcntl.c \ - -f ${m2libc}/${ARCH}/linux/unistd.c \ - -f ${m2libc}/${ARCH}/linux/sys/stat.c \ + -f ${m2libc}/${m2libcArch}/linux/unistd.c \ + -f ${m2libc}/${m2libcArch}/linux/sys/stat.c \ -f ${m2libc}/stdlib.c \ -f ${m2libc}/stdio.h \ -f ${m2libc}/stdio.c \ @@ -69,20 +69,20 @@ ${M2} --architecture ${ARCH} \ --debug \ -o ./M2-Mesoplanet-1.M1 -${blood-elf-0} ${ENDIAN_FLAG} ${BLOOD_FLAG} -f ./M2-Mesoplanet-1.M1 -o ./M2-Mesoplanet-1-footer.M1 +${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./M2-Mesoplanet-1.M1 -o ./M2-Mesoplanet-1-footer.M1 -${M1} --architecture ${ARCH} \ - ${ENDIAN_FLAG} \ - -f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \ - -f ${m2libc}/${ARCH}/libc-full.M1 \ +${M1} --architecture ${m2libcArch} \ + ${endianFlag} \ + -f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \ + -f ${m2libc}/${m2libcArch}/libc-full.M1 \ -f ./M2-Mesoplanet-1.M1 \ -f ./M2-Mesoplanet-1-footer.M1 \ -o ./M2-Mesoplanet-1.hex2 -${hex2} --architecture ${ARCH} \ - ${ENDIAN_FLAG} \ - --base-address ${BASE_ADDRESS} \ - -f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \ +${hex2} --architecture ${m2libcArch} \ + ${endianFlag} \ + --base-address ${baseAddress} \ + -f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \ -f ./M2-Mesoplanet-1.hex2 \ -o ${out}/bin/M2-Mesoplanet @@ -90,12 +90,12 @@ ${hex2} --architecture ${ARCH} \ # Phase-13 Build final blood-elf from C sources # ################################################# -${M2} --architecture ${ARCH} \ +${M2} --architecture ${m2libcArch} \ -f ${m2libc}/sys/types.h \ -f ${m2libc}/stddef.h \ - -f ${m2libc}/${ARCH}/linux/fcntl.c \ + -f ${m2libc}/${m2libcArch}/linux/fcntl.c \ -f ${m2libc}/fcntl.c \ - -f ${m2libc}/${ARCH}/linux/unistd.c \ + -f ${m2libc}/${m2libcArch}/linux/unistd.c \ -f ${m2libc}/stdlib.c \ -f ${m2libc}/stdio.h \ -f ${m2libc}/stdio.c \ @@ -105,19 +105,20 @@ ${M2} --architecture ${ARCH} \ --debug \ -o ./blood-elf-1.M1 -${blood-elf-0} ${BLOOD_FLAG} ${ENDIAN_FLAG} -f ./blood-elf-1.M1 -o ./blood-elf-1-footer.M1 -${M1} --architecture ${ARCH} \ - ${ENDIAN_FLAG} \ - -f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \ - -f ${m2libc}/${ARCH}/libc-full.M1 \ +${blood-elf-0} ${endianFlag} ${bloodFlag} -f ./blood-elf-1.M1 -o ./blood-elf-1-footer.M1 + +${M1} --architecture ${m2libcArch} \ + ${endianFlag} \ + -f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \ + -f ${m2libc}/${m2libcArch}/libc-full.M1 \ -f ./blood-elf-1.M1 \ -f ./blood-elf-1-footer.M1 \ -o ./blood-elf-1.hex2 -${hex2} --architecture ${ARCH} \ - ${ENDIAN_FLAG} \ - --base-address ${BASE_ADDRESS} \ - -f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \ +${hex2} --architecture ${m2libcArch} \ + ${endianFlag} \ + --base-address ${baseAddress} \ + -f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \ -f ./blood-elf-1.hex2 \ -o ${out}/bin/blood-elf @@ -129,11 +130,11 @@ ${hex2} --architecture ${ARCH} \ # Phase-14 Build get_machine from C sources # ############################################# -${M2} --architecture ${ARCH} \ +${M2} --architecture ${m2libcArch} \ -f ${m2libc}/sys/types.h \ -f ${m2libc}/stddef.h \ - -f ${m2libc}/${ARCH}/linux/unistd.c \ - -f ${m2libc}/${ARCH}/linux/fcntl.c \ + -f ${m2libc}/${m2libcArch}/linux/unistd.c \ + -f ${m2libc}/${m2libcArch}/linux/fcntl.c \ -f ${m2libc}/fcntl.c \ -f ${m2libc}/stdlib.c \ -f ${m2libc}/stdio.h \ @@ -143,20 +144,20 @@ ${M2} --architecture ${ARCH} \ --debug \ -o get_machine.M1 -${out}/bin/blood-elf ${BLOOD_FLAG} ${ENDIAN_FLAG} -f ./get_machine.M1 -o ./get_machine-footer.M1 +${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./get_machine.M1 -o ./get_machine-footer.M1 -${M1} --architecture ${ARCH} \ - ${ENDIAN_FLAG} \ - -f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \ - -f ${m2libc}/${ARCH}/libc-full.M1 \ +${M1} --architecture ${m2libcArch} \ + ${endianFlag} \ + -f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \ + -f ${m2libc}/${m2libcArch}/libc-full.M1 \ -f ./get_machine.M1 \ -f ./get_machine-footer.M1 \ -o ./get_machine.hex2 -${hex2} --architecture ${ARCH} \ - ${ENDIAN_FLAG} \ - --base-address ${BASE_ADDRESS} \ - -f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \ +${hex2} --architecture ${m2libcArch} \ + ${endianFlag} \ + --base-address ${baseAddress} \ + -f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \ -f ./get_machine.hex2 \ -o ${out}/bin/get_machine @@ -164,11 +165,11 @@ ${hex2} --architecture ${ARCH} \ # Phase-15 Build M2-Planet from M2-Planet # ############################################ -${M2} --architecture ${ARCH} \ +${M2} --architecture ${m2libcArch} \ -f ${m2libc}/sys/types.h \ -f ${m2libc}/stddef.h \ - -f ${m2libc}/${ARCH}/linux/unistd.c \ - -f ${m2libc}/${ARCH}/linux/fcntl.c \ + -f ${m2libc}/${m2libcArch}/linux/unistd.c \ + -f ${m2libc}/${m2libcArch}/linux/fcntl.c \ -f ${m2libc}/fcntl.c \ -f ${m2libc}/stdlib.c \ -f ${m2libc}/stdio.h \ @@ -185,20 +186,19 @@ ${M2} --architecture ${ARCH} \ --debug \ -o ./M2-1.M1 -${out}/bin/blood-elf ${ENDIAN_FLAG} ${BLOOD_FLAG} -f ./M2-1.M1 -o ./M2-1-footer.M1 +${out}/bin/blood-elf ${endianFlag} ${bloodFlag} -f ./M2-1.M1 -o ./M2-1-footer.M1 -${M1} --architecture ${ARCH} \ - ${ENDIAN_FLAG} \ - -f ${m2libc}/${ARCH}/${ARCH}_defs.M1 \ - -f ${m2libc}/${ARCH}/libc-full.M1 \ +${M1} --architecture ${m2libcArch} \ + ${endianFlag} \ + -f ${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \ + -f ${m2libc}/${m2libcArch}/libc-full.M1 \ -f ./M2-1.M1 \ -f ./M2-1-footer.M1 \ -o ./M2-1.hex2 -${hex2} --architecture ${ARCH} \ - ${ENDIAN_FLAG} \ - --base-address ${BASE_ADDRESS} \ - -f ${m2libc}/${ARCH}/ELF-${ARCH}-debug.hex2 \ +${hex2} --architecture ${m2libcArch} \ + ${endianFlag} \ + --base-address ${baseAddress} \ + -f ${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \ -f ./M2-1.hex2 \ -o ${out}/bin/M2-Planet - diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/default.nix index c4aca823203d..4a9c734981e2 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools/default.nix @@ -1,5 +1,6 @@ { lib , derivationWithMeta +, hostPlatform , kaem-unwrapped , M1 , M2 @@ -8,13 +9,14 @@ , m2libc , src , version +, platforms +, m2libcArch +, baseAddress }: let - ARCH = "x86"; - BLOOD_FLAG = " "; - BASE_ADDRESS = "0x8048000"; - ENDIAN_FLAG = "--little-endian"; + endianFlag = if hostPlatform.isLittleEndian then "--little-endian" else "--big-endian"; + bloodFlag = if hostPlatform.is64bit then "--64" else " "; # We need a few tools from mescc-tools-extra to assemble the output folder buildMesccToolsExtraUtil = name: @@ -26,13 +28,13 @@ let "--strict" "--file" (builtins.toFile "build-${name}.kaem" '' - ''${M2} --architecture ''${ARCH} \ + ''${M2} --architecture ${m2libcArch} \ -f ''${m2libc}/sys/types.h \ -f ''${m2libc}/stddef.h \ - -f ''${m2libc}/''${ARCH}/linux/fcntl.c \ + -f ''${m2libc}/${m2libcArch}/linux/fcntl.c \ -f ''${m2libc}/fcntl.c \ - -f ''${m2libc}/''${ARCH}/linux/unistd.c \ - -f ''${m2libc}/''${ARCH}/linux/sys/stat.c \ + -f ''${m2libc}/${m2libcArch}/linux/unistd.c \ + -f ''${m2libc}/${m2libcArch}/linux/sys/stat.c \ -f ''${m2libc}/stdlib.c \ -f ''${m2libc}/stdio.h \ -f ''${m2libc}/stdio.c \ @@ -42,25 +44,25 @@ let --debug \ -o ${name}.M1 - ''${blood-elf-0} ''${ENDIAN_FLAG} -f ${name}.M1 -o ${name}-footer.M1 + ''${blood-elf-0} ${endianFlag} ${bloodFlag} -f ${name}.M1 -o ${name}-footer.M1 - ''${M1} --architecture ''${ARCH} \ - ''${ENDIAN_FLAG} \ - -f ''${m2libc}/''${ARCH}/''${ARCH}_defs.M1 \ - -f ''${m2libc}/''${ARCH}/libc-full.M1 \ + ''${M1} --architecture ${m2libcArch} \ + ${endianFlag} \ + -f ''${m2libc}/${m2libcArch}/${m2libcArch}_defs.M1 \ + -f ''${m2libc}/${m2libcArch}/libc-full.M1 \ -f ${name}.M1 \ -f ${name}-footer.M1 \ -o ${name}.hex2 - ''${hex2} --architecture ''${ARCH} \ - ''${ENDIAN_FLAG} \ - -f ''${m2libc}/''${ARCH}/ELF-''${ARCH}-debug.hex2 \ + ''${hex2} --architecture ${m2libcArch} \ + ${endianFlag} \ + -f ''${m2libc}/${m2libcArch}/ELF-${m2libcArch}-debug.hex2 \ -f ${name}.hex2 \ - --base-address ''${BASE_ADDRESS} \ + --base-address ${baseAddress} \ -o ''${out} '') ]; - inherit version M1 M2 blood-elf-0 hex2 m2libc src ARCH BLOOD_FLAG BASE_ADDRESS ENDIAN_FLAG; + inherit version M1 M2 blood-elf-0 hex2 m2libc src; }; mkdir = buildMesccToolsExtraUtil "mkdir"; cp = buildMesccToolsExtraUtil "cp"; @@ -76,13 +78,13 @@ derivationWithMeta { "--file" ./build.kaem ]; - inherit version M1 M2 blood-elf-0 hex2 mkdir cp chmod replace m2libc src ARCH BLOOD_FLAG BASE_ADDRESS ENDIAN_FLAG; + inherit version M1 M2 blood-elf-0 hex2 mkdir cp chmod replace m2libc src m2libcArch baseAddress bloodFlag endianFlag; meta = with lib; { description = "Collection of tools written for use in bootstrapping"; homepage = "https://github.com/oriansj/mescc-tools"; license = licenses.gpl3Plus; maintainers = teams.minimal-bootstrap.members; - platforms = [ "i686-linux" ]; + inherit platforms; }; } diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/platforms.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/platforms.nix new file mode 100644 index 000000000000..53147df33444 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/platforms.nix @@ -0,0 +1,32 @@ +# Platform specific constants +{ lib +, hostPlatform +}: + +rec { + # meta.platforms + platforms = [ + "aarch64-linux" + "i686-linux" + "x86_64-linux" + ]; + + # system arch as used within the stage0 project + stage0Arch = { + "aarch64-linux" = "AArch64"; + "i686-linux" = "x86"; + "x86_64-linux" = "AMD64"; + }.${hostPlatform.system} or (throw "Unsupported system: ${hostPlatform.system}"); + + # lower-case form is widely used by m2libc + m2libcArch = lib.toLower stage0Arch; + + # Passed to M2-Mesoplanet as --operating-system + m2libcOS = if hostPlatform.isLinux then "linux" else throw "Unsupported system: ${hostPlatform.system}"; + + baseAddress = { + "aarch64-linux" = "0x00600000"; + "i686-linux" = "0x08048000"; + "x86_64-linux" = "0x00600000"; + }.${hostPlatform.system} or (throw "Unsupported system: ${hostPlatform.system}"); +} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/ignore-duplicate-symbols.patch b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/ignore-duplicate-symbols.patch new file mode 100644 index 000000000000..0aec8b465bf2 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/ignore-duplicate-symbols.patch @@ -0,0 +1,13 @@ +--- tccelf.c ++++ tccelf.c +@@ -710,8 +710,9 @@ ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, + #if 0 + printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n", + sym_bind, shndx, new_vis, esym_bind, esym->st_shndx, esym_vis); +-#endif + tcc_error_noabort("'%s' defined twice", name); ++#endif ++ goto do_patch; + } + } else { + esym->st_other = other; diff --git a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/ignore-static-inside-array.patch b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/ignore-static-inside-array.patch new file mode 100644 index 000000000000..8dc2fe3fcfb4 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/ignore-static-inside-array.patch @@ -0,0 +1,21 @@ +--- tccgen.c ++++ tccgen.c +@@ -4941,7 +4941,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) + next(); + n = -1; + t1 = 0; +- if (td & TYPE_PARAM) while (1) { ++ while (1) { + /* XXX The optional type-quals and static should only be accepted + in parameter decls. The '*' as well, and then even only + in prototypes (not function defs). */ +@@ -4972,7 +4972,8 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) + } + break; + +- } else if (tok != ']') { ++ } ++ if (tok != ']') { + if (!local_stack || (storage & VT_STATIC)) + vpushi(expr_const()); + else { diff --git a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/musl.nix b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/musl.nix new file mode 100644 index 000000000000..4d26faac20b1 --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/musl.nix @@ -0,0 +1,155 @@ +{ lib +, fetchurl +, callPackage +, bash +, tinycc-bootstrappable +, musl +, gnupatch +, gnutar +, gzip +}: +let + pname = "tinycc-musl"; + # next commit introduces use of realpath (unsupported in mes-libc) + version = "unstable-2023-07-10"; + rev = "fd6d2180c5c801bb0b4c5dde27d61503059fc97d"; + + src = fetchurl { + url = "https://repo.or.cz/tinycc.git/snapshot/${rev}.tar.gz"; + hash = "sha256-R81SNbEmh4s9FNQxCWZwUiMCYRkkwOHAdRf0aMnnRiA="; + }; + + patches = [ + ./ignore-duplicate-symbols.patch + ./ignore-static-inside-array.patch + ./static-link.patch + ]; + + meta = with lib; { + description = "Small, fast, and embeddable C compiler and interpreter"; + homepage = "https://repo.or.cz/w/tinycc.git"; + license = licenses.lgpl21Only; + maintainers = teams.minimal-bootstrap.members; + platforms = [ "i686-linux" ]; + }; + + tinycc-musl = bash.runCommand "${pname}-${version}" { + inherit pname version meta; + + nativeBuildInputs = [ + tinycc-bootstrappable.compiler + gnupatch + gnutar + gzip + ]; + } '' + # Unpack + tar xzf ${src} + cd tinycc-${builtins.substring 0 7 rev} + + # Patch + ${lib.concatMapStringsSep "\n" (f: "patch -Np0 -i ${f}") patches} + + # Configure + touch config.h + + # Build + # We first have to recompile using tcc-0.9.26 as tcc-0.9.27 is not self-hosting, + # but when linked with musl it is. + ln -s ${musl}/lib/libtcc1.a ./libtcc1.a + + tcc \ + -B ${tinycc-bootstrappable.libs}/lib \ + -DC2STR \ + -o c2str \ + conftest.c + ./c2str include/tccdefs.h tccdefs_.h + + tcc -v \ + -static \ + -o tcc-musl \ + -D TCC_TARGET_I386=1 \ + -D CONFIG_TCCDIR=\"\" \ + -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ + -D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \ + -D CONFIG_TCC_LIBPATHS=\"{B}\" \ + -D CONFIG_TCC_SYSINCLUDEPATHS=\"${musl}/include\" \ + -D TCC_LIBGCC=\"libc.a\" \ + -D TCC_LIBTCC1=\"libtcc1.a\" \ + -D CONFIG_TCC_STATIC=1 \ + -D CONFIG_USE_LIBGCC=1 \ + -D TCC_VERSION=\"0.9.27\" \ + -D ONE_SOURCE=1 \ + -D TCC_MUSL=1 \ + -D CONFIG_TCC_PREDEFS=1 \ + -D CONFIG_TCC_SEMLOCK=0 \ + -B . \ + -B ${tinycc-bootstrappable.libs}/lib \ + tcc.c + # libtcc1.a + rm -f libtcc1.a + tcc -c -D HAVE_CONFIG_H=1 lib/libtcc1.c + tcc -ar cr libtcc1.a libtcc1.o + + # Rebuild tcc-musl with itself + ./tcc-musl \ + -v \ + -static \ + -o tcc-musl \ + -D TCC_TARGET_I386=1 \ + -D CONFIG_TCCDIR=\"\" \ + -D CONFIG_TCC_CRTPREFIX=\"{B}\" \ + -D CONFIG_TCC_ELFINTERP=\"/musl/loader\" \ + -D CONFIG_TCC_LIBPATHS=\"{B}\" \ + -D CONFIG_TCC_SYSINCLUDEPATHS=\"${musl}/include\" \ + -D TCC_LIBGCC=\"libc.a\" \ + -D TCC_LIBTCC1=\"libtcc1.a\" \ + -D CONFIG_TCC_STATIC=1 \ + -D CONFIG_USE_LIBGCC=1 \ + -D TCC_VERSION=\"0.9.27\" \ + -D ONE_SOURCE=1 \ + -D TCC_MUSL=1 \ + -D CONFIG_TCC_PREDEFS=1 \ + -D CONFIG_TCC_SEMLOCK=0 \ + -B . \ + -B ${musl}/lib \ + tcc.c + # libtcc1.a + rm -f libtcc1.a + ./tcc-musl -c -D HAVE_CONFIG_H=1 lib/libtcc1.c + ./tcc-musl -c -D HAVE_CONFIG_H=1 lib/alloca.S + ./tcc-musl -ar cr libtcc1.a libtcc1.o alloca.o + + # Install + install -D tcc-musl $out/bin/tcc + install -Dm444 libtcc1.a $out/lib/libtcc1.a + ''; +in +{ + compiler = bash.runCommand "${pname}-${version}-compiler" { + inherit pname version meta; + passthru.tests.hello-world = result: + bash.runCommand "${pname}-simple-program-${version}" {} '' + cat <<EOF >> test.c + #include <stdio.h> + int main() { + printf("Hello World!\n"); + return 0; + } + EOF + ${result}/bin/tcc -v -static -B${musl}/lib -o test test.c + ./test + mkdir $out + ''; + passthru.tinycc-musl = tinycc-musl; + } "install -D ${tinycc-musl}/bin/tcc $out/bin/tcc"; + + libs = bash.runCommand "${pname}-${version}-libs" { + inherit pname version meta; + } '' + mkdir $out + cp -r ${musl}/* $out + chmod +w $out/lib/libtcc1.a + cp ${tinycc-musl}/lib/libtcc1.a $out/lib/libtcc1.a + ''; +} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/static-link.patch b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/static-link.patch new file mode 100644 index 000000000000..671a3b37f98d --- /dev/null +++ b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/static-link.patch @@ -0,0 +1,10 @@ +--- libtcc.c ++++ libtcc.c +@@ -793,6 +793,7 @@ LIBTCCAPI TCCState *tcc_new(void) + + s->gnu_ext = 1; + s->tcc_ext = 1; ++ s->static_link = 1; + s->nocommon = 1; + s->dollars_in_identifiers = 1; /*on by default like in gcc/clang*/ + s->cversion = 199901; /* default unless -std=c11 is supplied */ diff --git a/pkgs/os-specific/linux/minimal-bootstrap/xz/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/xz/default.nix index 92cb240c5f16..8dcccbacaca8 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/xz/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/xz/default.nix @@ -5,18 +5,19 @@ , bash , tinycc , gnumake +, gnused , gnugrep , gawk -, sed +, gnutar +, gzip }: let pname = "xz"; - # >=5.2 uses poll.h, unsupported by meslibc - version = "5.0.8"; + version = "5.4.3"; src = fetchurl { - url = "https://tukaani.org/xz/xz-${version}.tar.bz2"; - sha256 = "1nkb68dyrf16xwyqichcy1vhgbfg20dxz459rcsdx85h1gczk1i2"; + url = "https://tukaani.org/xz/xz-${version}.tar.gz"; + hash = "sha256-HDguC8Lk4K9YOYqQPdYv/35RAXHS3keh6+BtFSjpt+k="; }; in bash.runCommand "${pname}-${version}" { @@ -25,9 +26,11 @@ bash.runCommand "${pname}-${version}" { nativeBuildInputs = [ tinycc.compiler gnumake + gnused gnugrep gawk - sed + gnutar + gzip ]; passthru.tests.get-version = result: @@ -45,34 +48,23 @@ bash.runCommand "${pname}-${version}" { }; } '' # Unpack - unbz2 --file ${src} --output xz.tar - untar --file xz.tar - rm xz.tar + tar xzf ${src} cd xz-${version} # Configure - export CC="tcc -B ${tinycc.libs}/lib -include${./stubs.h}" - export CPP="tcc -E" - export LD=tcc + export CC="tcc -B ${tinycc.libs}/lib" export AR="tcc -ar" - export SED=sed - export ac_cv_prog_cc_c99= - export ac_cv_header_fcntl_h=yes - export ac_cv_header_limits_h=yes - export ac_cv_header_sys_time_h=yes - export ac_cv_func_utime=no + export LD=tcc bash ./configure \ --prefix=$out \ --build=${buildPlatform.config} \ --host=${hostPlatform.config} \ --disable-shared \ - --disable-nls \ - --disable-threads \ --disable-assembler # Build - make all + make -j $NIX_BUILD_CORES # Install - make install + make -j $NIX_BUILD_CORES install '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/xz/stubs.h b/pkgs/os-specific/linux/minimal-bootstrap/xz/stubs.h deleted file mode 100644 index cbf6f823299e..000000000000 --- a/pkgs/os-specific/linux/minimal-bootstrap/xz/stubs.h +++ /dev/null @@ -1,25 +0,0 @@ -#define sig_atomic_t int - -#define SSIZE_MAX LONG_MAX - -#define O_NOCTTY 0400 -#define O_NONBLOCK 04000 - -#define S_ISVTX 01000 -#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) - -int fchmod (int fd, int mode) -{ - return 0; -} - -int fchown (int fd, int owner, int group) -{ - return 0; -} - -#include <signal.h> -int sigfillset (sigset_t * set) -{ - return 0; -} |