diff options
Diffstat (limited to 'pkgs/os-specific/linux/minimal-bootstrap')
41 files changed, 1469 insertions, 644 deletions
diff --git a/pkgs/os-specific/linux/minimal-bootstrap/bash/2.nix b/pkgs/os-specific/linux/minimal-bootstrap/bash/2.nix index 41e3547a786..5eea877803a 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/bash/2.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/bash/2.nix @@ -84,6 +84,17 @@ kaem.runCommand "${pname}-${version}" { "-e" (builtins.toFile "bash-builder.sh" '' export CONFIG_SHELL=$SHELL + + # Normalize the NIX_BUILD_CORES variable. The value might be 0, which + # means that we're supposed to try and auto-detect the number of + # available CPU cores at run-time. We don't have nproc to detect the + # number of available CPU cores so default to 1 if not set. + NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}" + if [ $NIX_BUILD_CORES -le 0 ]; then + NIX_BUILD_CORES=1 + fi + export NIX_BUILD_CORES + bash -eux $buildCommandPath '') ]; diff --git a/pkgs/os-specific/linux/minimal-bootstrap/bash/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/bash/default.nix index dea5ad9f017..86fa3a58687 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: @@ -48,6 +54,17 @@ bootBash.runCommand "${pname}-${version}" { "-e" (builtins.toFile "bash-builder.sh" '' export CONFIG_SHELL=$SHELL + + # Normalize the NIX_BUILD_CORES variable. The value might be 0, which + # means that we're supposed to try and auto-detect the number of + # available CPU cores at run-time. + NIX_BUILD_CORES="''${NIX_BUILD_CORES:-1}" + if ((NIX_BUILD_CORES <= 0)); then + guess=$(nproc 2>/dev/null || true) + ((NIX_BUILD_CORES = guess <= 0 ? 1 : guess)) + fi + export NIX_BUILD_CORES + bash -eux $buildCommandPath '') ]; @@ -78,22 +95,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 00000000000..6e64dfa7fa3 --- /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 f386ebbaf8e..71e391efb55 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 84fb7a0a1b7..05da061ac26 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 eb4fe9bcf99..9d7480d239f 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 00000000000..14584e0a7e6 --- /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 55900f86d21..a246b587dd4 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/default.nix @@ -17,46 +17,43 @@ lib.makeScope bash = callPackage ./bash { bootBash = bash_2_05; - gcc = gcc2; - glibc = glibc22; - gawk = gawk-mes; + 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; - gawk = gawk-mes; - }; - binutils-mes = callPackage ./binutils { - bash = bash_2_05; - tinycc = tinycc-mes; - sed = heirloom.sed; - gawk = gawk-mes; - 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; - gawk = gawk-mes; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; }; findutils = callPackage ./findutils { - bash = bash_2_05; - gcc = gcc2; - glibc = glibc22; - gawk = gawk-mes; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; }; gawk-mes = callPackage ./gawk/mes.nix { @@ -67,35 +64,42 @@ lib.makeScope gawk = callPackage ./gawk { bash = bash_2_05; - gcc = gcc2; - glibc = glibc22; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; bootGawk = gawk-mes; }; - gcc2 = callPackage ./gcc/2.nix { - bash = bash_2_05; - gcc = gcc2-mes; - binutils = binutils-mes; - glibc = glibc22; + gcc46 = callPackage ./gcc/4.6.nix { + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; + # FIXME: not sure why new gawk doesn't work + gawk = gawk-mes; }; - gcc2-mes = callPackage ./gcc/2.nix { - bash = bash_2_05; - tinycc = tinycc-mes; - binutils = binutils-mes; - mesBootstrap = true; + 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; }; - gcc46 = callPackage ./gcc/4.6.nix { - gcc = gcc2; - glibc = 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; }; - inherit (callPackage ./glibc { - bash = bash_2_05; - gnused = gnused-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; - }) glibc22; + }; gnugrep = callPackage ./gnugrep { bash = bash_2_05; @@ -104,26 +108,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; @@ -144,9 +166,15 @@ 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; - gawk = gawk-mes; + gnumake = gnumake-musl; }; stage0-posix = callPackage ./stage0-posix { }; @@ -155,12 +183,16 @@ lib.makeScope 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; - gawk = gawk-mes; - inherit (heirloom) sed; + tinycc = tinycc-musl; + gnumake = gnumake-musl; + gnutar = gnutar-musl; }; inherit (callPackage ./utils.nix { }) derivationWithMeta writeTextFile writeText; @@ -169,24 +201,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 7545a52524a..24cd643b349 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 cf26abd2138..97418d218fb 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/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/gawk/default.nix index 935414f2176..879b98bf00c 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/gawk/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/gawk/default.nix @@ -3,10 +3,7 @@ , hostPlatform , fetchurl , bash -, gcc -, glibc -, binutils -, linux-headers +, tinycc , gnumake , gnugrep , gnused @@ -17,21 +14,18 @@ let inherit (import ./common.nix { inherit lib; }) meta; pname = "gawk"; - # >= 4.2.0 fails to cleanly build. may be worth investigating in the future. - # for now this version is sufficient to build glibc 2.16 - version = "4.1.4"; + version = "5.2.2"; src = fetchurl { url = "mirror://gnu/gawk/gawk-${version}.tar.gz"; - sha256 = "0dadjkpyyizmyd0l098qps8lb39r0vrz3xl3hwz2cmjs5c70h0wc"; + hash = "sha256-lFrvfM/xAfILIqEIArwAXplKsrjqPnJMwaGXxi9B9lA="; }; in bash.runCommand "${pname}-${version}" { inherit pname version meta; nativeBuildInputs = [ - gcc - binutils + tinycc.compiler gnumake gnused gnugrep @@ -51,18 +45,17 @@ bash.runCommand "${pname}-${version}" { cd gawk-${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 AR="tcc -ar" + export LD=tcc bash ./configure \ --prefix=$out \ --build=${buildPlatform.config} \ --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/gcc/2.nix b/pkgs/os-specific/linux/minimal-bootstrap/gcc/2.nix deleted file mode 100644 index c879fd30aaf..00000000000 --- 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 00000000000..277c5e82cc3 --- /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 ce348352b67..8b56dff5882 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 00000000000..ea9fdaf8854 --- /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 00000000000..fba3b731a00 --- /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 fb622b39580..00000000000 --- 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 00000000000..318553bf916 --- /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 5c4ff386add..00000000000 --- 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 00000000000..504095732e8 --- /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 00000000000..658f05923ac --- /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 b5647b96ee3..ee566f93c16 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 00000000000..031b5b5f0db --- /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 00000000000..717ea9868fd --- /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 e07561b3e7e..e07561b3e7e 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 00000000000..0818a0de39a --- /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/musl/1.1.nix b/pkgs/os-specific/linux/minimal-bootstrap/musl/1.1.nix new file mode 100644 index 00000000000..704ee42edeb --- /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 00000000000..cdeddf962d9 --- /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 00000000000..52db5f94742 --- /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 index c252d60328e..437ef342f6a 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/musl/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/musl/default.nix @@ -8,12 +8,11 @@ , gnumake , gnugrep , gnused -, gawk , gnutar , gzip }: let - pname = "musl"; + inherit (import ./common.nix { inherit lib; }) pname meta; version = "1.2.4"; src = fetchurl { @@ -22,7 +21,7 @@ let }; in bash.runCommand "${pname}-${version}" { - inherit pname version; + inherit pname version meta; nativeBuildInputs = [ gcc @@ -30,14 +29,13 @@ bash.runCommand "${pname}-${version}" { gnumake gnused gnugrep - gawk gnutar gzip ]; passthru.tests.hello-world = result: bash.runCommand "${pname}-simple-program-${version}" { - nativeBuildInputs = [ gcc binutils ]; + nativeBuildInputs = [ gcc binutils result ]; } '' cat <<EOF >> test.c #include <stdio.h> @@ -46,18 +44,10 @@ bash.runCommand "${pname}-${version}" { return 0; } EOF - gcc -static -B${result}/lib -I${result}/include -o test test.c + musl-gcc -o test test.c ./test mkdir $out ''; - - 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; - }; } '' # Unpack tar xzf ${src} @@ -77,11 +67,15 @@ bash.runCommand "${pname}-${version}" { bash ./configure \ --prefix=$out \ --build=${buildPlatform.config} \ - --host=${hostPlatform.config} + --host=${hostPlatform.config} \ + --syslibdir=$out/lib \ + --enable-wrapper # Build - make + make -j $NIX_BUILD_CORES # Install - make 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 203b480326e..7f2e8ab81a3 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,13 +1,12 @@ -{ +{ hostPlatform }: rec { - name = "stage0-posix-${version}-${rev}-source"; - # Pinned from https://github.com/oriansj/stage0-posix/commit/3189b5f325b7ef8b88e3edec7c1cde4fce73c76c - version = "unstable-2023-05-02"; - rev = "3189b5f325b7ef8b88e3edec7c1cde4fce73c76c"; + name = "stage0-posix-${version}-source"; + version = "1.6.0"; + rev = "Release_${version}"; outputHashAlgo = "sha256"; - outputHash = "sha256-FpMp7z+B3cR3LkQ+PooH/b1/NlxH8NHVJNWifaPWt4U="; + outputHash = "sha256-epUaShjKiAd749ICvc6rS6WhUkS8R4heKuPdwUjEtsQ="; /* Since `make-minimal-bootstrap-sources` requires nixpkgs and nix it @@ -65,7 +64,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/hex0.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/hex0.nix index 996f2f33ea3..9808e25711c 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/hex0.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/hex0.nix @@ -9,8 +9,9 @@ let hash = { - "x86" = "sha256-QU3RPGy51W7M2xnfFY1IqruKzusrSLU+L190ztN6JW8="; - "AMD64" = "sha256-RCgK9oZRDQUiWLVkcIBSR2HeoB+Bh0czthrpjFEkCaY="; + "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 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 2675d055aec..6cc7cddb82a 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/mescc-tools-boot.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-boot.nix index 65f0fb4c2ff..2114ffc707b 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-boot.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/mescc-tools-boot.nix @@ -83,7 +83,11 @@ rec { # Phase-2b Build catm from hex2 # ################################# - catm = run "catm" hex2-0 ["${src}/${stage0Arch}/catm_${stage0Arch}.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 diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/platforms.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/platforms.nix index c68f7630f3d..53147df3344 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/platforms.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/platforms.nix @@ -6,14 +6,16 @@ rec { # meta.platforms platforms = [ + "aarch64-linux" "i686-linux" "x86_64-linux" ]; # system arch as used within the stage0 project stage0Arch = { - "i686-linux" = "x86"; - "x86_64-linux" = "AMD64"; + "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 @@ -23,7 +25,8 @@ rec { m2libcOS = if hostPlatform.isLinux then "linux" else throw "Unsupported system: ${hostPlatform.system}"; baseAddress = { - "i686-linux" = "0x08048000"; - "x86_64-linux" = "0x00600000"; + "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 00000000000..0aec8b465bf --- /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 00000000000..8dc2fe3fcfb --- /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 00000000000..4d26faac20b --- /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 00000000000..671a3b37f98 --- /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 92cb240c5f1..8dcccbacaca 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 cbf6f823299..00000000000 --- 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; -} |