Merge pull request #231894 from Ericson2314/parallel-bootstrap

minimal-bootstrap: Parallelize + separate compilers & libs
This commit is contained in:
John Ericson 2023-05-16 09:38:20 -04:00 committed by GitHub
commit a4c5ee1f49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 368 additions and 262 deletions

View file

@ -20,11 +20,18 @@ lib.makeScope
mes = callPackage ./mes { };
mes-libc = callPackage ./mes/libc.nix { };
inherit (callPackage ./stage0-posix { }) kaem m2libc mescc-tools mescc-tools-extra;
stage0-posix = callPackage ./stage0-posix { };
inherit (self.stage0-posix) kaem m2libc mescc-tools mescc-tools-extra;
tinycc-bootstrappable = callPackage ./tinycc/bootstrappable.nix { };
tinycc-mes = callPackage ./tinycc/mes.nix { };
inherit (callPackage ./utils.nix { }) fetchurl derivationWithMeta writeTextFile writeText;
test = kaem.runCommand "minimal-bootstrap-test" {} ''
echo ${mes.compiler.tests.get-version}
echo ${tinycc-mes.compiler.tests.chain}
mkdir ''${out}
'';
})

View file

@ -45,7 +45,7 @@ let
./configure \
--build i686-pc-linux-gnu \
--host i686-pc-linux-gnu \
CC="${tinycc-mes}/bin/tcc -static" \
CC="${tinycc.compiler}/bin/tcc -B ${tinycc.libs}/lib -static" \
ac_cv_func_dup=no
- `ac_cv_func_dup` disabled as mes-libc doesn't implement tmpfile()
@ -148,7 +148,7 @@ in
kaem.runCommand "${pname}-${version}" {
inherit pname version;
nativeBuildInputs = [ tinycc gnupatch ];
nativeBuildInputs = [ tinycc.compiler gnupatch ];
meta = with lib; {
description = "A tool to control the generation of non-source files from sources";
@ -174,7 +174,7 @@ kaem.runCommand "${pname}-${version}" {
cp lib/fnmatch.in.h lib/fnmatch.h
# Compile
alias CC="tcc ${lib.concatStringsSep " " CFLAGS}"
alias CC="tcc -B ${tinycc.libs}/lib ${lib.concatStringsSep " " CFLAGS}"
${lib.concatMapStringsSep "\n" (f: "CC -c ${f}") sources}
# Link

View file

@ -70,7 +70,7 @@ in
kaem.runCommand "${pname}-${version}" {
inherit pname version;
nativeBuildInputs = [ tinycc ];
nativeBuildInputs = [ tinycc.compiler ];
meta = with lib; {
description = "GNU Patch, a program to apply differences to files";
@ -91,7 +91,7 @@ kaem.runCommand "${pname}-${version}" {
catm config.h
# Build
alias CC="tcc ${lib.concatStringsSep " " CFLAGS}"
alias CC="tcc -B ${tinycc.libs}/lib ${lib.concatStringsSep " " CFLAGS}"
${lib.concatMapStringsSep "\n" (f: "CC -c ${f}") sources}
# Link

View file

@ -20,7 +20,8 @@ kaem.runCommand "${pname}-${version}" {
};
} ''
mkdir -p ''${out}/bin
${mes}/bin/mes --no-auto-compile -e main ${mes}/bin/mescc.scm -- \
${mes.compiler}/bin/mes --no-auto-compile -e main ${mes.srcPost.bin}/bin/mescc.scm -- \
-L ${mes.libs}/lib \
-lc+tcc \
-o ''${out}/bin/ln \
${src}

View file

@ -6,6 +6,12 @@
, m2libc
, mescc-tools
}:
# Maintenance note:
# Build steps have been adapted from build-aux/bootstrap.sh.in
# as well as the live-bootstrap project
# https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/mes-0.24.2/mes-0.24.2.kaem
let
pname = "mes";
version = "0.24.2";
@ -28,26 +34,6 @@ let
# add symlink() to libc+tcc so we can use it in ln-boot
libc_tcc_SOURCES = sources.libc_tcc_SOURCES ++ [ "lib/linux/symlink.c" ];
compile = sources:
lib.concatMapStringsSep
"\n"
(f: ''CC -c ''${MES_PREFIX}/${f}'')
sources;
replaceExt = ext: source:
lib.replaceStrings
[ ".c" ]
[ ext ]
(builtins.baseNameOf source);
archive = out: sources:
"catm ${out} ${lib.concatMapStringsSep " " (replaceExt ".o") sources}";
sourceArchive = out: sources:
"catm ${out} ${lib.concatMapStringsSep " " (replaceExt ".s") sources}";
in
kaem.runCommand "${pname}-${version}" {
inherit pname version;
passthru = { inherit src nyacc; };
meta = with lib; {
description = "Scheme interpreter and C compiler for bootstrapping";
homepage = "https://www.gnu.org/software/mes";
@ -55,135 +41,199 @@ kaem.runCommand "${pname}-${version}" {
maintainers = with maintainers; [ emilytrau ];
platforms = [ "i686-linux" ];
};
}
# Maintenance note:
# Build steps have been adapted from build-aux/bootstrap.sh.in
# as well as the live-bootstrap project
# https://github.com/fosslinux/live-bootstrap/blob/1bc4296091c51f53a5598050c8956d16e945b0f5/sysa/mes-0.24.2/mes-0.24.2.kaem
''
# Unpack source
ungz --file ${src} --output mes.tar
mkdir ''${out} ''${out}/bin ''${out}/share
cd ''${out}/share
untar --non-strict --file ''${NIX_BUILD_TOP}/mes.tar # ignore symlinks
MES_PREFIX=''${out}/share/mes-${version}
LIBDIR=''${MES_PREFIX}/lib
srcPost = kaem.runCommand "${pname}-src-${version}" {
outputs = [ "out" "bin" ];
inherit meta;
} ''
# Unpack source
ungz --file ${src} --output mes.tar
mkdir ''${out}
cd ''${out}
untar --non-strict --file ''${NIX_BUILD_TOP}/mes.tar # ignore symlinks
cd ''${MES_PREFIX}
MES_PREFIX=''${out}/mes-${version}
cp ${config_h} include/mes/config.h
cd ''${MES_PREFIX}
mkdir include/arch
cp include/linux/x86/syscall.h include/arch/syscall.h
cp include/linux/x86/kernel-stat.h include/arch/kernel-stat.h
cp ${config_h} include/mes/config.h
# Remove pregenerated files
rm mes/module/mes/psyntax.pp mes/module/mes/psyntax.pp.header
mkdir include/arch
cp include/linux/x86/syscall.h include/arch/syscall.h
cp include/linux/x86/kernel-stat.h include/arch/kernel-stat.h
# These files are symlinked in the repo
cp mes/module/srfi/srfi-9-struct.mes mes/module/srfi/srfi-9.mes
cp mes/module/srfi/srfi-9/gnu-struct.mes mes/module/srfi/srfi-9/gnu.mes
# Remove pregenerated files
rm mes/module/mes/psyntax.pp mes/module/mes/psyntax.pp.header
# Fixes to support newer M2-Planet
catm x86_defs.M1 ${m2libc}/x86/x86_defs.M1 lib/m2/x86/x86_defs.M1
cp x86_defs.M1 lib/m2/x86/x86_defs.M1
rm x86_defs.M1
# These files are symlinked in the repo
cp mes/module/srfi/srfi-9-struct.mes mes/module/srfi/srfi-9.mes
cp mes/module/srfi/srfi-9/gnu-struct.mes mes/module/srfi/srfi-9/gnu.mes
# Remove environment impurities
__GUILE_LOAD_PATH="\"''${MES_PREFIX}/mes/module:''${MES_PREFIX}/module:${nyacc.guilePath}\""
boot0_scm=mes/module/mes/boot-0.scm
guile_mes=mes/module/mes/guile.mes
replace --file ''${boot0_scm} --output ''${boot0_scm} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH}
replace --file ''${guile_mes} --output ''${guile_mes} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH}
# Fixes to support newer M2-Planet
catm x86_defs.M1 ${m2libc}/x86/x86_defs.M1 lib/m2/x86/x86_defs.M1
cp x86_defs.M1 lib/m2/x86/x86_defs.M1
rm x86_defs.M1
module_mescc_scm=module/mescc/mescc.scm
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"M1\")" --replace-with "\"${mescc-tools}/bin/M1\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"HEX2\")" --replace-with "\"${mescc-tools}/bin/hex2\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"BLOOD_ELF\")" --replace-with "\"${mescc-tools}/bin/blood-elf\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"srcdest\")" --replace-with "\"''${MES_PREFIX}\""
# Remove environment impurities
__GUILE_LOAD_PATH="\"''${MES_PREFIX}/mes/module:''${MES_PREFIX}/module:${nyacc.guilePath}\""
boot0_scm=mes/module/mes/boot-0.scm
guile_mes=mes/module/mes/guile.mes
replace --file ''${boot0_scm} --output ''${boot0_scm} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH}
replace --file ''${guile_mes} --output ''${guile_mes} --match-on "(getenv \"GUILE_LOAD_PATH\")" --replace-with ''${__GUILE_LOAD_PATH}
mes_c=src/mes.c
replace --file ''${mes_c} --output ''${mes_c} --match-on "getenv (\"MES_PREFIX\")" --replace-with "\"''${MES_PREFIX}\""
replace --file ''${mes_c} --output ''${mes_c} --match-on "getenv (\"srcdest\")" --replace-with "\"''${MES_PREFIX}\""
module_mescc_scm=module/mescc/mescc.scm
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"M1\")" --replace-with "\"${mescc-tools}/bin/M1\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"HEX2\")" --replace-with "\"${mescc-tools}/bin/hex2\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"BLOOD_ELF\")" --replace-with "\"${mescc-tools}/bin/blood-elf\""
replace --file ''${module_mescc_scm} --output ''${module_mescc_scm} --match-on "(getenv \"srcdest\")" --replace-with "\"''${MES_PREFIX}\""
# Increase runtime resource limits
gc_c=src/gc.c
replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_ARENA\")" --replace-with "\"100000000\""
replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_MAX_ARENA\")" --replace-with "\"100000000\""
replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_STACK\")" --replace-with "\"6000000\""
mes_c=src/mes.c
replace --file ''${mes_c} --output ''${mes_c} --match-on "getenv (\"MES_PREFIX\")" --replace-with "\"''${MES_PREFIX}\""
replace --file ''${mes_c} --output ''${mes_c} --match-on "getenv (\"srcdest\")" --replace-with "\"''${MES_PREFIX}\""
# Create mescc.scm
mescc_in=scripts/mescc.scm.in
replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"MES_PREFIX\")" --replace-with "\"''${MES_PREFIX}\""
replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"includedir\")" --replace-with "\"''${MES_PREFIX}/include\""
replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"libdir\")" --replace-with "\"''${MES_PREFIX}/lib\""
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @prefix@ --replace-with ''${MES_PREFIX}
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @VERSION@ --replace-with ${version}
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @mes_cpu@ --replace-with x86
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @mes_kernel@ --replace-with linux
cp ''${mescc_in} ''${out}/bin/mescc.scm
# Increase runtime resource limits
gc_c=src/gc.c
replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_ARENA\")" --replace-with "\"100000000\""
replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_MAX_ARENA\")" --replace-with "\"100000000\""
replace --file ''${gc_c} --output ''${gc_c} --match-on "getenv (\"MES_STACK\")" --replace-with "\"6000000\""
# Build mes-m2
mes_cpu=x86
stage0_cpu=x86
kaem --verbose --strict --file kaem.run
cp bin/mes-m2 ''${out}/bin/mes-m2
chmod 555 ''${out}/bin/mes-m2
# Create mescc.scm
mescc_in=scripts/mescc.scm.in
replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"MES_PREFIX\")" --replace-with "\"''${MES_PREFIX}\""
replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"includedir\")" --replace-with "\"''${MES_PREFIX}/include\""
replace --file ''${mescc_in} --output ''${mescc_in} --match-on "(getenv \"libdir\")" --replace-with "\"''${MES_PREFIX}/lib\""
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @prefix@ --replace-with ''${MES_PREFIX}
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @VERSION@ --replace-with ${version}
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @mes_cpu@ --replace-with x86
replace --file ''${mescc_in} --output ''${mescc_in} --match-on @mes_kernel@ --replace-with linux
mkdir -p ''${bin}/bin
cp ''${mescc_in} ''${bin}/bin/mescc.scm
# Build mes-m2
mes_cpu=x86
stage0_cpu=x86
kaem --verbose --strict --file kaem.run
cp bin/mes-m2 ''${bin}/bin/mes-m2
chmod 555 ''${bin}/bin/mes-m2
'';
srcPrefix = "${srcPost.out}/mes-${version}";
cc = "${srcPost.bin}/bin/mes-m2";
ccArgs = [
"-e" "main"
"${srcPost.bin}/bin/mescc.scm"
"--"
"-D" "HAVE_CONFIG_H=1"
"-I" "${srcPrefix}/include"
"-I" "${srcPrefix}/include/linux/x86"
];
CC = toString ([ cc ] ++ ccArgs);
stripExt = source:
lib.replaceStrings
[ ".c" ]
[ "" ]
(builtins.baseNameOf source);
compile = source: kaem.runCommand (stripExt source) {} ''
mkdir ''${out}
cd ''${out}
${CC} -c ${srcPrefix}/${source}
'';
crt1 = compile "/lib/linux/x86-mes-mescc/crt1.c";
getRes = suffix: res: "${res}/${res.name}${suffix}";
archive = out: sources:
"catm ${out} ${lib.concatMapStringsSep " " (getRes ".o") sources}";
sourceArchive = out: sources:
"catm ${out} ${lib.concatMapStringsSep " " (getRes ".s") sources}";
mkLib = libname: sources: let
os = map compile sources;
in kaem.runCommand "${pname}-${libname}-${version}" {
inherit meta;
} ''
LIBDIR=''${out}/lib
mkdir -p ''${LIBDIR}
cd ''${LIBDIR}
${archive "${libname}.a" os}
${sourceArchive "${libname}.s" os}
'';
libc-mini = mkLib "libc-mini" libc_mini_SOURCES;
libmescc = mkLib "libmescc" libmescc_SOURCES;
libc = mkLib "libc" libc_SOURCES;
libc_tcc = mkLib "libc+tcc" libc_tcc_SOURCES;
# Recompile Mes and Mes C library using mes-m2 bootstrapped Mes
cd ''${NIX_BUILD_TOP}
alias CC="''${out}/bin/mes-m2 -e main ''${out}/bin/mescc.scm -- -D HAVE_CONFIG_H=1 -I ''${MES_PREFIX}/include -I ''${MES_PREFIX}/include/linux/x86"
mkdir -p ''${LIBDIR}/x86-mes
libs = kaem.runCommand "${pname}-m2-libs-${version}" {
inherit pname version;
# crt1.o
CC -c ''${MES_PREFIX}/lib/linux/x86-mes-mescc/crt1.c
cp crt1.o ''${LIBDIR}/x86-mes
cp crt1.s ''${LIBDIR}/x86-mes
passthru.tests.get-version = result: kaem.runCommand "${pname}-get-version-${version}" {} ''
${result}/bin/mes --version
mkdir ''${out}
'';
# libc-mini.a
${compile libc_mini_SOURCES}
${archive "libc-mini.a" libc_mini_SOURCES}
${sourceArchive "libc-mini.s" libc_mini_SOURCES}
cp libc-mini.a ''${LIBDIR}/x86-mes
cp libc-mini.s ''${LIBDIR}/x86-mes
inherit meta;
}
''
LIBDIR=''${out}/lib
mkdir -p ''${out} ''${LIBDIR}
# libmescc.a
${compile libmescc_SOURCES}
${archive "libmescc.a" libmescc_SOURCES}
${sourceArchive "libmescc.s" libmescc_SOURCES}
cp libmescc.a ''${LIBDIR}/x86-mes
cp libmescc.s ''${LIBDIR}/x86-mes
mkdir -p ''${LIBDIR}/x86-mes
# libc.a
${compile libc_SOURCES}
${archive "libc.a" libc_SOURCES}
${sourceArchive "libc.s" libc_SOURCES}
cp libc.a ''${LIBDIR}/x86-mes
cp libc.s ''${LIBDIR}/x86-mes
# crt1.o
cp ${crt1}/crt1.o ''${LIBDIR}/x86-mes
cp ${crt1}/crt1.s ''${LIBDIR}/x86-mes
# libc+tcc.a
# optimisation: don't recompile common libc sources
${compile (lib.subtractLists libc_SOURCES libc_tcc_SOURCES)}
${archive "libc+tcc.a" libc_tcc_SOURCES}
${sourceArchive "libc+tcc.s" libc_tcc_SOURCES}
cp libc+tcc.a ''${LIBDIR}/x86-mes
cp libc+tcc.s ''${LIBDIR}/x86-mes
# libc-mini.a
cp ${libc-mini}/lib/libc-mini.a ''${LIBDIR}/x86-mes
cp ${libc-mini}/lib/libc-mini.s ''${LIBDIR}/x86-mes
# libmescc.a
cp ${libmescc}/lib/libmescc.a ''${LIBDIR}/x86-mes
cp ${libmescc}/lib/libmescc.s ''${LIBDIR}/x86-mes
# libc.a
cp ${libc}/lib/libc.a ''${LIBDIR}/x86-mes
cp ${libc}/lib/libc.s ''${LIBDIR}/x86-mes
# libc+tcc.a
cp ${libc_tcc}/lib/libc+tcc.a ''${LIBDIR}/x86-mes
cp ${libc_tcc}/lib/libc+tcc.s ''${LIBDIR}/x86-mes
'';
# Build mes itself
${compile mes_SOURCES}
''${out}/bin/mes-m2 -e main ''${out}/bin/mescc.scm -- \
--base-address 0x08048000 \
-L ''${MES_PREFIX}/lib \
-L . \
-lc \
-lmescc \
-nostdlib \
-o ''${out}/bin/mes \
crt1.o \
${lib.concatMapStringsSep " " (replaceExt ".o") mes_SOURCES}
compiler = kaem.runCommand "${pname}-${version}" {
inherit pname version;
# Check
''${out}/bin/mes --version
''
passthru.tests.get-version = result: kaem.runCommand "${pname}-get-version-${version}" {} ''
${result}/bin/mes --version
mkdir ''${out}
'';
inherit meta;
}
''
mkdir -p ''${out}/bin
${srcPost.bin}/bin/mes-m2 -e main ${srcPost.bin}/bin/mescc.scm -- \
--base-address 0x08048000 \
-L ''${srcPrefix}/lib \
-L ${libs}/lib \
-lc \
-lmescc \
-nostdlib \
-o ''${out}/bin/mes \
${libs}/lib/x86-mes/crt1.o \
${lib.concatMapStringsSep " " (getRes ".o") (map compile mes_SOURCES)}
'';
in {
inherit srcPost srcPrefix nyacc;
inherit compiler libs;
}

View file

@ -6,13 +6,11 @@
}:
let
pname = "mes-libc";
inherit (mes) version;
inherit (mes.compiler) version;
sources = (import ./sources.nix).x86.linux.gcc;
inherit (sources) libtcc1_SOURCES libc_gnu_SOURCES;
prefix = "${mes}/share/mes-${version}";
# Concatenate all source files into a convenient bundle
# "gcc" variants of source files (eg. "lib/linux/x86-mes-gcc") can also be
# compiled by tinycc
@ -37,11 +35,10 @@ kaem.runCommand "${pname}-${version}" {
platforms = [ "i686-linux" ];
};
} ''
cd ${prefix}
cd ${mes.srcPrefix}
# mescc compiled libc.a
mkdir -p ''${out}/lib/x86-mes
cp lib/x86-mes/libc.a ''${out}/lib/x86-mes
# libc.c
catm ''${TMPDIR}/first.c ${lib.concatStringsSep " " firstLibc}
@ -59,5 +56,5 @@ kaem.runCommand "${pname}-${version}" {
cp lib/posix/getopt.c ''${out}/lib/libgetopt.c
# Install headers
ln -s ${prefix}/include ''${out}/include
ln -s ${mes.srcPrefix}/include ''${out}/include
''

View file

@ -12,7 +12,9 @@ lib.makeScope newScope (self: with self; {
kaem = callPackage ./kaem { };
kaem-minimal = callPackage ./kaem/minimal.nix { };
inherit (callPackage ./stage0-posix-x86.nix { }) blood-elf-0 hex2 kaem-unwrapped M1 M2;
stage0-posix-x86 = callPackage ./stage0-posix-x86.nix { };
inherit (self.stage0-posix-x86) blood-elf-0 hex2 kaem-unwrapped M1 M2;
mescc-tools = callPackage ./mescc-tools { };

View file

@ -15,7 +15,7 @@
, mes-libc
}:
let
inherit (callPackage ./common.nix { }) buildTinyccMes;
inherit (callPackage ./common.nix { }) buildTinyccMes recompileLibc;
version = "unstable-2023-04-20";
rev = "80114c4da6b17fbaabb399cc29f427e368309bc8";
@ -39,50 +39,54 @@ let
platforms = [ "i686-linux" ];
};
tinycc-boot-mes = kaem.runCommand "tinycc-boot-mes-${version}" {} ''
catm config.h
${mes}/bin/mes --no-auto-compile -e main ${mes}/bin/mescc.scm -- \
-S \
-o tcc.s \
-I . \
-D BOOTSTRAP=1 \
-I ${src} \
-D TCC_TARGET_I386=1 \
-D inline= \
-D CONFIG_TCCDIR=\"''${out}/lib\" \
-D CONFIG_SYSROOT=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"''${out}/lib\" \
-D CONFIG_TCC_ELFINTERP=\"/mes/loader\" \
-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}/bin/mes --no-auto-compile -e main ${mes}/bin/mescc.scm -- \
-l c+tcc \
-o ''${out}/bin/tcc \
tcc.s
pname = "tinycc-boot-mes";
''${out}/bin/tcc -version
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
'';
# Recompile libc: crt{1,n,i}, libtcc.a, libc.a, libgetopt.a
mkdir -p ''${out}/lib
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crt1.o ${mes-libc}/lib/crt1.c
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crtn.o ${mes-libc}/lib/crtn.c
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crti.o ${mes-libc}/lib/crti.c
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o libc.o ${mes-libc}/lib/libc.c
''${out}/bin/tcc -ar cr ''${out}/lib/libc.a libc.o
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o libtcc1.o ${mes-libc}/lib/libtcc1.c
''${out}/bin/tcc -ar cr ''${out}/lib/libtcc1.a libtcc1.o
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o libgetopt.o ${mes-libc}/lib/libgetopt.c
''${out}/bin/tcc -ar cr ''${out}/lib/libgetopt.a libgetopt.o
'';
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

View file

@ -3,67 +3,105 @@
, mes-libc
, ln-boot
}:
{
buildTinyccMes = {
pname,
version,
src,
prev,
buildOptions,
libtccBuildOptions,
meta
}:
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 " " libtccBuildOptions;
in
kaem.runCommand "${pname}-${version}" {
inherit pname version meta;
nativeBuildInputs = [ ln-boot ];
} ''
catm config.h
mkdir -p ''${out}/bin
${prev}/bin/tcc \
-g \
-v \
-static \
-o ''${out}/bin/tcc \
-D BOOTSTRAP=1 \
${options} \
-I . \
-I ${src} \
-D TCC_TARGET_I386=1 \
-D CONFIG_TCCDIR=\"''${out}/lib\" \
-D CONFIG_TCC_CRTPREFIX=\"''${out}/lib\" \
-D CONFIG_TCC_ELFINTERP=\"\" \
-D CONFIG_TCC_LIBPATHS=\"''${out}/lib\" \
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${mes-libc}/include:${src}/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 \
-L ${prev}/lib \
${src}/tcc.c
''${out}/bin/tcc -v
# Recompile libc: crt{1,n,i}, libtcc.a, libc.a, libgetopt.a
mkdir -p ''${out}/lib
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crt1.o ${mes-libc}/lib/crt1.c
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crtn.o ${mes-libc}/lib/crtn.c
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o ''${out}/lib/crti.o ${mes-libc}/lib/crti.c
''${out}/bin/tcc -c -D TCC_TARGET_I386=1 ${libtccOptions} -o libtcc1.o ${src}/lib/libtcc1.c
''${out}/bin/tcc -ar cr ''${out}/lib/libtcc1.a libtcc1.o
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o libc.o ${mes-libc}/lib/libc.c
''${out}/bin/tcc -ar cr ''${out}/lib/libc.a libc.o
''${out}/bin/tcc ${mes-libc.CFLAGS} -c -o libgetopt.o ${mes-libc}/lib/libgetopt.c
''${out}/bin/tcc -ar cr ''${out}/lib/libgetopt.a libgetopt.o
# Install headers
ln -s ${mes-libc}/include ''${out}/include
'';
libtccOptions = lib.strings.concatStringsSep " "
(["-c" "-D" "TCC_TARGET_I386=1" ] ++ libtccBuildOptions);
compiler = kaem.runCommand "${pname}-${version}" {
inherit pname version meta;
nativeBuildInputs = [ ln-boot ];
passthru.tests = rec {
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 \
-static \
-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

@ -37,7 +37,12 @@ let
tccdefs = kaem.runCommand "tccdefs-${version}" {} ''
mkdir ''${out}
${tinycc-bootstrappable}/bin/tcc -static -DC2STR -o c2str ${src}/conftest.c
${tinycc-bootstrappable.compiler}/bin/tcc \
-B ${tinycc-bootstrappable.libs}/lib \
-static \
-DC2STR \
-o c2str \
${src}/conftest.c
./c2str ${src}/include/tccdefs.h ''${out}/tccdefs_.h
'';

View file

@ -18,14 +18,18 @@ rec {
passthru = attrs.passthru or {};
validity = checkMeta.assertValidity { inherit meta attrs; };
meta = checkMeta.commonMeta { inherit validity attrs; };
baseDrv = derivation ({
inherit (buildPlatform) system;
inherit (meta) name;
} // (builtins.removeAttrs attrs [ "meta" "passthru" ]));
passthru' = passthru // lib.optionalAttrs (passthru ? tests) {
tests = lib.mapAttrs (_: f: f baseDrv) passthru.tests;
};
in
lib.extendDerivation
validity.handled
({ inherit meta passthru; } // passthru)
(derivation ({
inherit (buildPlatform) system;
inherit (meta) name;
} // (builtins.removeAttrs attrs [ "meta" "passthru" ])));
({ inherit meta; passthru = passthru'; } // passthru')
baseDrv;
writeTextFile =
{ name # the name of the derivation
@ -36,7 +40,7 @@ rec {
, preferLocalBuild ? true
}:
derivationWithMeta {
inherit name text executable allowSubstitutes preferLocalBuild;
inherit name text allowSubstitutes preferLocalBuild;
passAsFile = [ "text" ];
builder = "${kaem}/bin/kaem";
@ -44,20 +48,18 @@ rec {
"--verbose"
"--strict"
"--file"
(builtins.toFile "write-text-file.kaem" ''
(builtins.toFile "write-text-file.kaem" (''
target=''${out}''${destination}
if match x''${mkdirDestination} x1; then
mkdir -p ''${out}''${destinationDir}
fi
'' + lib.optionalString (builtins.dirOf destination == ".") ''
mkdir -p ''${out}''${destinationDir}
'' + ''
cp ''${textPath} ''${target}
if match x''${executable} x1; then
chmod 555 ''${target}
fi
'')
'' + lib.optionalString executable ''
chmod 555 ''${target}
''))
];
PATH = lib.makeBinPath [ mescc-tools-extra ];
mkdirDestination = if builtins.dirOf destination == "." then "0" else "1";
destinationDir = builtins.dirOf destination;
inherit destination;
};