From b55f9fc7db573d960d43ace819ebf42bf6f8f40a Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Fri, 7 Jun 2024 05:32:10 -0700 Subject: [PATCH] feat: bzip2, gcc v8, gcc v13, gnutar --- foundation/src/stages/stage1/bash/default.nix | 2 +- .../src/stages/stage1/bzip2/default.nix | 97 +++++++++ foundation/src/stages/stage1/default.nix | 5 + foundation/src/stages/stage1/gcc/default.nix | 178 ++++++++++++++++ foundation/src/stages/stage1/gcc/v8.nix | 195 ++++++++++++++++++ .../src/stages/stage1/gnutar/default.nix | 32 ++- foundation/src/stages/stage1/musl/default.nix | 2 +- 7 files changed, 492 insertions(+), 19 deletions(-) create mode 100644 foundation/src/stages/stage1/bzip2/default.nix create mode 100644 foundation/src/stages/stage1/gcc/v8.nix diff --git a/foundation/src/stages/stage1/bash/default.nix b/foundation/src/stages/stage1/bash/default.nix index 4f9f3d3..8d34ab5 100644 --- a/foundation/src/stages/stage1/bash/default.nix +++ b/foundation/src/stages/stage1/bash/default.nix @@ -90,7 +90,7 @@ in { stage1.gnupatch.package stage1.gnused.package stage1.gnugrep.package - stage1.gnutar.package + stage1.gnutar.musl.package stage1.gawk.boot.package stage1.gzip.package stage1.diffutils.package diff --git a/foundation/src/stages/stage1/bzip2/default.nix b/foundation/src/stages/stage1/bzip2/default.nix new file mode 100644 index 0000000..205f795 --- /dev/null +++ b/foundation/src/stages/stage1/bzip2/default.nix @@ -0,0 +1,97 @@ +{ + lib, + config, +}: let + cfg = config.aux.foundation.stages.stage1.bzip2; + + platform = config.aux.platform; + builders = config.aux.foundation.builders; + + stage1 = config.aux.foundation.stages.stage1; +in { + options.aux.foundation.stages.stage1.bzip2 = { + package = lib.options.create { + type = lib.types.package; + description = "The package to use for bzip2."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of the package."; + }; + + src = lib.options.create { + type = lib.types.package; + description = "Source for the package."; + }; + + meta = { + description = lib.options.create { + type = lib.types.string; + description = "Description for the package."; + default.value = "High-quality data compression program"; + }; + + homepage = lib.options.create { + type = lib.types.string; + description = "Homepage for the package."; + default.value = "https://www.sourceware.org/bzip2"; + }; + + license = lib.options.create { + # TODO: Add a proper type for licenses. + type = lib.types.attrs.any; + description = "License for the package."; + default.value = lib.licenses.bsdOriginal; + }; + + platforms = lib.options.create { + type = lib.types.list.of lib.types.string; + description = "Platforms the package supports."; + # TODO: Support more platforms. + default.value = ["i686-linux"]; + }; + }; + }; + + config = { + aux.foundation.stages.stage1.bzip2 = { + version = "1.0.8"; + + src = builtins.fetchurl { + url = "https://sourceware.org/pub/bzip2/bzip2-${cfg.version}.tar.gz"; + sha256 = "0s92986cv0p692icqlw1j42y9nld8zd83qwhzbqd61p1dqbh6nmb"; + }; + + package = builders.bash.build { + name = "bzip2-${cfg.version}"; + + meta = cfg.meta; + + deps.build.host = [ + stage1.tinycc.musl.compiler.package + stage1.gnumake.package + stage1.gnutar.musl.package + stage1.gzip.package + ]; + + script = '' + # Unpack + tar xzf ${cfg.src} + cd bzip2-${cfg.version} + + # Build + make \ + -j $NIX_BUILD_CORES \ + CC="tcc -B ${stage1.tinycc.musl.libs.package}/lib" \ + AR="tcc -ar" \ + bzip2 bzip2recover + + # Install + make install -j $NIX_BUILD_CORES PREFIX=$out + + ''; + }; + }; + }; +} diff --git a/foundation/src/stages/stage1/default.nix b/foundation/src/stages/stage1/default.nix index db057c6..4301f62 100644 --- a/foundation/src/stages/stage1/default.nix +++ b/foundation/src/stages/stage1/default.nix @@ -26,6 +26,7 @@ in { ./diffutils ./binutils ./findutils + ./bzip2 ./gcc ]; @@ -70,7 +71,11 @@ in { # These packages are built using Bash v5 stage1-gcc-46 = stage1.gcc.v46.package; stage1-musl = stage1.musl.package; + stage1-bzip2 = stage1.bzip2.package; stage1-gcc-46-cxx = stage1.gcc.v46.cxx.package; + stage1-gnutar = stage1.gnutar.package; + stage1-gcc-8 = stage1.gcc.v8.package; + stage1-gcc = stage1.gcc.package; }; extras = { diff --git a/foundation/src/stages/stage1/gcc/default.nix b/foundation/src/stages/stage1/gcc/default.nix index 12ad6ce..26ba8d7 100644 --- a/foundation/src/stages/stage1/gcc/default.nix +++ b/foundation/src/stages/stage1/gcc/default.nix @@ -12,9 +12,79 @@ in { includes = [ ./v4.6.nix ./v4.6.cxx.nix + ./v8.nix ]; options.aux.foundation.stages.stage1.gcc = { + package = lib.options.create { + type = lib.types.package; + description = "The package to use for gcc-cxx."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of the package."; + }; + + src = lib.options.create { + type = lib.types.package; + description = "Source for the package."; + }; + + cc = { + src = lib.options.create { + type = lib.types.package; + description = "The cc source for the package."; + }; + }; + + gmp = { + src = lib.options.create { + type = lib.types.package; + description = "The gmp source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of gmp."; + }; + }; + + mpfr = { + src = lib.options.create { + type = lib.types.package; + description = "The mpfr source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of mpfr."; + }; + }; + + mpc = { + src = lib.options.create { + type = lib.types.package; + description = "The mpc source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of mpc."; + }; + }; + + isl = { + src = lib.options.create { + type = lib.types.package; + description = "The isl source for the package."; + }; + version = lib.options.create { + type = lib.types.string; + description = "Version of isl."; + }; + }; + meta = { description = lib.options.create { type = lib.types.string; @@ -42,4 +112,112 @@ in { }; }; }; + + config = { + aux.foundation.stages.stage1.gcc = { + version = "13.2.0"; + + src = builtins.fetchurl { + url = "https://ftpmirror.gnu.org/gcc/gcc-${cfg.version}/gcc-${cfg.version}.tar.xz"; + sha256 = "4nXnZEKmBnNBon8Exca4PYYTFEAEwEE1KIY9xrXHQ9o="; + }; + + gmp = { + version = "6.3.0"; + src = builtins.fetchurl { + url = "https://ftpmirror.gnu.org/gmp/gmp-${cfg.gmp.version}.tar.xz"; + sha256 = "o8K4AgG4nmhhb0rTC8Zq7kknw85Q4zkpyoGdXENTiJg="; + }; + }; + + mpfr = { + version = "4.2.1"; + src = builtins.fetchurl { + url = "https://ftpmirror.gnu.org/mpfr/mpfr-${cfg.mpfr.version}.tar.xz"; + sha256 = "J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I="; + }; + }; + + mpc = { + version = "1.3.1"; + src = builtins.fetchurl { + url = "https://ftpmirror.gnu.org/mpc/mpc-${cfg.mpc.version}.tar.gz"; + sha256 = "q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg="; + }; + }; + + isl = { + version = "0.24"; + src = builtins.fetchurl { + url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${cfg.isl.version}.tar.bz2"; + sha256 = "/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA="; + }; + }; + + package = builders.bash.build { + name = "gcc-${cfg.version}"; + + meta = cfg.meta; + + deps.build.host = [ + stage1.gcc.v8.package + stage1.binutils.package + stage1.gnumake.package + stage1.gnused.package + stage1.gnugrep.package + stage1.gawk.boot.package + stage1.diffutils.package + stage1.findutils.package + stage1.gnutar.package + stage1.gzip.package + stage1.bzip2.package + stage1.xz.package + ]; + + script = '' + # Unpack + tar xf ${cfg.src} + tar xf ${cfg.gmp.src} + tar xf ${cfg.mpfr.src} + tar xf ${cfg.mpc.src} + tar xf ${cfg.isl.src} + cd gcc-${cfg.version} + + ln -s ../gmp-${cfg.gmp.version} gmp + ln -s ../mpfr-${cfg.mpfr.version} mpfr + ln -s ../mpc-${cfg.mpc.version} mpc + ln -s ../isl-${cfg.isl.version} 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,${stage1.musl.package}/lib/libc.so" + export CXX="g++ -Wl,-dynamic-linker -Wl,${stage1.musl.package}/lib/libc.so" + export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${stage1.musl.package}/lib/libc.so" + export LIBRARY_PATH="${stage1.musl.package}/lib" + + bash ./configure \ + --prefix=$out \ + --build=${platform.build} \ + --host=${platform.host} \ + --with-native-system-header-dir=/include \ + --with-sysroot=${stage1.musl.package} \ + --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/foundation/src/stages/stage1/gcc/v8.nix b/foundation/src/stages/stage1/gcc/v8.nix new file mode 100644 index 0000000..ae551b9 --- /dev/null +++ b/foundation/src/stages/stage1/gcc/v8.nix @@ -0,0 +1,195 @@ +{ + lib, + config, +}: let + cfg = config.aux.foundation.stages.stage1.gcc.v8; + + platform = config.aux.platform; + builders = config.aux.foundation.builders; + + stage1 = config.aux.foundation.stages.stage1; +in { + options.aux.foundation.stages.stage1.gcc.v8 = { + package = lib.options.create { + type = lib.types.package; + description = "The package to use for gcc."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of the package."; + }; + + src = lib.options.create { + type = lib.types.package; + description = "Source for the package."; + }; + + cc = { + src = lib.options.create { + type = lib.types.package; + description = "The cc source for the package."; + }; + }; + + gmp = { + src = lib.options.create { + type = lib.types.package; + description = "The gmp source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of gmp."; + }; + }; + + mpfr = { + src = lib.options.create { + type = lib.types.package; + description = "The mpfr source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of mpfr."; + }; + }; + + mpc = { + src = lib.options.create { + type = lib.types.package; + description = "The mpc source for the package."; + }; + + version = lib.options.create { + type = lib.types.string; + description = "Version of mpc."; + }; + }; + + isl = { + src = lib.options.create { + type = lib.types.package; + description = "The isl source for the package."; + }; + version = lib.options.create { + type = lib.types.string; + description = "Version of isl."; + }; + }; + }; + + config = { + aux.foundation.stages.stage1.gcc.v8 = { + version = "8.5.0"; + + src = builtins.fetchurl { + url = "https://ftpmirror.gnu.org/gcc/gcc-${cfg.version}/gcc-${cfg.version}.tar.xz"; + sha256 = "0wiEGlEbuDCmEAOXsAQtskzhH2Qtq26m7kSELlMl7VA="; + }; + + gmp = { + # last version to compile with gcc 4.6 + version = "6.2.1"; + src = builtins.fetchurl { + url = "https://ftpmirror.gnu.org/gmp/gmp-${cfg.gmp.version}.tar.xz"; + sha256 = "/UgpkSzd0S+EGBw0Ucx1K+IkZD6H+sSXtp7d2txJtPI="; + }; + }; + + mpfr = { + version = "4.2.1"; + src = builtins.fetchurl { + url = "https://ftpmirror.gnu.org/mpfr/mpfr-${cfg.mpfr.version}.tar.xz"; + sha256 = "J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I="; + }; + }; + + mpc = { + version = "1.3.1"; + src = builtins.fetchurl { + url = "https://ftpmirror.gnu.org/mpc/mpc-${cfg.mpc.version}.tar.gz"; + sha256 = "q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg="; + }; + }; + + isl = { + version = "0.24"; + src = builtins.fetchurl { + url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${cfg.isl.version}.tar.bz2"; + sha256 = "/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA="; + }; + }; + + package = builders.bash.build { + name = "gcc-${cfg.version}"; + + meta = stage1.gcc.meta; + + deps.build.host = [ + stage1.gcc.v46.cxx.package + stage1.binutils.package + stage1.gnumake.package + stage1.gnused.package + stage1.gnugrep.package + stage1.gawk.boot.package + stage1.diffutils.package + stage1.findutils.package + stage1.gnutar.package + stage1.gzip.package + stage1.bzip2.package + stage1.xz.package + ]; + + script = '' + # Unpack + tar xf ${cfg.src} + tar xf ${cfg.gmp.src} + tar xf ${cfg.mpfr.src} + tar xf ${cfg.mpc.src} + tar xf ${cfg.isl.src} + cd gcc-${cfg.version} + + ln -s ../gmp-${cfg.gmp.version} gmp + ln -s ../mpfr-${cfg.mpfr.version} mpfr + ln -s ../mpc-${cfg.mpc.version} mpc + ln -s ../isl-${cfg.isl.version} 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,${stage1.musl.package}/lib/libc.so" + export CXX="g++ -Wl,-dynamic-linker -Wl,${stage1.musl.package}/lib/libc.so" + export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${stage1.musl.package}/lib/libc.so" + export C_INCLUDE_PATH="${stage1.musl.package}/include" + export CPLUS_INCLUDE_PATH="$C_INCLUDE_PATH" + export LIBRARY_PATH="${stage1.musl.package}/lib" + + bash ./configure \ + --prefix=$out \ + --build=${platform.build} \ + --host=${platform.host} \ + --with-native-system-header-dir=/include \ + --with-sysroot=${stage1.musl.package} \ + --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/foundation/src/stages/stage1/gnutar/default.nix b/foundation/src/stages/stage1/gnutar/default.nix index 924b87c..2ade7fd 100644 --- a/foundation/src/stages/stage1/gnutar/default.nix +++ b/foundation/src/stages/stage1/gnutar/default.nix @@ -34,7 +34,7 @@ in { description = lib.options.create { type = lib.types.string; description = "Description for the package."; - default.value = "GNU implementation of the `tar' archiver"; + default.value = "GNU implementation of the `tar` archiver"; }; homepage = lib.options.create { @@ -66,11 +66,11 @@ in { config = { aux.foundation.stages.stage1.gnutar = { - version = "1.12"; + version = "1.35"; src = builtins.fetchurl { url = "https://ftpmirror.gnu.org/tar/tar-${cfg.version}.tar.gz"; - sha256 = "xsN+iIsTbM76uQPFEUn0t71lnWnUrqISRfYQU6V6pgo="; + sha256 = "FNVeMgY+qVJuBX+/Nfyr1TN452l4fv95GcN1WwLStX4="; }; package = builders.bash.boot.build { @@ -79,36 +79,34 @@ in { meta = cfg.meta; deps.build.host = [ - stage1.tinycc.musl.compiler.package - stage1.gnumake.boot.package - stage1.gnused.boot.package + stage1.gcc.v46.cxx.package + stage1.musl.package + stage1.binutils.package + stage1.gnumake.package + stage1.gnused.package stage1.gnugrep.package + stage1.gawk.package + stage1.gzip.package + stage1.gnutar.musl.package ]; script = '' # Unpack - ungz --file ${cfg.src} --output tar.tar - untar --file tar.tar - rm tar.tar + tar xzf ${cfg.src} cd tar-${cfg.version} # Configure - export CC="tcc -B ${stage1.tinycc.musl.libs.package}/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=${platform.build} \ --host=${platform.host} \ - --disable-nls + CC=musl-gcc # Build - make AR="tcc -ar" + make -j $NIX_BUILD_CORES # Install - make install + make -j $NIX_BUILD_CORES install ''; }; diff --git a/foundation/src/stages/stage1/musl/default.nix b/foundation/src/stages/stage1/musl/default.nix index ba25edb..20ef930 100644 --- a/foundation/src/stages/stage1/musl/default.nix +++ b/foundation/src/stages/stage1/musl/default.nix @@ -78,7 +78,7 @@ in { stage1.gnumake.package stage1.gnused.package stage1.gnugrep.package - stage1.gnutar.package + stage1.gnutar.musl.package stage1.gzip.package ];