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,20 +41,18 @@ 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
''
srcPost = kaem.runCommand "${pname}-src-${version}" {
outputs = [ "out" "bin" ];
inherit meta;
} ''
# Unpack source
ungz --file ${src} --output mes.tar
mkdir ''${out} ''${out}/bin ''${out}/share
cd ''${out}/share
mkdir ''${out}
cd ''${out}
untar --non-strict --file ''${NIX_BUILD_TOP}/mes.tar # ignore symlinks
MES_PREFIX=''${out}/share/mes-${version}
LIBDIR=''${MES_PREFIX}/lib
MES_PREFIX=''${out}/mes-${version}
cd ''${MES_PREFIX}
@ -122,68 +106,134 @@ kaem.runCommand "${pname}-${version}" {
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
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 ''${out}/bin/mes-m2
chmod 555 ''${out}/bin/mes-m2
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"
libs = kaem.runCommand "${pname}-m2-libs-${version}" {
inherit pname version;
passthru.tests.get-version = result: kaem.runCommand "${pname}-get-version-${version}" {} ''
${result}/bin/mes --version
mkdir ''${out}
'';
inherit meta;
}
''
LIBDIR=''${out}/lib
mkdir -p ''${out} ''${LIBDIR}
mkdir -p ''${LIBDIR}/x86-mes
# 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
cp ${crt1}/crt1.o ''${LIBDIR}/x86-mes
cp ${crt1}/crt1.s ''${LIBDIR}/x86-mes
# 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
cp ${libc-mini}/lib/libc-mini.a ''${LIBDIR}/x86-mes
cp ${libc-mini}/lib/libc-mini.s ''${LIBDIR}/x86-mes
# 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
cp ${libmescc}/lib/libmescc.a ''${LIBDIR}/x86-mes
cp ${libmescc}/lib/libmescc.s ''${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
cp ${libc}/lib/libc.a ''${LIBDIR}/x86-mes
cp ${libc}/lib/libc.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
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 -- \
compiler = kaem.runCommand "${pname}-${version}" {
inherit pname 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 ''${MES_PREFIX}/lib \
-L . \
-L ''${srcPrefix}/lib \
-L ${libs}/lib \
-lc \
-lmescc \
-nostdlib \
-o ''${out}/bin/mes \
crt1.o \
${lib.concatMapStringsSep " " (replaceExt ".o") mes_SOURCES}
# Check
''${out}/bin/mes --version
''
${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,9 +39,17 @@ let
platforms = [ "i686-linux" ];
};
tinycc-boot-mes = kaem.runCommand "tinycc-boot-mes-${version}" {} ''
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}/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 -- \
-S \
-o tcc.s \
-I . \
@ -49,10 +57,11 @@ let
-I ${src} \
-D TCC_TARGET_I386=1 \
-D inline= \
-D CONFIG_TCCDIR=\"''${out}/lib\" \
-D CONFIG_TCCDIR=\"\" \
-D CONFIG_SYSROOT=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"''${out}/lib\" \
-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 \
@ -64,26 +73,21 @@ let
-D ONE_SOURCE=1 \
${src}/tcc.c
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 \
-l c+tcc \
-o ''${out}/bin/tcc \
tcc.s
''${out}/bin/tcc -version
# 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,27 +3,77 @@
, 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}" {
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}/bin/tcc \
${prev.compiler}/bin/tcc \
-B ${prev.libs}/lib \
-g \
-v \
-static \
@ -33,11 +83,12 @@
-I . \
-I ${src} \
-D TCC_TARGET_I386=1 \
-D CONFIG_TCCDIR=\"''${out}/lib\" \
-D CONFIG_TCC_CRTPREFIX=\"''${out}/lib\" \
-D CONFIG_TCCDIR=\"\" \
-D CONFIG_SYSROOT=\"\" \
-D CONFIG_TCC_CRTPREFIX=\"{B}\" \
-D CONFIG_TCC_ELFINTERP=\"\" \
-D CONFIG_TCC_LIBPATHS=\"''${out}/lib\" \
-D CONFIG_TCC_SYSINCLUDEPATHS=\"${mes-libc}/include:${src}/include\" \
-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 \
@ -46,24 +97,11 @@
-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
'';
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
'' + lib.optionalString (builtins.dirOf destination == ".") ''
mkdir -p ''${out}''${destinationDir}
fi
'' + ''
cp ''${textPath} ''${target}
if match x''${executable} x1; then
'' + lib.optionalString executable ''
chmod 555 ''${target}
fi
'')
''))
];
PATH = lib.makeBinPath [ mescc-tools-extra ];
mkdirDestination = if builtins.dirOf destination == "." then "0" else "1";
destinationDir = builtins.dirOf destination;
inherit destination;
};