push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,180 @@
# Bootstrappable TCC is a fork from mainline TCC development
# that can be compiled by MesCC
# Build steps adapted from https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/tcc-0.9.26/tcc-0.9.26.kaem
#
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
#
# SPDX-License-Identifier: GPL-3.0-or-later
{
lib,
callPackage,
fetchurl,
kaem,
mes,
mes-libc,
}:
let
inherit (callPackage ./common.nix { }) buildTinyccMes recompileLibc;
version = "unstable-2023-04-20";
rev = "80114c4da6b17fbaabb399cc29f427e368309bc8";
tarball = fetchurl {
url = "https://gitlab.com/janneke/tinycc/-/archive/${rev}/tinycc-${rev}.tar.gz";
sha256 = "1a0cw9a62qc76qqn5sjmp3xrbbvsz2dxrw21lrnx9q0s74mwaxbq";
};
src =
(kaem.runCommand "tinycc-bootstrappable-${version}-source" { } ''
ungz --file ${tarball} --output tinycc.tar
mkdir -p ''${out}
cd ''${out}
untar --file ''${NIX_BUILD_TOP}/tinycc.tar
# Patch
cd tinycc-${rev}
# Static link by default
replace --file libtcc.c --output libtcc.c --match-on "s->ms_extensions = 1;" --replace-with "s->ms_extensions = 1; s->static_link = 1;"
'')
+ "/tinycc-${rev}";
meta = with lib; {
description = "Tiny C Compiler's bootstrappable fork";
homepage = "https://gitlab.com/janneke/tinycc";
license = licenses.lgpl21Only;
teams = [ teams.minimal-bootstrap ];
platforms = [ "i686-linux" ];
};
pname = "tinycc-boot-mes";
tinycc-boot-mes = rec {
compiler =
kaem.runCommand "${pname}-${version}"
{
passthru.tests.get-version =
result:
kaem.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/tcc -version
mkdir ''${out}
'';
}
''
catm config.h
${mes.compiler}/bin/mes --no-auto-compile -e main ${mes.srcPost.bin}/bin/mescc.scm -- \
-S \
-o tcc.s \
-I . \
-D BOOTSTRAP=1 \
-I ${src} \
-D TCC_TARGET_I386=1 \
-D inline= \
-D CONFIG_TCCDIR=\"\" \
-D CONFIG_SYSROOT=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"{B}\" \
-D CONFIG_TCC_ELFINTERP=\"/mes/loader\" \
-D CONFIG_TCC_LIBPATHS=\"{B}\" \
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${mes-libc}/include\" \
-D TCC_LIBGCC=\"${mes-libc}/lib/x86-mes/libc.a\" \
-D CONFIG_TCC_LIBTCC1_MES=0 \
-D CONFIG_TCCBOOT=1 \
-D CONFIG_TCC_STATIC=1 \
-D CONFIG_USE_LIBGCC=1 \
-D TCC_MES_LIBC=1 \
-D TCC_VERSION=\"${version}\" \
-D ONE_SOURCE=1 \
${src}/tcc.c
mkdir -p ''${out}/bin
${mes.compiler}/bin/mes --no-auto-compile -e main ${mes.srcPost.bin}/bin/mescc.scm -- \
-L ${mes.libs}/lib \
-l c+tcc \
-o ''${out}/bin/tcc \
tcc.s
'';
libs = recompileLibc {
inherit pname version;
tcc = compiler;
src = mes-libc;
libtccOptions = mes-libc.CFLAGS;
};
};
# Bootstrap stage build flags obtained from
# https://gitlab.com/janneke/tinycc/-/blob/80114c4da6b17fbaabb399cc29f427e368309bc8/boot.sh
tinycc-boot0 = buildTinyccMes {
pname = "tinycc-boot0";
inherit src version meta;
prev = tinycc-boot-mes;
buildOptions = [
"-D HAVE_LONG_LONG_STUB=1"
"-D HAVE_SETJMP=1"
];
libtccBuildOptions = [
"-D HAVE_LONG_LONG_STUB=1"
];
};
tinycc-boot1 = buildTinyccMes {
pname = "tinycc-boot1";
inherit src version meta;
prev = tinycc-boot0;
buildOptions = [
"-D HAVE_BITFIELD=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
];
libtccBuildOptions = [
"-D HAVE_LONG_LONG=1"
];
};
tinycc-boot2 = buildTinyccMes {
pname = "tinycc-boot2";
inherit src version meta;
prev = tinycc-boot1;
buildOptions = [
"-D HAVE_BITFIELD=1"
"-D HAVE_FLOAT_STUB=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
];
libtccBuildOptions = [
"-D HAVE_FLOAT_STUB=1"
"-D HAVE_LONG_LONG=1"
];
};
tinycc-boot3 = buildTinyccMes {
pname = "tinycc-boot3";
inherit src version meta;
prev = tinycc-boot2;
buildOptions = [
"-D HAVE_BITFIELD=1"
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
];
libtccBuildOptions = [
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
];
};
in
buildTinyccMes {
pname = "tinycc-bootstrappable";
inherit src version meta;
prev = tinycc-boot3;
buildOptions = [
"-D HAVE_BITFIELD=1"
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
];
libtccBuildOptions = [
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
];
}

