From 0312e3c4cc261e2384fcf372c766a0cf245f3213 Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Sat, 15 Jun 2024 07:08:45 -0700 Subject: [PATCH] feat: working gcc build --- foundation/src/stages/stage2/bash/default.nix | 2 + lib/src/dag/default.nix | 4 + tidepool/flake.lock | 16 +- tidepool/src/builders/basic.nix | 17 +- tidepool/src/export.nix | 5 +- tidepool/src/lib/packages.nix | 4 +- tidepool/src/lib/types.nix | 17 +- tidepool/src/mirrors/default.nix | 5 + tidepool/src/mirrors/gnu.nix | 9 + tidepool/src/modules.nix | 1 + tidepool/src/packages/aux/foundation.nix | 41 ---- tidepool/src/packages/default.nix | 4 +- tidepool/src/packages/foundation/default.nix | 43 ++++ .../src/packages/foundation/gcc/default.nix | 203 ++++++++++++++++++ 14 files changed, 302 insertions(+), 69 deletions(-) create mode 100644 tidepool/src/mirrors/default.nix create mode 100644 tidepool/src/mirrors/gnu.nix delete mode 100644 tidepool/src/packages/aux/foundation.nix create mode 100644 tidepool/src/packages/foundation/default.nix create mode 100644 tidepool/src/packages/foundation/gcc/default.nix diff --git a/foundation/src/stages/stage2/bash/default.nix b/foundation/src/stages/stage2/bash/default.nix index 11e6e7f..4ea4295 100644 --- a/foundation/src/stages/stage2/bash/default.nix +++ b/foundation/src/stages/stage2/bash/default.nix @@ -76,6 +76,7 @@ in { deps.build.host = [ stage1.gcc.package stage1.musl.package + stage1.coreutils.package stage1.binutils.package stage1.gnumake.package stage1.gnupatch.package @@ -110,6 +111,7 @@ in { make -j $NIX_BUILD_CORES install-strip rm $out/bin/bashbug + ln -s $out/bin/bash $out/bin/sh ''; }; }; diff --git a/lib/src/dag/default.nix b/lib/src/dag/default.nix index 432ded3..a904740 100644 --- a/lib/src/dag/default.nix +++ b/lib/src/dag/default.nix @@ -58,6 +58,10 @@ lib: { else sorted; }; + apply = { + # defaults = graph: defaults: + }; + ## Map over the entries in a DAG and modify their values. ## ## @type (String -> a -> b) -> Dag a -> Dag b diff --git a/tidepool/flake.lock b/tidepool/flake.lock index 8ec01e0..4572262 100644 --- a/tidepool/flake.lock +++ b/tidepool/flake.lock @@ -8,10 +8,10 @@ }, "locked": { "dir": "foundation", - "dirtyRev": "2989fdc4fe153f13e7b6b476476805b03c419f0c-dirty", - "dirtyShortRev": "2989fdc-dirty", - "lastModified": 1718444137, - "narHash": "sha256-gArdjry0N4et4B+wQa31JyLJ448JWd9OFA1Roe3EOAc=", + "dirtyRev": "6bd35bf4d5f24b8e91d8afa589ea3088796b2baa-dirty", + "dirtyShortRev": "6bd35bf-dirty", + "lastModified": 1718450285, + "narHash": "sha256-/i3RlOudzZdl6UBdhMDRBAgVQTHOZDXEkSfRUw77aK8=", "type": "git", "url": "file:../?dir=foundation" }, @@ -24,10 +24,10 @@ "lib": { "locked": { "dir": "lib", - "dirtyRev": "2989fdc4fe153f13e7b6b476476805b03c419f0c-dirty", - "dirtyShortRev": "2989fdc-dirty", - "lastModified": 1718444137, - "narHash": "sha256-gArdjry0N4et4B+wQa31JyLJ448JWd9OFA1Roe3EOAc=", + "dirtyRev": "6bd35bf4d5f24b8e91d8afa589ea3088796b2baa-dirty", + "dirtyShortRev": "6bd35bf-dirty", + "lastModified": 1718450285, + "narHash": "sha256-/i3RlOudzZdl6UBdhMDRBAgVQTHOZDXEkSfRUw77aK8=", "type": "git", "url": "file:../?dir=lib" }, diff --git a/tidepool/src/builders/basic.nix b/tidepool/src/builders/basic.nix index ba2b042..ccde394 100644 --- a/tidepool/src/builders/basic.nix +++ b/tidepool/src/builders/basic.nix @@ -37,13 +37,16 @@ in { SHELL = cfg.executable; - PATH = lib.paths.bin ( - (lib'.packages.dependencies.getPackages package.deps.build.host) - ++ [ - foundation.stage2-bash - foundation.stage2-coreutils - ] - ); + PATH = let + bins = lib.paths.bin ( + (lib'.packages.dependencies.getPackages package.deps.build.host) + ++ [ + foundation.stage2-bash + foundation.stage2-coreutils + ] + ); + in + builtins.concatStringsSep ":" ([bins] ++ (lib.lists.when (package.env ? PATH) [package.env.PATH])); builder = cfg.executable; diff --git a/tidepool/src/export.nix b/tidepool/src/export.nix index 0b4c052..ba35e4a 100644 --- a/tidepool/src/export.nix +++ b/tidepool/src/export.nix @@ -12,8 +12,9 @@ in { modules = import ./modules.nix; packages = { - example-x = config.packages.example.x; - cross-example-x-x86_64-linux = config.packages.cross.x86_64-linux.example.x; + foundation-gcc = config.packages.foundation.gcc; + # example-x = config.packages.example.x; + # cross-example-x-x86_64-linux = config.packages.cross.x86_64-linux.example.x; }; }; }; diff --git a/tidepool/src/lib/packages.nix b/tidepool/src/lib/packages.nix index a2a9959..b6bc0ce 100644 --- a/tidepool/src/lib/packages.nix +++ b/tidepool/src/lib/packages.nix @@ -17,14 +17,14 @@ getLatest = alias: let versions = builtins.attrNames alias.versions; - sorted = builtins.sort (builtins.compareVersions) versions; + sorted = builtins.sort (lib.versions.gte) versions; in builtins.head sorted; build = package: system: cross: let resolved = if package ? versions - then package.versions.${config.preferences.packages.version} or (lib'.packages.getLatest package) + then package.versions.${config.preferences.packages.version} or (package.versions.${lib'.packages.getLatest package}) else package; buildDependencies = builtins.mapAttrs (name: dep: lib'.packages.build dep system cross); diff --git a/tidepool/src/lib/types.nix b/tidepool/src/lib/types.nix index 8945019..414d5df 100644 --- a/tidepool/src/lib/types.nix +++ b/tidepool/src/lib/types.nix @@ -82,13 +82,6 @@ extend = lib.options.create { description = "Extend the package's submodules with additional configuration."; type = lib.types.function lib.types.raw; - default.value = value: - meta.extend { - modules = - if builtins.isAttrs value - then [{config = value;}] - else lib.lists.from.any value; - }; }; name = lib.options.create { @@ -298,6 +291,16 @@ default.value = config.builder.build config; }; }; + + config = { + extend = value: + meta.extend { + modules = + if builtins.isAttrs value + then [{config = value;}] + else lib.lists.from.any value; + }; + }; }); }; }; diff --git a/tidepool/src/mirrors/default.nix b/tidepool/src/mirrors/default.nix new file mode 100644 index 0000000..6de6799 --- /dev/null +++ b/tidepool/src/mirrors/default.nix @@ -0,0 +1,5 @@ +{ + includes = [ + ./gnu.nix + ]; +} diff --git a/tidepool/src/mirrors/gnu.nix b/tidepool/src/mirrors/gnu.nix new file mode 100644 index 0000000..a38a329 --- /dev/null +++ b/tidepool/src/mirrors/gnu.nix @@ -0,0 +1,9 @@ +{lib}: { + options.mirrors = { + gnu = lib.options.create { + description = "The GNU mirror to use"; + type = lib.types.string; + default.value = "https://ftp.gnu.org/gnu"; + }; + }; +} diff --git a/tidepool/src/modules.nix b/tidepool/src/modules.nix index 0b97ad5..3c0e055 100644 --- a/tidepool/src/modules.nix +++ b/tidepool/src/modules.nix @@ -2,5 +2,6 @@ builders = ./builders; exports = ./exports; lib = ./lib; + mirrors = ./mirrors; packages = ./packages; } diff --git a/tidepool/src/packages/aux/foundation.nix b/tidepool/src/packages/aux/foundation.nix deleted file mode 100644 index 2d769e7..0000000 --- a/tidepool/src/packages/aux/foundation.nix +++ /dev/null @@ -1,41 +0,0 @@ -{ - lib, - lib', - config, - options, -}: let - builders = config.builders; -in { - config = { - packages = { - example = { - x = { - versions = { - "latest" = {config}: { - config = { - meta = { - platforms = ["i686-linux" "x86_64-linux"]; - }; - - pname = "x"; - version = "1.0.0"; - - builder = builders.basic; - - phases = { - build = '' - make --build ${config.platform.build.double} --host ${config.platform.host.double} - ''; - - install = lib.dag.entry.after ["build"] '' - make install DESTDIR=$out - ''; - }; - }; - }; - }; - }; - }; - }; - }; -} diff --git a/tidepool/src/packages/default.nix b/tidepool/src/packages/default.nix index 555922c..3ef6b4a 100644 --- a/tidepool/src/packages/default.nix +++ b/tidepool/src/packages/default.nix @@ -8,7 +8,7 @@ packages = builtins.removeAttrs config.packages ["cross"]; in { includes = [ - ./aux/foundation.nix + ./foundation ]; options = { @@ -37,7 +37,7 @@ in { }; }; - config.packages.cross = lib.attrs.generate doubles ( + config.packages.config.cross = lib.attrs.generate doubles ( system: builtins.mapAttrs ( diff --git a/tidepool/src/packages/foundation/default.nix b/tidepool/src/packages/foundation/default.nix new file mode 100644 index 0000000..5772791 --- /dev/null +++ b/tidepool/src/packages/foundation/default.nix @@ -0,0 +1,43 @@ +{ + lib, + lib', + config, + options, +}: { + includes = [ + ./gcc + ]; + + config = { + packages = { + # example = { + # x = { + # versions = { + # "latest" = {config}: { + # config = { + # meta = { + # platforms = ["i686-linux" "x86_64-linux"]; + # }; + + # pname = "x"; + # version = "1.0.0"; + + # builder = builders.basic; + + # phases = { + # build = '' + # make --build ${config.platform.build.double} --host ${config.platform.host.double} + # ''; + + # install = lib.dag.entry.after ["build"] '' + # make install DESTDIR=$out + # ''; + # }; + # }; + # }; + # }; + # }; + # }; + }; + }; +} diff --git a/tidepool/src/packages/foundation/gcc/default.nix b/tidepool/src/packages/foundation/gcc/default.nix new file mode 100644 index 0000000..5657d52 --- /dev/null +++ b/tidepool/src/packages/foundation/gcc/default.nix @@ -0,0 +1,203 @@ +{ + lib, + lib', + config, + options, +}: let + inherit + (config) + mirrors + builders + # These are the upstream foundational packages exported from the Aux Foundation project. + + foundation + ; +in { + config.packages.foundation.gcc = { + versions = { + "13.2.0" = {config}: { + options = { + src = lib.options.create { + type = lib.types.derivation; + description = "Source for the package."; + }; + + cc = { + src = lib.options.create { + type = lib.types.derivation; + description = "The cc source for the package."; + }; + }; + + gmp = { + src = lib.options.create { + type = lib.types.derivation; + 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.derivation; + 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.derivation; + 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.derivation; + description = "The isl source for the package."; + }; + version = lib.options.create { + type = lib.types.string; + description = "Version of isl."; + }; + }; + }; + + config = { + meta = { + platforms = ["i686-linux"]; + }; + + pname = "gcc"; + version = "13.2.0"; + + builder = builders.basic; + + env = { + PATH = lib.paths.bin [ + foundation.stage2-gcc + foundation.stage2-binutils + foundation.stage2-gnumake + foundation.stage2-gnused + foundation.stage2-gnugrep + foundation.stage2-gawk + foundation.stage2-diffutils + foundation.stage2-findutils + foundation.stage2-gnutar + foundation.stage2-gzip + foundation.stage2-bzip2 + foundation.stage1-xz + ]; + }; + + phases = { + unpack = lib.dag.entry.before ["patch"] '' + # Unpack + tar xf ${config.src} + tar xf ${config.gmp.src} + tar xf ${config.mpfr.src} + tar xf ${config.mpc.src} + tar xf ${config.isl.src} + cd gcc-${config.version} + + ln -s ../gmp-${config.gmp.version} gmp + ln -s ../mpfr-${config.mpfr.version} mpfr + ln -s ../mpc-${config.mpc.version} mpc + ln -s ../isl-${config.isl.version} isl + ''; + + patch = lib.dag.entry.between ["configure"] ["unpack"] '' + # Patch + # force musl even if host triple is gnu + sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host + ''; + + configure = lib.dag.entry.between ["build"] ["patch"] '' + # Configure + export CC="gcc -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so" + export CXX="g++ -Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so" + export CFLAGS_FOR_TARGET="-Wl,-dynamic-linker -Wl,${foundation.stage1-musl}/lib/libc.so" + export LIBRARY_PATH="${foundation.stage1-musl}/lib" + + bash ./configure \ + --prefix=$out \ + --build=${config.platform.build.triple} \ + --host=${config.platform.host.triple} \ + --with-native-system-header-dir=/include \ + --with-sysroot=${foundation.stage1-musl} \ + --enable-languages=c,c++ \ + --disable-bootstrap \ + --disable-libsanitizer \ + --disable-lto \ + --disable-multilib \ + --disable-plugin \ + CFLAGS=-static \ + CXXFLAGS=-static + ''; + + build = lib.dag.entry.between ["install"] ["configure"] '' + # Build + make -j $NIX_BUILD_CORES + ''; + + install = lib.dag.entry.after ["build"] '' + # Install + make -j $NIX_BUILD_CORES install-strip + ''; + }; + + src = builtins.fetchurl { + url = "${mirrors.gnu}/gcc/gcc-${config.version}/gcc-${config.version}.tar.xz"; + sha256 = "4nXnZEKmBnNBon8Exca4PYYTFEAEwEE1KIY9xrXHQ9o="; + }; + + gmp = { + version = "6.3.0"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/gmp/gmp-${config.gmp.version}.tar.xz"; + sha256 = "o8K4AgG4nmhhb0rTC8Zq7kknw85Q4zkpyoGdXENTiJg="; + }; + }; + + mpfr = { + version = "4.2.1"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/mpfr/mpfr-${config.mpfr.version}.tar.xz"; + sha256 = "J3gHNTpnJpeJlpRa8T5Sgp46vXqaW3+yeTiU4Y8fy7I="; + }; + }; + + mpc = { + version = "1.3.1"; + src = builtins.fetchurl { + url = "${mirrors.gnu}/mpc/mpc-${config.mpc.version}.tar.gz"; + sha256 = "q2QkkvXPiCt0qgy3MM1BCoHtzb7IlRg86TDnBsHHWbg="; + }; + }; + + isl = { + version = "0.24"; + src = builtins.fetchurl { + url = "https://gcc.gnu.org/pub/gcc/infrastructure/isl-${config.isl.version}.tar.bz2"; + sha256 = "/PeN2WVsEOuM+fvV9ZoLawE4YgX+GTSzsoegoYmBRcA="; + }; + }; + }; + }; + }; + }; +}