feat: working gcc build

This commit is contained in:
Jake Hamilton 2024-06-15 07:08:45 -07:00
parent 6bd35bf4d5
commit 0312e3c4cc
Signed by untrusted user: jakehamilton
GPG key ID: 9762169A1B35EA68
14 changed files with 302 additions and 69 deletions

View file

@ -76,6 +76,7 @@ in {
deps.build.host = [ deps.build.host = [
stage1.gcc.package stage1.gcc.package
stage1.musl.package stage1.musl.package
stage1.coreutils.package
stage1.binutils.package stage1.binutils.package
stage1.gnumake.package stage1.gnumake.package
stage1.gnupatch.package stage1.gnupatch.package
@ -110,6 +111,7 @@ in {
make -j $NIX_BUILD_CORES install-strip make -j $NIX_BUILD_CORES install-strip
rm $out/bin/bashbug rm $out/bin/bashbug
ln -s $out/bin/bash $out/bin/sh
''; '';
}; };
}; };

View file

@ -58,6 +58,10 @@ lib: {
else sorted; else sorted;
}; };
apply = {
# defaults = graph: defaults:
};
## Map over the entries in a DAG and modify their values. ## Map over the entries in a DAG and modify their values.
## ##
## @type (String -> a -> b) -> Dag a -> Dag b ## @type (String -> a -> b) -> Dag a -> Dag b

View file

@ -8,10 +8,10 @@
}, },
"locked": { "locked": {
"dir": "foundation", "dir": "foundation",
"dirtyRev": "2989fdc4fe153f13e7b6b476476805b03c419f0c-dirty", "dirtyRev": "6bd35bf4d5f24b8e91d8afa589ea3088796b2baa-dirty",
"dirtyShortRev": "2989fdc-dirty", "dirtyShortRev": "6bd35bf-dirty",
"lastModified": 1718444137, "lastModified": 1718450285,
"narHash": "sha256-gArdjry0N4et4B+wQa31JyLJ448JWd9OFA1Roe3EOAc=", "narHash": "sha256-/i3RlOudzZdl6UBdhMDRBAgVQTHOZDXEkSfRUw77aK8=",
"type": "git", "type": "git",
"url": "file:../?dir=foundation" "url": "file:../?dir=foundation"
}, },
@ -24,10 +24,10 @@
"lib": { "lib": {
"locked": { "locked": {
"dir": "lib", "dir": "lib",
"dirtyRev": "2989fdc4fe153f13e7b6b476476805b03c419f0c-dirty", "dirtyRev": "6bd35bf4d5f24b8e91d8afa589ea3088796b2baa-dirty",
"dirtyShortRev": "2989fdc-dirty", "dirtyShortRev": "6bd35bf-dirty",
"lastModified": 1718444137, "lastModified": 1718450285,
"narHash": "sha256-gArdjry0N4et4B+wQa31JyLJ448JWd9OFA1Roe3EOAc=", "narHash": "sha256-/i3RlOudzZdl6UBdhMDRBAgVQTHOZDXEkSfRUw77aK8=",
"type": "git", "type": "git",
"url": "file:../?dir=lib" "url": "file:../?dir=lib"
}, },

View file

@ -37,13 +37,16 @@ in {
SHELL = cfg.executable; SHELL = cfg.executable;
PATH = lib.paths.bin ( PATH = let
bins = lib.paths.bin (
(lib'.packages.dependencies.getPackages package.deps.build.host) (lib'.packages.dependencies.getPackages package.deps.build.host)
++ [ ++ [
foundation.stage2-bash foundation.stage2-bash
foundation.stage2-coreutils foundation.stage2-coreutils
] ]
); );
in
builtins.concatStringsSep ":" ([bins] ++ (lib.lists.when (package.env ? PATH) [package.env.PATH]));
builder = cfg.executable; builder = cfg.executable;

View file

@ -12,8 +12,9 @@ in {
modules = import ./modules.nix; modules = import ./modules.nix;
packages = { packages = {
example-x = config.packages.example.x; foundation-gcc = config.packages.foundation.gcc;
cross-example-x-x86_64-linux = config.packages.cross.x86_64-linux.example.x; # example-x = config.packages.example.x;
# cross-example-x-x86_64-linux = config.packages.cross.x86_64-linux.example.x;
}; };
}; };
}; };

View file

@ -17,14 +17,14 @@
getLatest = alias: let getLatest = alias: let
versions = builtins.attrNames alias.versions; versions = builtins.attrNames alias.versions;
sorted = builtins.sort (builtins.compareVersions) versions; sorted = builtins.sort (lib.versions.gte) versions;
in in
builtins.head sorted; builtins.head sorted;
build = package: system: cross: let build = package: system: cross: let
resolved = resolved =
if package ? versions 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; else package;
buildDependencies = builtins.mapAttrs (name: dep: lib'.packages.build dep system cross); buildDependencies = builtins.mapAttrs (name: dep: lib'.packages.build dep system cross);

View file

@ -82,13 +82,6 @@
extend = lib.options.create { extend = lib.options.create {
description = "Extend the package's submodules with additional configuration."; description = "Extend the package's submodules with additional configuration.";
type = lib.types.function lib.types.raw; 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 { name = lib.options.create {
@ -298,6 +291,16 @@
default.value = config.builder.build config; 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;
};
};
}); });
}; };
}; };

View file

@ -0,0 +1,5 @@
{
includes = [
./gnu.nix
];
}

View file

@ -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";
};
};
}

View file

@ -2,5 +2,6 @@
builders = ./builders; builders = ./builders;
exports = ./exports; exports = ./exports;
lib = ./lib; lib = ./lib;
mirrors = ./mirrors;
packages = ./packages; packages = ./packages;
} }

View file

@ -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
'';
};
};
};
};
};
};
};
};
}

View file

@ -8,7 +8,7 @@
packages = builtins.removeAttrs config.packages ["cross"]; packages = builtins.removeAttrs config.packages ["cross"];
in { in {
includes = [ includes = [
./aux/foundation.nix ./foundation
]; ];
options = { options = {
@ -37,7 +37,7 @@ in {
}; };
}; };
config.packages.cross = lib.attrs.generate doubles ( config.packages.config.cross = lib.attrs.generate doubles (
system: system:
builtins.mapAttrs builtins.mapAttrs
( (

View file

@ -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
# '';
# };
# };
# };
# };
# };
# };
};
};
}

View file

@ -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=";
};
};
};
};
};
};
}