View File

@@ -0,0 +1,130 @@
{
lib,
kaem,
mes-libc,
}:
rec {
# Recompile libc: crt{1,n,i}, libtcc.a, libc.a, libgetopt.a
recompileLibc =
{
tcc,
pname,
version,
src,
libtccOptions,
}:
let
crt = kaem.runCommand "crt" { } ''
mkdir -p ''${out}/lib
${tcc}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crt1.o ${mes-libc}/lib/crt1.c
${tcc}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crtn.o ${mes-libc}/lib/crtn.c
${tcc}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crti.o ${mes-libc}/lib/crti.c
'';
library =
lib: options: source:
kaem.runCommand "${lib}.a" { } ''
${tcc}/bin/tcc ${options} -c -o ${lib}.o ${source}
${tcc}/bin/tcc -ar cr ''${out} ${lib}.o
'';
libtcc1 = library "libtcc1" libtccOptions "${src}/lib/libtcc1.c";
libc = library "libc" mes-libc.CFLAGS "${mes-libc}/lib/libc.c";
libgetopt = library "libgetopt" mes-libc.CFLAGS "${mes-libc}/lib/libgetopt.c";
in
kaem.runCommand "${pname}-libs-${version}" { } ''
mkdir -p ''${out}/lib
cp ${crt}/lib/crt1.o ''${out}/lib
cp ${crt}/lib/crtn.o ''${out}/lib
cp ${crt}/lib/crti.o ''${out}/lib
cp ${libtcc1} ''${out}/lib/libtcc1.a
cp ${libc} ''${out}/lib/libc.a
cp ${libgetopt} ''${out}/lib/libgetopt.a
'';
buildTinyccMes =
{
pname,
version,
src,
prev,
buildOptions,
libtccBuildOptions,
meta,
}:
let
options = lib.strings.concatStringsSep " " buildOptions;
libtccOptions = lib.strings.concatStringsSep " " (
[
"-c"
"-D"
"TCC_TARGET_I386=1"
]
++ libtccBuildOptions
);
compiler =
kaem.runCommand "${pname}-${version}"
{
inherit pname version meta;
passthru.tests = {
get-version =
result:
kaem.runCommand "${pname}-get-version-${version}" { } ''
${result}/bin/tcc -version
mkdir ''${out}
'';
chain =
result:
kaem.runCommand "${pname}-chain-${version}" { } ''
echo ${prev.compiler.tests.chain or prev.compiler.tests.get-version};
${result}/bin/tcc -version
mkdir ''${out}
'';
};
}
''
catm config.h
mkdir -p ''${out}/bin
${prev.compiler}/bin/tcc \
-B ${prev.libs}/lib \
-g \
-v \
-o ''${out}/bin/tcc \
-D BOOTSTRAP=1 \
${options} \
-I . \
-I ${src} \
-D TCC_TARGET_I386=1 \
-D CONFIG_TCCDIR=\"\" \
-D CONFIG_SYSROOT=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"{B}\" \
-D CONFIG_TCC_ELFINTERP=\"\" \
-D CONFIG_TCC_LIBPATHS=\"{B}\" \
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${mes-libc}/include\" \
-D TCC_LIBGCC=\"libc.a\" \
-D TCC_LIBTCC1=\"libtcc1.a\" \
-D CONFIG_TCCBOOT=1 \
-D CONFIG_TCC_STATIC=1 \
-D CONFIG_USE_LIBGCC=1 \
-D TCC_MES_LIBC=1 \
-D TCC_VERSION=\"${version}\" \
-D ONE_SOURCE=1 \
${src}/tcc.c
'';
libs = recompileLibc {
inherit
pname
version
src
libtccOptions
;
tcc = compiler;
};
in
{
inherit prev compiler libs;
};
}

