diff options
Diffstat (limited to 'pkgs/os-specific/linux/minimal-bootstrap')
13 files changed, 421 insertions, 312 deletions
diff --git a/pkgs/os-specific/linux/minimal-bootstrap/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/default.nix index 97c9a26b53f..5907cdb4cda 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/default.nix @@ -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 runCommand; + 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} + ''; }) diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnumake/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/default.nix index 0db52e28742..7a467ce4487 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/gnumake/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnumake/default.nix @@ -1,6 +1,6 @@ { lib -, runCommand , fetchurl +, kaem , tinycc , gnupatch }: @@ -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() @@ -145,10 +145,10 @@ let objects = map (x: lib.replaceStrings [".c"] [".o"] (builtins.baseNameOf x)) sources; in -runCommand "${pname}-${version}" { +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 @@ 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 diff --git a/pkgs/os-specific/linux/minimal-bootstrap/gnupatch/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/gnupatch/default.nix index 2a44f3805d4..6cb9d23cafa 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/gnupatch/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/gnupatch/default.nix @@ -1,6 +1,6 @@ { lib -, runCommand , fetchurl +, kaem , tinycc }: let @@ -67,10 +67,10 @@ let objects = map (x: lib.replaceStrings [".c"] [".o"] (builtins.baseNameOf x)) sources; in -runCommand "${pname}-${version}" { +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 @@ 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 diff --git a/pkgs/os-specific/linux/minimal-bootstrap/ln-boot/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/ln-boot/default.nix index 23c634421cb..46cd06e53b2 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/ln-boot/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/ln-boot/default.nix @@ -1,5 +1,5 @@ { lib -, runCommand +, kaem , mes }: let @@ -8,7 +8,7 @@ let src = ./ln.c; in -runCommand "${pname}-${version}" { +kaem.runCommand "${pname}-${version}" { inherit pname version; meta = with lib; { @@ -20,7 +20,8 @@ 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} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/mes/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/mes/default.nix index abf3955eb2d..9d28de47189 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/mes/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/mes/default.nix @@ -1,11 +1,17 @@ { lib -, runCommand , fetchurl , writeText , callPackage +, kaem , 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 -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 @@ 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 - - cd ''${MES_PREFIX} - - cp ${config_h} include/mes/config.h - - 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 - - # Remove pregenerated files - rm mes/module/mes/psyntax.pp mes/module/mes/psyntax.pp.header - - # 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 - - # 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 - - # 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} - - 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}\"" - - 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}\"" - - # 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\"" - - # 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 - - # 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 + 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 + + MES_PREFIX=''${out}/mes-${version} + + cd ''${MES_PREFIX} + + cp ${config_h} include/mes/config.h + + 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 + + # Remove pregenerated files + rm mes/module/mes/psyntax.pp mes/module/mes/psyntax.pp.header + + # 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 + + # 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 + + # 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} + + 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}\"" + + 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}\"" + + # 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\"" + + # 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 - - # 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 - - # 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 - - # 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 - - # 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 - - # 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 + 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 + cp ${crt1}/crt1.o ''${LIBDIR}/x86-mes + cp ${crt1}/crt1.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} - - # Check - ''${out}/bin/mes --version -'' + 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 ''${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; +} diff --git a/pkgs/os-specific/linux/minimal-bootstrap/mes/libc.nix b/pkgs/os-specific/linux/minimal-bootstrap/mes/libc.nix index 06cd95de87e..b21bd744e5f 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/mes/libc.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/mes/libc.nix @@ -1,18 +1,16 @@ { lib -, runCommand +, kaem , ln-boot , mes , mes-libc }: 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 @@ -21,7 +19,8 @@ let # the operation in two firstLibc = lib.take 100 libc_gnu_SOURCES; lastLibc = lib.drop 100 libc_gnu_SOURCES; -in runCommand "${pname}-${version}" { +in +kaem.runCommand "${pname}-${version}" { inherit pname version; nativeBuildInputs = [ ln-boot ]; @@ -36,11 +35,10 @@ in 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} @@ -58,5 +56,5 @@ in 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 '' diff --git a/pkgs/os-specific/linux/minimal-bootstrap/mes/nyacc.nix b/pkgs/os-specific/linux/minimal-bootstrap/mes/nyacc.nix index 7a196fd5ef9..220b9b66730 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/mes/nyacc.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/mes/nyacc.nix @@ -1,6 +1,6 @@ { lib -, runCommand , fetchurl +, kaem , nyacc }: let @@ -15,7 +15,7 @@ let sha256 = "065ksalfllbdrzl12dz9d9dcxrv97wqxblslngsc6kajvnvlyvpk"; }; in -runCommand "${pname}-${version}" { +kaem.runCommand "${pname}-${version}" { inherit pname version; passthru.guilePath = "${nyacc}/share/${pname}-${version}/module"; diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/default.nix index 650644f6ef0..2b41261add3 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/default.nix @@ -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 { }; diff --git a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/default.nix index 2af660ad7a4..969dd35845e 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/default.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/stage0-posix/kaem/default.nix @@ -1,6 +1,9 @@ { lib , derivationWithMeta +, writeText +, kaem , kaem-unwrapped +, mescc-tools , mescc-tools-extra , version }: @@ -23,6 +26,21 @@ derivationWithMeta { ]; PATH = lib.makeBinPath [ mescc-tools-extra ]; + passthru.runCommand = name: env: buildCommand: + derivationWithMeta ({ + inherit name; + + builder = "${kaem}/bin/kaem"; + args = [ + "--verbose" + "--strict" + "--file" + (writeText "${name}-builder" buildCommand) + ]; + + PATH = lib.makeBinPath ((env.nativeBuildInputs or []) ++ [ kaem mescc-tools mescc-tools-extra ]); + } // (builtins.removeAttrs env [ "nativeBuildInputs" ])); + meta = with lib; { description = "Minimal build tool for running scripts on systems that lack any shell"; homepage = "https://github.com/oriansj/mescc-tools"; diff --git a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/bootstrappable.nix b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/bootstrappable.nix index bb0e058906c..1f30b63cbd0 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/bootstrappable.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/bootstrappable.nix @@ -8,14 +8,14 @@ # SPDX-License-Identifier: GPL-3.0-or-later { lib -, runCommand , callPackage , fetchurl +, kaem , mes , mes-libc }: let - inherit (callPackage ./common.nix { }) buildTinyccMes; + inherit (callPackage ./common.nix { }) buildTinyccMes recompileLibc; version = "unstable-2023-04-20"; rev = "80114c4da6b17fbaabb399cc29f427e368309bc8"; @@ -24,7 +24,7 @@ let url = "https://gitlab.com/janneke/tinycc/-/archive/${rev}/tinycc-${rev}.tar.gz"; sha256 = "1a0cw9a62qc76qqn5sjmp3xrbbvsz2dxrw21lrnx9q0s74mwaxbq"; }; - src = (runCommand "tinycc-bootstrappable-${version}-source" {} '' + src = (kaem.runCommand "tinycc-bootstrappable-${version}-source" {} '' ungz --file ${tarball} --output tinycc.tar mkdir -p ''${out} cd ''${out} @@ -39,50 +39,54 @@ let platforms = [ "i686-linux" ]; }; - tinycc-boot-mes = 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 diff --git a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/common.nix b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/common.nix index 84f4bcc0ed5..d05ac35a6d9 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/common.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/common.nix @@ -1,69 +1,107 @@ { lib -, runCommand +, kaem , mes-libc , ln-boot }: -{ - buildTinyccMes = { - pname, - version, - src, - prev, - buildOptions, - libtccBuildOptions, - meta - }: - let - options = lib.strings.concatStringsSep " " buildOptions; - libtccOptions = lib.strings.concatStringsSep " " libtccBuildOptions; - in - 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 +rec { - # Recompile libc: crt{1,n,i}, libtcc.a, libc.a, libgetopt.a + # 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 - ''${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 + ${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 + ''; - # Install headers - ln -s ${mes-libc}/include ''${out}/include + 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; + 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; }; } diff --git a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/mes.nix b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/mes.nix index 81674893ead..229d794cf35 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/tinycc/mes.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/tinycc/mes.nix @@ -5,9 +5,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later { lib -, runCommand , fetchurl , callPackage +, kaem , tinycc-bootstrappable }: let @@ -20,7 +20,7 @@ let url = "https://repo.or.cz/tinycc.git/snapshot/${rev}.tar.gz"; sha256 = "11idrvbwfgj1d03crv994mpbbbyg63j1k64lw1gjy7mkiifw2xap"; }; - src = (runCommand "tinycc-${version}-source" {} '' + src = (kaem.runCommand "tinycc-${version}-source" {} '' ungz --file ${tarball} --output tinycc.tar mkdir -p ''${out} cd ''${out} @@ -35,9 +35,14 @@ let platforms = [ "i686-linux" ]; }; - tccdefs = runCommand "tccdefs-${version}" {} '' + 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 ''; diff --git a/pkgs/os-specific/linux/minimal-bootstrap/utils.nix b/pkgs/os-specific/linux/minimal-bootstrap/utils.nix index 1cc56654d7b..e710c34aa6a 100644 --- a/pkgs/os-specific/linux/minimal-bootstrap/utils.nix +++ b/pkgs/os-specific/linux/minimal-bootstrap/utils.nix @@ -2,7 +2,6 @@ , buildPlatform , callPackage , kaem -, mescc-tools , mescc-tools-extra }: @@ -19,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 @@ -37,7 +40,7 @@ rec { , preferLocalBuild ? true }: derivationWithMeta { - inherit name text executable allowSubstitutes preferLocalBuild; + inherit name text allowSubstitutes preferLocalBuild; passAsFile = [ "text" ]; builder = "${kaem}/bin/kaem"; @@ -45,39 +48,22 @@ 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; }; writeText = name: text: writeTextFile {inherit name text;}; - runCommand = name: env: buildCommand: - derivationWithMeta ({ - inherit name; - - builder = "${kaem}/bin/kaem"; - args = [ - "--verbose" - "--strict" - "--file" - (writeText "${name}-builder" buildCommand) - ]; - - PATH = lib.makeBinPath ((env.nativeBuildInputs or []) ++ [ kaem mescc-tools mescc-tools-extra ]); - } // (builtins.removeAttrs env [ "nativeBuildInputs" ])); - } |