minimal-bootstrap.tcc: Dedup, separate compiler from libs
This commit is contained in:
parent
207bab5062
commit
0c7631d319
|
@ -29,4 +29,8 @@ lib.makeScope
|
|||
|
||||
inherit (callPackage ./utils.nix { }) fetchurl derivationWithMeta writeTextFile writeText;
|
||||
|
||||
test = kaem.runCommand "minimal-bootstrap-test" {} ''
|
||||
echo ${tinycc-mes.compiler.tests.chain}
|
||||
mkdir ''${out}
|
||||
'';
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,53 @@ 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}/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=\"\" \
|
||||
-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}/bin/mes --no-auto-compile -e main ${mes}/bin/mescc.scm -- \
|
||||
-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
|
||||
|
|
|
@ -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; };
|
||||
}
|
||||
|
|
|
@ -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
|
||||
'';
|
||||
|
||||
|
|
Loading…
Reference in a new issue