View File

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

View File

@@ -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 {

View File

@@ -0,0 +1,99 @@
# Build steps adapted from https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/tcc-0.9.27/tcc-0.9.27.kaem
#
# SPDX-FileCopyrightText: 2021-22 fosslinux <fosslinux@aussies.space>
#
# SPDX-License-Identifier: GPL-3.0-or-later
{
lib,
fetchurl,
callPackage,
kaem,
tinycc-bootstrappable,
}:
let
inherit (callPackage ./common.nix { }) buildTinyccMes;
version = "unstable-2023-04-20";
rev = "86f3d8e33105435946383aee52487b5ddf918140";
tarball = fetchurl {
url = "https://repo.or.cz/tinycc.git/snapshot/${rev}.tar.gz";
sha256 = "11idrvbwfgj1d03crv994mpbbbyg63j1k64lw1gjy7mkiifw2xap";
};
src =
(kaem.runCommand "tinycc-${version}-source" { } ''
ungz --file ${tarball} --output tinycc.tar
mkdir -p ''${out}
cd ''${out}
untar --file ''${NIX_BUILD_TOP}/tinycc.tar
# Patch
cd tinycc-${builtins.substring 0 7 rev}
# Static link by default
replace --file libtcc.c --output libtcc.c --match-on "s->ms_extensions = 1;" --replace-with "s->ms_extensions = 1; s->static_link = 1;"
'')
+ "/tinycc-${builtins.substring 0 7 rev}";
meta = with lib; {
description = "Small, fast, and embeddable C compiler and interpreter";
homepage = "https://repo.or.cz/w/tinycc.git";
license = licenses.lgpl21Only;
teams = [ teams.minimal-bootstrap ];
platforms = [ "i686-linux" ];
};
tccdefs = kaem.runCommand "tccdefs-${version}" { } ''
mkdir ''${out}
${tinycc-bootstrappable.compiler}/bin/tcc \
-B ${tinycc-bootstrappable.libs}/lib \
-DC2STR \
-o c2str \
${src}/conftest.c
./c2str ${src}/include/tccdefs.h ''${out}/tccdefs_.h
'';
tinycc-mes-boot = buildTinyccMes {
pname = "tinycc-mes-boot";
inherit src version meta;
prev = tinycc-bootstrappable;
buildOptions = [
"-D HAVE_BITFIELD=1"
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
"-D CONFIG_TCC_PREDEFS=1"
"-I ${tccdefs}"
"-D CONFIG_TCC_SEMLOCK=0"
];
libtccBuildOptions = [
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D CONFIG_TCC_PREDEFS=1"
"-I ${tccdefs}"
"-D CONFIG_TCC_SEMLOCK=0"
];
};
in
buildTinyccMes {
pname = "tinycc-mes";
inherit src version meta;
prev = tinycc-mes-boot;
buildOptions = [
"-std=c99"
"-D HAVE_BITFIELD=1"
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D HAVE_SETJMP=1"
"-D CONFIG_TCC_PREDEFS=1"
"-I ${tccdefs}"
"-D CONFIG_TCC_SEMLOCK=0"
];
libtccBuildOptions = [
"-D HAVE_FLOAT=1"
"-D HAVE_LONG_LONG=1"
"-D CONFIG_TCC_PREDEFS=1"
"-I ${tccdefs}"
"-D CONFIG_TCC_SEMLOCK=0"
];
}

View File

@@ -0,0 +1,163 @@
{
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;
teams = [ teams.minimal-bootstrap ];
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
'';
}

View File

@@ -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 */