wip: custom targets

This commit is contained in:
Victor Fuentes 2025-10-16 13:38:08 -07:00
parent 57a4021ce9
commit 0d8ad0c11b
Signed by: vlinkz
GPG key ID: DF727B8D5AF99C64
30 changed files with 262 additions and 149 deletions

View file

@ -69,7 +69,8 @@ in
package.env
// {
inherit (package) name;
inherit script system;
inherit script;
system = (lib.systems.withBuildInfo system).double;
outputs = builtins.attrNames (lib.packages.getOutputs package);

View file

@ -67,7 +67,7 @@ in
else if value == "@build" || value == "@host" then
[ value ]
else if lib.strings.hasPrefix "@" value then
lib.systems.doubles.${lib.strings.removePrefix "@" value}
lib.systems.targets.${lib.strings.removePrefix "@" value}
else
[ value ];
};

View file

@ -24,15 +24,28 @@ let
else
lib.attrs.match patterns;
getDoubles =
getTargets =
predicate:
builtins.map lib.systems.into.double (builtins.filter predicate lib.systems.doubles.resolved);
builtins.filter (double: predicate (lib.systems.from.string double)) lib.systems.targets.all;
in
{
options = {
systems.extraTargets = (
lib.options.create {
description = "Map of extra target systems.";
default.value = { };
type = lib.types.attrs.of (lib.types.either lib.types.string lib.types.attrs.any);
apply = value: builtins.mapAttrs (_: x: if builtins.isString x then { system = x; } else x) value;
}
);
};
config = {
lib.systems = {
match = builtins.mapAttrs (lib.fp.const matchAnyAttrs) lib.systems.patterns;
extraTargets = config.systems.extraTargets;
platforms = {
pc = {
linux-kernel = {
@ -1753,7 +1766,12 @@ in
string =
value:
let
parts = lib.strings.split "-" value;
value' =
if lib.attrs.has [ value ] config.systems.extraTargets then
config.systems.extraTargets."${value}".system
else
value;
parts = lib.strings.split "-" value';
skeleton = lib.systems.skeleton parts;
system = lib.systems.create (lib.systems.from.skeleton skeleton);
in
@ -2327,8 +2345,8 @@ in
];
};
doubles = {
resolved = builtins.map lib.systems.from.string lib.systems.doubles.all;
targets = {
resolved = builtins.map lib.systems.from.string lib.systems.targets.all;
all = [
# Cygwin
@ -2433,91 +2451,92 @@ in
# Windows
"x86_64-windows"
"i686-windows"
];
]
++ builtins.attrNames config.systems.extraTargets;
arm = getDoubles lib.systems.match.isAarch32;
armv7 = getDoubles lib.systems.match.isArmv7;
aarch64 = getDoubles lib.systems.match.isAarch64;
x86 = getDoubles lib.systems.match.isx86;
i686 = getDoubles lib.systems.match.isi686;
x86_64 = getDoubles lib.systems.match.isx86_64;
microblaze = getDoubles lib.systems.match.isMicroBlaze;
mips = getDoubles lib.systems.match.isMips;
mmix = getDoubles lib.systems.match.isMmix;
power = getDoubles lib.systems.match.isPower;
riscv = getDoubles lib.systems.match.isRiscV;
riscv32 = getDoubles lib.systems.match.isRiscV32;
riscv64 = getDoubles lib.systems.match.isRiscV64;
rx = getDoubles lib.systems.match.isRx;
vc4 = getDoubles lib.systems.match.isVc4;
or1k = getDoubles lib.systems.match.isOr1k;
m68k = getDoubles lib.systems.match.isM68k;
s390 = getDoubles lib.systems.match.isS390;
s390x = getDoubles lib.systems.match.isS390x;
loongarch64 = getDoubles lib.systems.match.isLoongArch64;
js = getDoubles lib.systems.match.isJavaScript;
arm = getTargets lib.systems.match.isAarch32;
armv7 = getTargets lib.systems.match.isArmv7;
aarch64 = getTargets lib.systems.match.isAarch64;
x86 = getTargets lib.systems.match.isx86;
i686 = getTargets lib.systems.match.isi686;
x86_64 = getTargets lib.systems.match.isx86_64;
microblaze = getTargets lib.systems.match.isMicroBlaze;
mips = getTargets lib.systems.match.isMips;
mmix = getTargets lib.systems.match.isMmix;
power = getTargets lib.systems.match.isPower;
riscv = getTargets lib.systems.match.isRiscV;
riscv32 = getTargets lib.systems.match.isRiscV32;
riscv64 = getTargets lib.systems.match.isRiscV64;
rx = getTargets lib.systems.match.isRx;
vc4 = getTargets lib.systems.match.isVc4;
or1k = getTargets lib.systems.match.isOr1k;
m68k = getTargets lib.systems.match.isM68k;
s390 = getTargets lib.systems.match.isS390;
s390x = getTargets lib.systems.match.isS390x;
loongarch64 = getTargets lib.systems.match.isLoongArch64;
js = getTargets lib.systems.match.isJavaScript;
bigEndian = getDoubles lib.systems.match.isBigEndian;
littleEndian = getDoubles lib.systems.match.isLittleEndian;
bigEndian = getTargets lib.systems.match.isBigEndian;
littleEndian = getTargets lib.systems.match.isLittleEndian;
cygwin = getDoubles lib.systems.match.isCygwin;
darwin = getDoubles lib.systems.match.isDarwin;
freebsd = getDoubles lib.systems.match.isFreeBSD;
cygwin = getTargets lib.systems.match.isCygwin;
darwin = getTargets lib.systems.match.isDarwin;
freebsd = getTargets lib.systems.match.isFreeBSD;
# Should be better, but MinGW is unclear.
gnu =
getDoubles (
getTargets (
lib.attrs.match {
kernel = types.kernels.linux;
abi = types.abis.gnu;
}
)
++ getDoubles (
++ getTargets (
lib.attrs.match {
kernel = types.kernels.linux;
abi = types.abis.gnueabi;
}
)
++ getDoubles (
++ getTargets (
lib.attrs.match {
kernel = types.kernels.linux;
abi = types.abis.gnueabihf;
}
)
++ getDoubles (
++ getTargets (
lib.attrs.match {
kernel = types.kernels.linux;
abi = types.abis.gnuabin32;
}
)
++ getDoubles (
++ getTargets (
lib.attrs.match {
kernel = types.kernels.linux;
abi = types.abis.gnuabi64;
}
)
++ getDoubles (
++ getTargets (
lib.attrs.match {
kernel = types.kernels.linux;
abi = types.abis.gnuabielfv1;
}
)
++ getDoubles (
++ getTargets (
lib.attrs.match {
kernel = types.kernels.linux;
abi = types.abis.gnuabielfv2;
}
);
illumos = getDoubles lib.systems.match.isSunOS;
linux = getDoubles lib.systems.match.isLinux;
netbsd = getDoubles lib.systems.match.isNetBSD;
openbsd = getDoubles lib.systems.match.isOpenBSD;
unix = getDoubles lib.systems.match.isUnix;
wasi = getDoubles lib.systems.match.isWasi;
redox = getDoubles lib.systems.match.isRedox;
windows = getDoubles lib.systems.match.isWindows;
genode = getDoubles lib.systems.match.isGenode;
illumos = getTargets lib.systems.match.isSunOS;
linux = getTargets lib.systems.match.isLinux;
netbsd = getTargets lib.systems.match.isNetBSD;
openbsd = getTargets lib.systems.match.isOpenBSD;
unix = getTargets lib.systems.match.isUnix;
wasi = getTargets lib.systems.match.isWasi;
redox = getTargets lib.systems.match.isRedox;
windows = getTargets lib.systems.match.isWindows;
genode = getTargets lib.systems.match.isGenode;
embedded = getDoubles lib.systems.match.isNone;
embedded = getTargets lib.systems.match.isNone;
mesaPlatforms = [
"i686-linux"
@ -2538,7 +2557,14 @@ in
withBuildInfo =
args:
let
settings = if builtins.isString args then { system = args; } else args;
settings =
if builtins.isString args then
if lib.attrs.has [ args ] config.systems.extraTargets then
config.systems.extraTargets."${args}"
else
{ system = args; }
else
args;
resolved = {
system = lib.systems.from.string (if settings ? triple then settings.triple else settings.system);

View file

@ -769,8 +769,8 @@ in
description = "The built derivations for all platforms.";
type = lib.types.raw;
writable = false;
default.value = lib.attrs.generate lib.systems.doubles.all (
build: lib.attrs.generate lib.systems.doubles.all (host: lib.packages.build config build host)
default.value = lib.attrs.generate lib.systems.targets.all (
build: lib.attrs.generate lib.systems.targets.all (host: lib.packages.build config build host)
);
};

View file

@ -78,7 +78,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};
@ -92,17 +92,12 @@ in
configure =
let
flags = builtins.concatStringsSep " " (
[
"--prefix=$out"
"--build=${platform.build.triple}"
"--host=${platform.host.triple}"
"--enable-static-link"
]
++ lib.lists.when (config.platform.host == "i686-linux") [
"--without-bash-malloc"
]
);
flags = builtins.concatStringsSep " " ([
"--prefix=$out"
"--build=${platform.build.triple}"
"--host=${platform.host.triple}"
"--without-bash-malloc"
]);
in
''
# Configure

View file

@ -28,7 +28,7 @@ in
settings = {
target = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
default.value = config.platform.host;
};
allTargets = lib.options.create {
description = "Include all targets (dramatically increases size of binaries).";
@ -38,7 +38,7 @@ in
};
target = lib.options.create {
type = lib.types.raw;
default.value = lib.attrs.generate lib.systems.doubles.all (
default.value = lib.attrs.generate lib.systems.targets.all (
target:
(config.extend { settings.target = target; })
.packages.${config.platform.build}.${config.platform.host}

View file

@ -11,6 +11,7 @@ let
platform = {
build = lib.systems.withBuildInfo config.platform.build;
host = lib.systems.withBuildInfo config.platform.host;
target = lib.systems.withBuildInfo config.settings.target;
};
version = lib.strings.removeSuffix "-stage1" config.version;
@ -45,8 +46,8 @@ let
++ lib.lists.when (config.settings.allTargets) [
"--enable-target=all"
]
++ lib.lists.when (config.settings.target != null) [
"--target=${(lib.systems.withBuildInfo config.settings.target).triple}"
++ lib.lists.when (platform.host.triple != platform.target.triple) [
"--target=${platform.target.triple}"
];
in
{
@ -54,7 +55,7 @@ in
settings = {
target = lib.options.create {
type = lib.types.nullish lib.types.string;
default.value = null;
default.value = config.platform.host;
};
allTargets = lib.options.create {
description = "Include all targets (dramatically increases size of binaries).";
@ -64,7 +65,7 @@ in
};
target = lib.options.create {
type = lib.types.raw;
default.value = lib.attrs.generate lib.systems.doubles.all (
default.value = lib.attrs.generate lib.systems.targets.all (
target:
(config.extend { settings.target = target; })
.packages.${config.platform.build}.${config.platform.host}
@ -137,7 +138,7 @@ in
}
)
// (lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
});
};

View file

@ -77,7 +77,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -68,7 +68,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -85,7 +85,7 @@ in
)
// lib.attrs.when (config.platform.build != config.platform.host) {
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
};
};

View file

@ -79,7 +79,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -79,7 +79,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -79,7 +79,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -7,23 +7,34 @@ let
builders
;
platform = {
build = lib.systems.withBuildInfo config.platform.build;
host = lib.systems.withBuildInfo config.platform.host;
target = lib.systems.withBuildInfo config.settings.target;
};
package =
if
config.platform.build == config.platform.host && config.platform.host != config.settings.target
platform.build.triple == platform.host.triple && platform.host.triple != platform.target.triple
then
packages.foundation.gcc.versions."13.2.0-stage2".extend {
platform = lib.modules.overrides.force config.platform;
settings.target = config.settings.target;
}
else if
config.platform.build != config.platform.host && config.platform.host == config.settings.target
platform.build.triple != platform.host.triple && platform.host.triple == platform.target.triple
then
packages.foundation.gcc.versions."13.2.0-stage3".extend {
platform = lib.modules.overrides.force config.platform;
}
else if
platform.build.triple != platform.host.triple && platform.host.triple != platform.target.triple
then
throw "Canadian cross is not supported"
else
packages.foundation.gcc.versions."13.2.0-stage4".extend {
platform = lib.modules.overrides.force config.platform;
settings.target = config.settings.target;
};
in
{
@ -35,7 +46,7 @@ in
};
target = lib.options.create {
type = lib.types.raw;
default.value = lib.attrs.generate lib.systems.doubles.all (
default.value = lib.attrs.generate lib.systems.targets.all (
target:
(config.extend { settings.target = target; })
.packages.${config.platform.build}.${config.platform.host}

View file

@ -81,7 +81,7 @@ in
};
target = lib.options.create {
type = lib.types.raw;
default.value = lib.attrs.generate lib.systems.doubles.all (
default.value = lib.attrs.generate lib.systems.targets.all (
target:
(config.extend { settings.target = target; })
.packages.${config.platform.build}.${config.platform.host}

View file

@ -30,10 +30,10 @@ let
];
gccFlags = [
"-Wl,-dynamic-linker=${config.deps.host.glibc.dynamicLinker}"
"-Wl,-rpath,${config.deps.host.glibc.package}/lib"
"-L${config.deps.host.glibc.package}/lib"
"-B${config.deps.host.glibc.package}/lib"
"-Wl,-dynamic-linker=${config.deps.host.libc.dynamicLinker}"
"-Wl,-rpath,${config.deps.host.libc.package}/lib"
"-L${config.deps.host.libc.package}/lib"
"-B${config.deps.host.libc.package}/lib"
"-L${config.package.outPath}${libPrefix}/lib"
"-B${config.package.outPath}${libPrefix}/lib"
];
@ -49,9 +49,9 @@ let
"--disable-libsanitizer"
"--disable-lto"
"--disable-multilib"
"--with-headers=${config.deps.host.glibc.package}/include"
"--with-headers=${config.deps.host.libc.package}/include"
"--with-build-sysroot=/"
"--with-native-system-header-dir=${config.deps.host.glibc.package}/include"
"--with-native-system-header-dir=${config.deps.host.libc.package}/include"
"--with-build-time-tools=${config.deps.build.binutils-cross.package}/bin"
];
in
@ -84,7 +84,7 @@ in
};
target = lib.options.create {
type = lib.types.raw;
default.value = lib.attrs.generate lib.systems.doubles.all (
default.value = lib.attrs.generate lib.systems.targets.all (
target:
(config.extend { settings.target = target; })
.packages.${config.platform.build}.${config.platform.host}
@ -184,16 +184,26 @@ in
};
host = {
glibc = packages.foundation.glibc.versions."2.38-stage1".extend {
platform.host = lib.modules.overrides.force config.settings.target;
};
libc =
if platform.target.libc == "glibc" then
packages.foundation.glibc.versions."2.38-stage1".extend {
platform.host = lib.modules.overrides.force config.settings.target;
}
else
packages.foundation.musl.versions."1.2.4-stage1".extend {
platform.host = lib.modules.overrides.force config.settings.target;
};
};
};
env = {
CFLAGS_FOR_TARGET = "-Wl,-dynamic-linker -Wl,${config.deps.host.glibc.dynamicLinker} -B${config.deps.host.glibc.package}/lib";
LDFLAGS_FOR_TARGET = "-L$(pwd)/${platform.target.triple}/libgcc -L${config.deps.host.glibc.package}/lib";
LIBRARY_PATH = "${config.deps.host.glibc.package}/lib";
CFLAGS_FOR_TARGET = builtins.concatStringsSep " " [
"-Wl,-dynamic-linker=${config.deps.host.libc.dynamicLinker}"
"-Wl,-rpath,${config.deps.host.libc.package}/lib"
"-B${config.deps.host.libc.package}/lib"
];
LDFLAGS_FOR_TARGET = "-L$(pwd)/${platform.target.triple}/libgcc -L${config.deps.host.libc.package}/lib";
LIBRARY_PATH = "${config.deps.host.libc.package}/lib";
};
hooks = ctx: {
@ -239,9 +249,9 @@ in
# TODO(vlinkz) Hack to fix missing crti.o and crtn.o. Figure out how to properly find their paths.
mkdir gcc
ln -sv ${config.deps.host.glibc.package}/lib/{crti.o,crtn.o} gcc
ln -sv ${config.deps.host.libc.package}/lib/{crti.o,crtn.o} gcc
mkdir -p ${platform.target.triple}/libstdc++-v3/src
ln -sv ${config.deps.host.glibc.package}/lib/{crti.o,crtn.o} ${platform.target.triple}/libstdc++-v3/src
ln -sv ${config.deps.host.libc.package}/lib/{crti.o,crtn.o} ${platform.target.triple}/libstdc++-v3/src
bash ../configure ${builtins.concatStringsSep " " configureFlags}
'';

View file

@ -21,10 +21,10 @@ let
];
gccFlags = [
"-Wl,-dynamic-linker=${config.deps.host.glibc.dynamicLinker}"
"-Wl,-rpath,${config.deps.host.glibc.package}/lib"
"-L${config.deps.host.glibc.package}/lib"
"-B${config.deps.host.glibc.package}/lib"
"-Wl,-dynamic-linker=${config.deps.host.libc.dynamicLinker}"
"-Wl,-rpath,${config.deps.host.libc.package}/lib"
"-L${config.deps.host.libc.package}/lib"
"-B${config.deps.host.libc.package}/lib"
"-L${config.package.outPath}/lib"
"-B${config.package.outPath}/lib"
];
@ -39,7 +39,7 @@ let
"--disable-bootstrap"
"--disable-libsanitizer"
"--disable-multilib"
"--with-native-system-header-dir=${config.deps.host.glibc.package}/include"
"--with-native-system-header-dir=${config.deps.host.libc.package}/include"
"--with-gxx-include-dir=${builtins.placeholder "out"}/include/c++/${config.version}/"
"--with-build-sysroot=/"
];
@ -142,7 +142,11 @@ in
xz = packages.foundation.xz.versions."5.4.3-bootstrap";
binutils = packages.foundation.binutils.versions."2.41-bootstrap";
gcc = packages.foundation.gcc.versions."13.2.0-stage4";
glibc = packages.foundation.glibc.versions."2.38-bootstrap";
libc =
if platform.host.libc == "glibc" then
packages.foundation.glibc.versions."2.38-bootstrap"
else
packages.foundation.musl.versions."1.2.4-bootstrap";
}
else
{
@ -159,27 +163,52 @@ in
xz = packages.foundation.xz.versions."5.4.3-stage1-passthrough";
binutils = packages.foundation.binutils.versions."2.41-stage1";
gcc = packages.foundation.gcc.versions."13.2.0-stage4";
glibc = packages.foundation.glibc.versions."2.38-stage1-passthrough";
libc =
if platform.host.libc == "glibc" then
packages.foundation.glibc.versions."2.38-stage1-passthrough"
else
packages.foundation.musl.versions."1.2.4-stage1-passthrough";
}
)
// {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
host = {
glibc = packages.foundation.glibc.versions."2.38-stage1";
libc =
if platform.host.libc == "glibc" then
packages.foundation.glibc.versions."2.38-stage1"
else
packages.foundation.musl.versions."1.2.4-stage1";
};
};
env = rec {
CFLAGS_FOR_BUILD = "-Wl,-dynamic-linker -Wl,${config.deps.build.glibc.dynamicLinker} -B${config.deps.build.glibc.package}/lib";
LDFLAGS_FOR_BUILD = "-L${config.deps.build.gcc.package}/lib -L${config.deps.build.glibc.package}/lib -Wl,-rpath,${config.deps.build.gcc.package}/lib -Wl,-rpath,${config.deps.build.glibc.package}/lib";
CFLAGS_FOR_TARGET = "-Wl,-dynamic-linker -Wl,${config.deps.host.glibc.dynamicLinker} -B${config.deps.host.glibc.package}/lib";
LDFLAGS_FOR_TARGET = "-L$(pwd)/${platform.host.triple}/libgcc -L${config.deps.host.glibc.package}/lib";
CFLAGS = CFLAGS_FOR_TARGET;
LDFLAGS = LDFLAGS_FOR_TARGET;
LIBRARY_PATH = "${config.deps.host.glibc.package}/lib";
env = {
CFLAGS_FOR_BUILD = builtins.concatStringsSep " " [
"-Wl,-dynamic-linker=${config.deps.build.libc.dynamicLinker}"
"-Wl,-rpath,${config.deps.build.libc.package}/lib"
"-B${config.deps.build.libc.package}/lib"
"-Wl,-rpath,${config.deps.build.gcc.package}/lib"
"-B${config.deps.build.gcc.package}/lib"
];
LDFLAGS_FOR_BUILD = builtins.concatStringsSep " " [
"-Wl,-rpath,${config.deps.build.gcc.package}/lib"
"-Wl,-rpath,${config.deps.build.libc.package}/lib"
];
CFLAGS_FOR_TARGET = builtins.concatStringsSep " " [
"-Wl,-dynamic-linker=${config.deps.host.libc.dynamicLinker}"
"-Wl,-rpath,${builtins.placeholder "out"}/lib"
"-B${builtins.placeholder "out"}/lib"
"-Wl,-rpath,${config.deps.host.libc.package}/lib"
"-B${config.deps.host.libc.package}/lib"
];
LDFLAGS_FOR_TARGET = builtins.concatStringsSep " " [
"-L$(pwd)/${platform.host.triple}/libgcc"
"-Wl,-rpath,${builtins.placeholder "out"}/lib"
"-Wl,-rpath,${config.deps.host.libc.package}/lib"
];
LIBRARY_PATH = "${config.deps.host.libc.package}/lib";
};
hooks = ctx: {

View file

@ -14,6 +14,7 @@ let
platform = {
build = lib.systems.withBuildInfo config.platform.build;
host = lib.systems.withBuildInfo config.platform.host;
target = lib.systems.withBuildInfo config.settings.target;
};
patches = [
@ -21,10 +22,10 @@ let
];
gccFlags = [
"-Wl,-dynamic-linker=${config.deps.host.glibc.dynamicLinker}"
"-Wl,-rpath,${config.deps.host.glibc.package}/lib"
"-L${config.deps.host.glibc.package}/lib"
"-B${config.deps.host.glibc.package}/lib"
"-Wl,-dynamic-linker=${config.deps.host.libc.dynamicLinker}"
"-Wl,-rpath,${config.deps.host.libc.package}/lib"
"-L${config.deps.host.libc.package}/lib"
"-B${config.deps.host.libc.package}/lib"
"-L${config.package.outPath}/lib"
"-B${config.package.outPath}/lib"
];
@ -39,7 +40,7 @@ let
"--disable-libsanitizer"
"--disable-multilib"
"--with-build-sysroot=/"
"--with-native-system-header-dir=${config.deps.host.glibc.package}/include"
"--with-native-system-header-dir=${config.deps.host.libc.package}/include"
];
in
{
@ -63,6 +64,16 @@ in
type = lib.types.string;
description = "Version of isl.";
};
settings.target = lib.options.create {
type = lib.types.string;
default.value = config.platform.host;
description = "Target of the compiler";
apply =
value:
assert (lib.systems.withBuildInfo value).triple == platform.host.triple;
value;
};
};
config = {
@ -146,17 +157,33 @@ in
host =
if (config.platform.build == "i686-linux") then
{
glibc = packages.foundation.glibc.versions."2.38-bootstrap";
libc =
if platform.host.libc == "glibc" then
packages.foundation.glibc.versions."2.38-bootstrap"
else
packages.foundation.musl.versions."1.2.4-bootstrap";
}
else
{
glibc = packages.foundation.glibc.versions."2.38-stage1-passthrough";
libc =
if platform.host.libc == "glibc" then
packages.foundation.glibc.versions."2.38-stage1-passthrough"
else
packages.foundation.musl.versions."1.2.4-stage1-passthrough";
};
};
env = {
CFLAGS_FOR_TARGET = "-Wl,-dynamic-linker -Wl,${config.deps.host.glibc.dynamicLinker}";
LIBRARY_PATH = "${config.deps.host.glibc.package}/lib";
CFLAGS_FOR_TARGET = builtins.concatStringsSep " " [
"-Wl,-dynamic-linker=${config.deps.host.libc.dynamicLinker}"
"-Wl,-rpath,${builtins.placeholder "out"}/lib"
"-Wl,-rpath,${config.deps.host.libc.package}/lib"
];
LDFLAGS_FOR_TARGET = builtins.concatStringsSep " " [
"-Wl,-rpath,${builtins.placeholder "out"}/lib"
"-Wl,-rpath,${config.deps.host.libc.package}/lib"
];
LIBRARY_PATH = "${config.deps.host.libc.package}/lib";
};
hooks = ctx: {

View file

@ -26,7 +26,6 @@ in
options = {
dynamicLinker = lib.options.create {
type = lib.types.string;
default = "ld-linux-x86-64.so.2";
description = "The dynamic linker/loader to be used.";
};
};

View file

@ -19,7 +19,7 @@ in
options = {
dynamicLinker = lib.options.create {
type = lib.types.string;
default = "ld-linux-x86-64.so.2";
default.value = "ld-linux-x86-64.so.2";
description = "The dynamic linker/loader to be used.";
};
};

View file

@ -79,7 +79,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -79,7 +79,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -85,7 +85,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -79,7 +79,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -79,7 +79,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -79,7 +79,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -79,7 +79,7 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-passthrough".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
};

View file

@ -1,10 +1,18 @@
{ global }:
{ config, global }:
let
inherit (global) lib builders;
inherit (global.internal.packages) foundation;
in
{
options = {
dynamicLinker = lib.options.create {
type = lib.types.string;
default.value = "${config.package.outPath}/lib/libc.so";
description = "The dynamic linker/loader to be used.";
};
};
config = {
meta = {
description = "An efficient, small, quality libc implementation.";

View file

@ -23,6 +23,14 @@ let
};
in
{
options = {
dynamicLinker = lib.options.create {
type = lib.types.string;
default.value = "${config.package.outPath}/lib/libc.so";
description = "The dynamic linker/loader to be used.";
};
};
config = {
meta = {
description = "An efficient, small, quality libc implementation.";

View file

@ -12,6 +12,14 @@ let
in
{
options = {
dynamicLinker = lib.options.create {
type = lib.types.string;
default.value = "${config.package.outPath}/lib/libc.so";
description = "The dynamic linker/loader to be used.";
};
};
config = {
meta = {
description = "An efficient, small, quality libc implementation.";
@ -67,16 +75,9 @@ in
}
)
// lib.attrs.when (config.platform.build != config.platform.host) {
gcc = packages.foundation.gcc.versions."13.2.0-stage2".target.${config.platform.host};
binutils = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
gcc-cross = packages.foundation.gcc.versions."13.2.0-stage1".target.${config.platform.host};
binutils-cross = packages.foundation.binutils.versions."2.41-stage1".target.${config.platform.host};
};
# target = lib.attrs.when (config.platform.host != config.platform.target) {
# gcc = packages.foundation.gcc.versions."13.2.0-stage2";
# binutils = packages.foundation.binutils.versions."2.41-stage1";
# };
host = lib.attrs.when (config.platform.build != config.platform.host) {
bash = packages.foundation.bash.versions."5.2.15-stage1";
};
};
phases = {
@ -119,12 +120,9 @@ in
install = ''
# Install
make -j $NIX_BUILD_CORES install
sed -i 's|/bin/sh|${
if (config.platform.build != config.platform.host) then
config.deps.host.bash.package
else
config.deps.build.bash.package
}/bin/bash|' $out/bin/*
${lib.strings.when (config.platform.build == config.platform.host) ''
sed -i 's|/bin/sh|${config.deps.build.bash.package}/bin/bash|' $out/bin/*
''}
ln -s ../lib/libc.so $out/bin/ldd
'';
};