unvendor
This commit is contained in:
Dawid Sobczak 2025-04-18 12:41:04 +01:00
parent 9a4b261179
commit 404aa8ebbb
139 changed files with 8091 additions and 1178 deletions

View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -uex
cp tcc-seed stage/store/0-tcc-seed

933
06/recipes/1-stage1.c Normal file
View file

@ -0,0 +1,933 @@
// SPDX-FileCopyrightText: 2021 Alexander Sosedkin <monk@unboiled.info>
// SPDX-License-Identifier: MIT
// syscalls (x86_64) ///////////////////////////////////////////////////////////
#ifndef INSIDE_NIX
#include "1-stage1/syscall.h"
#define TCC_SEED "/store/0-tcc-seed"
#define PROTOSRC "/protosrc"
#define RECIPES_STAGE1 "/recipes/1-stage1"
#define TMP_STAGE1 "/tmp/1-stage1"
#define STORE_PROTOBUSYBOX "/store/1-stage1/protobusybox"
#define STORE_PROTOMUSL "/store/1-stage1/protomusl"
#define STORE_TINYCC "/store/1-stage1/tinycc"
#define EXTRA_HELLO_ARGS
#else
#include "syscall.h"
#define EXTRA_HELLO_ARGS \
"-DRECIPES_STAGE1=\"" RECIPES_STAGE1"\"",
#endif
#define SYS_write 1
#define SYS_open 2
#define SYS_fork 57
#define SYS_execve 59
#define SYS_exit 60
#define SYS_wait4 61
#define SYS_getdents 78
#define SYS_mkdir 83
long write(int fd, const void* buf, long cnt) {
return __syscall3(SYS_write, fd, (long) buf, cnt);
}
int execve(const char* fname,
const char* const argv[], const char* const envp[]) {
return __syscall3(SYS_execve, (long) fname, (long) argv, (long) envp);
}
void exit(int code) { __syscall1(SYS_exit, code); };
int fork() { return __syscall0(SYS_fork); }
int wait4(int pid, int* status, int options, void* rusage) {
return __syscall4(
SYS_wait4,
pid, (long) status, options, (long) rusage
);
}
int mkdir(const char *pathname, unsigned mode) {
return __syscall2(SYS_mkdir, (long) pathname, mode);
}
int open(const char *pathname, int flags, int mode) {
return __syscall3(SYS_open, (long) pathname, flags, mode);
}
struct linux_dirent {
long d_ino;
long d_off;
unsigned short d_reclen;
char d_name[];
};
int getdents(unsigned int fd, struct linux_dirent *dirp,
unsigned int count) {
return __syscall3(SYS_getdents, fd, (long) dirp, count);
}
// random defines //////////////////////////////////////////////////////////////
#define NULL ((void*) 0)
#define STDOUT 1
#define STDERR 2
#define O_RDONLY 0
#define O_DIRECTORY 0200000
#define DT_REG 8
// basic QoL ///////////////////////////////////////////////////////////////////
unsigned strlen(const char* s) {
unsigned l;
for (l = 0; s[l]; l++);
return l;
}
int write_(int fd, const char* msg) {
return write(fd, msg, strlen(msg));
}
#define __quote(x) #x
#define _quote(x) __quote(x)
// real assert calls abort() -> 128 + SIGABRT = 134
#define assert(v) \
while (!(v)) { \
write_(STDERR, "Assertion "); \
write_(STDERR, _quote(v)); write_(STDERR, " failed at "); \
write_(STDERR, __FILE__); write_(STDERR, ":"); \
write_(STDERR, __func__); write_(STDERR, ":"); \
write_(STDERR, _quote(__LINE__)); write_(STDERR, "!\n"); \
exit(134); \
}
void err(const char* msg) { assert(write_(STDERR, msg) == strlen(msg)); }
void log_begin_line(const char* msg) {
assert(write_(STDOUT, "### 1-stage1.c: ") == 16);
assert(write_(STDOUT, msg) == strlen(msg));
}
void log_continue_line(const char* msg) {
assert(write_(STDOUT, msg) == strlen(msg));
}
void log_end_line() { assert(write_(STDOUT, "\n") == 1); }
void log(const char* msg) { log_begin_line(msg); log_end_line(); };
// more library function substitutes ///////////////////////////////////////////
void memset(char* ptr, int with, long len) {
long i;
for (i = 0; i < len; i++)
ptr[i] = with;
}
char* strcpy(char* dest, const char* src) {
while (*src)
*dest++ = *src++;
*dest = 0;
return dest;
}
int strcmp(const char* a, const char* b) {
for (; *a && *b; a++, b++)
if (*a != *b)
return (*a < *b) ? -1 : 1;
return !a && !b;
}
// my convenience functions: mkdir'ing /////////////////////////////////////////
void mkreqdirs(const char* path) {
char b[128], *p;
strcpy(b, path);
for (p = b + 1; *p; p++)
if (*p == '/') { *p = '\0'; mkdir(b, 0777); *p = '/'; }
}
void mkreqdirs_at(const char* at, const char* subpath) {
char b[128], *p;
p = strcpy(b, at);
p = strcpy(strcpy(strcpy(p, "/"), subpath), "/");
mkreqdirs(b);
}
#define mkdirs_at(at, args...) \
do { \
const char* const* p; \
for (p = (char*[]) { "/", ## args, NULL }; *p; p++) \
mkreqdirs_at(at, *p); \
} while (0)
// my convenience functions: fork + exec ///////////////////////////////////////
int run_(const char* cmd, const char* const args[], const char* const env[]) {
int pid, status, termsig;
if (pid = fork()) {
assert(wait4(pid, &status, 0, NULL) == pid);
termsig = status & 0x7f; // WTERMSIG
if (!termsig) {
return (status & 0xff00) >> 8; // WEXITSTATUS
} else {
err("child has been killed");
exit(termsig);
}
} else {
exit(execve(cmd, args, env));
}
return 0; // unreacheable
}
#define run(expected_retcode, first_arg, args...) \
do { \
const char const* __env[] = {NULL}; \
const char const* __args[] = {(first_arg), ##args, NULL}; \
int __i; \
log_begin_line("run() running: "); \
for(__i = 0; __args[__i]; __i++) { \
log_continue_line(__args[__i]); \
log_continue_line(" "); \
} \
log_end_line(); \
assert(run_(first_arg, __args, __env) == (expected_retcode)); \
} while (0)
#define run0(first_arg, args...) run(0, (first_arg), ## args)
// my convenience functions: dynamic args accumulation / command execution /////
struct args_accumulator {
char* pointers[4096];
char storage[262144];
char** ptr_curr;
char* char_curr;
};
void _aa_init(struct args_accumulator* aa) {
aa->char_curr = aa->storage;
aa->ptr_curr = aa->pointers;
*aa->ptr_curr = NULL;
}
void aa_append(struct args_accumulator* aa, const char* new_arg) {
*aa->ptr_curr = aa->char_curr;
*++aa->ptr_curr = NULL;
aa->char_curr = strcpy(aa->char_curr, new_arg);
aa->char_curr++;
}
void _aa_extend_from_arr(struct args_accumulator* aa, const char* const* p) {
for (; *p; p++)
aa_append(aa, *p);
}
void aa_extend_from(struct args_accumulator* aa, const void* from) {
// Cheat a little with void* to accept
// both struct args_accumulator* and null-terminated string arrays.
// Qualifiers could be stricter, but then declaring get cumbersome.
_aa_extend_from_arr(aa, (const char* const*) from);
}
#define aa_extend(aa_ptr, args...) \
_aa_extend_from_arr(aa_ptr, (const char*[]) { NULL, ## args, NULL } + 1)
#define aa_init(aa_ptr, args...) \
do { _aa_init(aa_ptr); aa_extend(aa_ptr, ## args); } while (0)
void aa_sort(struct args_accumulator* aa) {
int changes;
char **p, **n, *t;
if (!aa->pointers[0])
return;
if (!aa->pointers[1])
return;
do {
changes = 0;
for (p = aa->pointers, n = p + 1; *n; p++, n++) {
if (strcmp(*p, *n) > 0) {
t = *p; *p = *n; *n = t;
changes = 1;
}
}
} while (changes);
}
int aa_run(const struct args_accumulator* aa) {
int i;
log_begin_line("aa_run() running: ");
for (i = 0; aa->pointers[i]; i++) {
log_continue_line(aa->pointers[i]);
log_continue_line(" ");
}
log_end_line(STDOUT, "\n");
return run_(aa->pointers[0], aa->pointers, (char*[]) { NULL });
}
#define aa_run0(aa_ptr) do { assert(aa_run(aa_ptr) == 0); } while (0)
// my convenience functions: compiling whole directories worth of files ////////
_Bool is_compileable(char* fname) {
int i = 0;
while (fname[i])
i++;
if (i > 2)
if (fname[i - 2] == '.')
if (fname[i - 1] == 'c' || fname[i-1] == 's')
return 1;
return 0;
}
void aa_extend_from_dir(struct args_accumulator* aa_out,
unsigned short keep_components, const char* dir_path) {
struct args_accumulator aa;
char d_buf[256];
char buf[256];
const char* prefix;
char* out_subpath;
struct linux_dirent* d;
int fd, r;
char d_type;
aa_init(&aa);
prefix = dir_path + strlen(dir_path);
while (keep_components) {
while (*prefix != '/')
prefix--;
keep_components--;
prefix += keep_components ? -1 : 1;
}
fd = open(dir_path, O_RDONLY | O_DIRECTORY, 0);
assert(fd != -1);
while (1) {
d = (struct linux_dirent*) d_buf;
r = getdents(fd, d, 256);
assert(r != -1);
if (!r)
break;
while ((char*) d - d_buf < r) {
d_type = *((char*) d + d->d_reclen - 1);
if ((d_type == DT_REG || !d_type)
&& is_compileable(d->d_name)) {
out_subpath = strcpy(buf, prefix);
out_subpath = strcpy(out_subpath, "/");
out_subpath = strcpy(out_subpath, d->d_name);
aa_append(&aa, buf);
}
d = (struct linux_dirent*) ((char*) d + d->d_reclen);
}
}
aa_sort(&aa); // iteration order isn't guaranteed, make stable
aa_extend_from(aa_out, &aa);
}
void mass_compile(const char* cc, const void* compile_args,
const char* in_dir_path, const void* fnames /* NULL=auto */,
const char* out_obj_dir_path, const char* out_lib_file_path) {
// qualifiers could've been stricter
// const void* could be struct args_accumulator*,
// NULL-terminated arrays or even just NULLs for fnames
struct args_accumulator aa, aa_link, aa_sources;
char in_file_path_buf[128], out_file_path_buf[128];
char* in_file_path;
char* out_file_path;
char** p;
aa_init(&aa_sources);
if (!fnames)
aa_extend_from_dir(&aa_sources, 0, in_dir_path);
else
aa_extend_from(&aa_sources, fnames);
mkreqdirs(out_lib_file_path);
aa_init(&aa_link, cc, "-ar", "rc", out_lib_file_path);
for (p = (char**) &aa_sources; *p; p++) {
in_file_path = strcpy(in_file_path_buf, in_dir_path);
in_file_path = strcpy(in_file_path, "/");
in_file_path = strcpy(in_file_path, *p);
out_file_path = strcpy(out_file_path_buf, out_obj_dir_path);
out_file_path = strcpy(out_file_path, "/");
out_file_path = strcpy(out_file_path, *p);
out_file_path = strcpy(out_file_path, ".o");
mkreqdirs(out_file_path_buf);
aa_init(&aa, cc);
aa_extend_from(&aa, compile_args);
aa_extend(&aa, "-c", in_file_path_buf, "-o", out_file_path_buf);
aa_run0(&aa);
aa_append(&aa_link, out_file_path_buf);
}
aa_run0(&aa_link);
}
// Kinda boring parts //////////////////////////////////////////////////////////
#define TCC_ARGS_NOSTD "-nostdlib", "-nostdinc", "-I", "/protosrc/tinycc/include"
void sanity_test() {
struct args_accumulator aa1, aa2;
log("sanity-testing run()...");
log("* testing run() -> retcode 0...");
run0(TCC_SEED, "--help");
log("* testing run() -> retcode 1...");
run(1, TCC_SEED, "-ar", "--help");
log("run() seems to work OK");
log("sanity-testing args accumulator...");
log("* testing aa_append, aa_extend, aa_sort and aa_run0...");
aa_init(&aa1);
aa_init(&aa2);
aa_append(&aa1, TCC_SEED);
aa_append(&aa2, "-ar");
aa_extend(&aa2, "help-must-precede-ar", "--help");
aa_sort(&aa2);
aa_extend_from(&aa1, &aa2);
assert(!strcmp(((char**) &aa1)[0], TCC_SEED));
assert(!strcmp(((char**) &aa1)[1], "--help"));
assert(!strcmp(((char**) &aa1)[2], "-ar"));
assert(!strcmp(((char**) &aa1)[3], "help-must-precede-ar"));
assert(NULL == ((char**) &aa1)[4]);
aa_run0(&aa1);
log("* testing aa_multi and aa_run for 1...");
aa_init(&aa1, TCC_SEED, "-ar", "--help");
assert(aa_run(&aa1) == 1);
}
// Interesting parts: libtcc1 //////////////////////////////////////////////////
void compile_libtcc1_1st_time_nostd(const char* cc) {
log("compiling our first libtcc1.a...");
mass_compile(cc, (char* []) { TCC_ARGS_NOSTD, "-DTCC_MUSL", NULL },
PROTOSRC"/tinycc/lib", (char* []) {
"libtcc1.c", "alloca.S",
"dsohandle.c", "stdatomic.c", "va_list.c",
0},
TMP_STAGE1"/tinycc/libtcc1",
STORE_TINYCC"/lib/libtcc1.a");
} // see also compile_libtcc1 far below
// Interesting parts: protomusl ////////////////////////////////////////////////
#define PROTOMUSL_EXTRA_CFLAGS \
"-std=c99", \
"-D_XOPEN_SOURCE=700"
#define PROTOMUSL_INTERNAL_INCLUDES \
"-I" PROTOSRC"/protomusl/src/include", \
"-I" PROTOSRC"/protomusl/arch/x86_64", \
"-I" PROTOSRC"/protomusl/host-generated/sed1", \
"-I" PROTOSRC"/protomusl/host-generated/sed2", \
"-I" PROTOSRC"/protomusl/arch/generic", \
"-I" PROTOSRC"/protomusl/src/internal", \
"-I" PROTOSRC"/protomusl/include"
#define PROTOMUSL_NOSTD_LDFLAGS_PRE \
"-static", \
STORE_PROTOMUSL"/lib/crt1.o", \
STORE_PROTOMUSL"/lib/crti.o"
#define PROTOMUSL_NOSTD_LDFLAGS_POST \
STORE_PROTOMUSL"/lib/libc.a", \
STORE_PROTOMUSL"/lib/crtn.o"
#define PROTOMUSL_INCLUDES \
"-I" PROTOSRC"/protomusl/include", \
"-I" PROTOSRC"/protomusl/arch/x86_64", \
"-I" PROTOSRC"/protomusl/arch/generic", \
"-I" PROTOSRC"/protomusl/host-generated/sed1", \
"-I" PROTOSRC"/protomusl/host-generated/sed2"
void compile_protomusl(const char* cc) {
struct args_accumulator aa;
aa_init(&aa);
log("compiling part of musl (protomusl)...");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/conf");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/ctype");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/dirent");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/env");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/errno");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/exit");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/fcntl");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/fenv");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/internal");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/ldso");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/legacy");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/linux");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/locale");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/malloc");
aa_extend_from_dir(&aa, 2, PROTOSRC"/protomusl/src/malloc/mallocng");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/math");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/misc");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/mman");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/multibyte");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/network");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/passwd");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/prng");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/process");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/regex");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/select");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/setjmp");
aa_extend_from_dir(&aa, 2, PROTOSRC"/protomusl/src/setjmp/x86_64");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/signal");
aa_extend_from_dir(&aa, 2, PROTOSRC"/protomusl/src/signal/x86_64");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/stat");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/stdio");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/stdlib");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/string");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/temp");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/termios");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/thread");
aa_extend_from_dir(&aa, 2, PROTOSRC"/protomusl/src/thread/x86_64");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/time");
aa_extend_from_dir(&aa, 1, PROTOSRC"/protomusl/src/unistd");
mass_compile(cc, (char*[]) {
TCC_ARGS_NOSTD,
PROTOMUSL_EXTRA_CFLAGS,
PROTOMUSL_INTERNAL_INCLUDES,
0},
PROTOSRC"/protomusl/src", &aa,
TMP_STAGE1"/protomusl",
STORE_PROTOMUSL"/lib/libc.a");
log("compiling crt bits of protomusl...");
run0(cc, TCC_ARGS_NOSTD, PROTOMUSL_INTERNAL_INCLUDES, "-DCRT",
"-c", PROTOSRC"/protomusl/crt/crt1.c",
"-o", STORE_PROTOMUSL"/lib/crt1.o");
run0(cc, TCC_ARGS_NOSTD, "-DCRT",
"-c", PROTOSRC"/protomusl/crt/crti.c",
"-o", STORE_PROTOMUSL"/lib/crti.o");
run0(cc, TCC_ARGS_NOSTD, "-DCRT",
"-c", PROTOSRC"/protomusl/crt/crtn.c",
"-o", STORE_PROTOMUSL"/lib/crtn.o");
}
void test_example_1st_time_nostd(const char* cc) {
log("linking an example (1st time)...");
run0(cc, TCC_ARGS_NOSTD, PROTOMUSL_INCLUDES,
PROTOMUSL_NOSTD_LDFLAGS_PRE,
RECIPES_STAGE1"/hello.c", EXTRA_HELLO_ARGS
PROTOMUSL_NOSTD_LDFLAGS_POST,
STORE_TINYCC"/lib/libtcc1.a",
"-o", TMP_STAGE1"/protomusl-hello");
log("executing an example...");
run(42, TMP_STAGE1"/protomusl-hello");
}
// Interesting parts: recompiling tcc //////////////////////////////////////////
void compile_libtcc1(const char* cc) {
log("recompiling libtcc1.a...");
mass_compile(cc, (char*[]) { "-DTCC_MUSL", PROTOMUSL_INCLUDES, 0},
PROTOSRC"/tinycc/lib", (char*[]) {
"libtcc1.c", "alloca.S",
"dsohandle.c", "stdatomic.c", "va_list.c",
// now we can compile more
"tcov.c", "alloca-bt.S",
// bcheck.c is excluded, as it references __FILE__
0},
TMP_STAGE1"/tinycc/libtcc1",
STORE_TINYCC"/lib/libtcc1.a");
}
#define TCC_CFLAGS \
"-I"PROTOSRC"/tinycc", \
"-I"PROTOSRC"/tinycc/include", \
"-I"TMP_STAGE1"/tinycc/gen", \
"-DTCC_VERSION=\"mob-af1abf1\"", \
"-DTCC_GITHASH=\"mob:af1abf1\"", \
"-DTCC_TARGET_X86_64", \
"-DTCC_MUSL", \
"-DONE_SOURCE=0", \
"-DCONFIG_TCCDIR=\""STORE_TINYCC"/lib\"", \
"-DCONFIG_TCC_SYSINCLUDEPATHS="\
"\""STORE_PROTOMUSL"/include\"", \
"-DCONFIG_TCC_LIBPATHS=\""STORE_PROTOMUSL"/lib\"", \
"-DCONFIG_TCC_CRTPREFIX=\""STORE_PROTOMUSL"/lib\"", \
"-DCONFIG_TCC_ELFINTERP=\"/sorry/not/yet\"", \
"-DCONFIG_TCC_PREDEFS=1"
void compile_tcc_1st_time_nostd(const char* cc) {
log("compiling tcc's conftest...");
mkdirs_at(TMP_STAGE1"/tinycc", "gen", "lib", "bin");
mkdirs_at(STORE_TINYCC"", "lib", "bin");
run0(cc, TCC_ARGS_NOSTD, PROTOMUSL_INCLUDES,
PROTOMUSL_NOSTD_LDFLAGS_PRE,
"-DC2STR", PROTOSRC"/tinycc/conftest.c",
PROTOMUSL_NOSTD_LDFLAGS_POST,
STORE_TINYCC"/lib/libtcc1.a",
"-o", TMP_STAGE1"/tinycc/conftest"
);
log("generating tccdefs_.h with conftest...");
run0(TMP_STAGE1"/tinycc/conftest",
PROTOSRC"/tinycc/include/tccdefs.h",
TMP_STAGE1"/tinycc/gen/tccdefs_.h");
log("compiling libtcc...");
mass_compile(cc, (char*[]) {
TCC_ARGS_NOSTD,
PROTOMUSL_INCLUDES,
TCC_CFLAGS,
0},
PROTOSRC"/tinycc", (char*[]) {
"libtcc.c", "tccpp.c", "tccgen.c", "tccelf.c",
"tccdbg.c", "tccasm.c", "tccrun.c",
"x86_64-gen.c", "x86_64-link.c", "i386-asm.c",
0},
TMP_STAGE1"/tinycc/libtcc",
STORE_TINYCC"/lib/libtcc.a");
run0(cc, TCC_ARGS_NOSTD, PROTOMUSL_INCLUDES, TCC_CFLAGS,
PROTOMUSL_NOSTD_LDFLAGS_PRE,
PROTOSRC"/tinycc/tcc.c",
STORE_TINYCC"/lib/libtcc.a",
PROTOMUSL_NOSTD_LDFLAGS_POST,
STORE_TINYCC"/lib/libtcc1.a",
"-o", STORE_TINYCC"/bin/tcc");
run0(STORE_TINYCC"/bin/tcc", "-print-search-dirs");
}
void compile_tcc(const char* cc) {
log("recompiling libtcc...");
mass_compile(cc, (char*[]) { PROTOMUSL_INCLUDES, TCC_CFLAGS, 0},
PROTOSRC"/tinycc", (char*[]) {
"libtcc.c", "tccpp.c", "tccgen.c", "tccelf.c",
"tccdbg.c", "tccasm.c", "tccrun.c",
"x86_64-gen.c", "x86_64-link.c", "i386-asm.c",
0},
TMP_STAGE1"/tinycc/libtcc",
STORE_TINYCC"/lib/libtcc.a");
run0(cc, PROTOMUSL_INCLUDES, TCC_CFLAGS, "-static",
PROTOSRC"/tinycc/tcc.c",
STORE_TINYCC"/lib/libtcc.a",
"-o", STORE_TINYCC"/bin/tcc");
}
void test_example_intermediate(const char* cc) {
log("linking an example (our tcc, includes not installed)...");
run0(cc, PROTOMUSL_INCLUDES, "-static",
RECIPES_STAGE1"/hello.c", EXTRA_HELLO_ARGS
"-o", TMP_STAGE1"/protomusl-hello");
log("executing an example...");
run(42, TMP_STAGE1"/protomusl-hello");
}
void test_example_final(const char* cc_wrapper) {
log("linking an example (wrapped tcc, includes installed)...");
run0(cc_wrapper, RECIPES_STAGE1"/hello.c", EXTRA_HELLO_ARGS
"-o", TMP_STAGE1"/protomusl-hello");
log("executing an example...");
run(42, TMP_STAGE1"/protomusl-hello");
}
// Interesting parts: hacky standalone busybox applets /////////////////////////
void compile_standalone_busybox_applets(const char* cc) {
log("compiling protolibbb...");
mass_compile(cc, (char*[]) {
PROTOMUSL_INCLUDES,
"-I"PROTOSRC"/protobusybox/include/",
"-I"PROTOSRC"/protobusybox/libbb/",
"-include", RECIPES_STAGE1"/protobusybox.h",
0},
PROTOSRC"/protobusybox/libbb", (char*[]) {
"ask_confirmation.c",
"auto_string.c",
"bb_cat.c",
"bb_getgroups.c",
"bb_pwd.c",
"bb_strtonum.c",
"compare_string_array.c",
"concat_path_file.c",
"concat_subpath_file.c",
"copy_file.c",
"copyfd.c",
"crc32.c",
"default_error_retval.c",
"dump.c",
"endofname.c",
"executable.c",
"fclose_nonstdin.c",
"fflush_stdout_and_exit.c",
"full_write.c",
"get_last_path_component.c",
"get_line_from_file.c",
"getopt32.c",
"inode_hash.c",
"isdirectory.c",
"isqrt.c",
"last_char_is.c",
"llist.c",
"make_directory.c",
"messages.c",
"mode_string.c",
"parse_mode.c",
"perror_msg.c",
"perror_nomsg_and_die.c",
"printable_string.c",
"process_escape_sequence.c",
"procps.c",
"ptr_to_globals.c",
"read.c",
"read_printf.c",
"recursive_action.c",
"remove_file.c",
"safe_poll.c",
"safe_strncpy.c",
"safe_write.c",
"signals.c",
"single_argv.c",
"skip_whitespace.c",
"sysconf.c",
"time.c",
"u_signal_names.c",
"verror_msg.c",
"vfork_daemon_rexec.c",
"wfopen.c",
"wfopen_input.c",
"xatonum.c",
"xfunc_die.c",
"xfuncs.c",
"xfuncs_printf.c",
"xgetcwd.c",
"xreadlink.c",
"xrealloc_vector.c",
"xregcomp.c",
0},
TMP_STAGE1"/protobusybox/libbb",
TMP_STAGE1"/protobusybox/libbb.a");
log("compiling standalone protobusybox applets...");
mkreqdirs(STORE_PROTOBUSYBOX"/bin/");
#define compile_applet(applet_name, files...) \
run0(cc, PROTOMUSL_INCLUDES, \
"-D__GNUC__=2", "-D__GNUC_MINOR__=7", \
"-static", \
"-I"PROTOSRC"/protobusybox/include", \
"-include", RECIPES_STAGE1"/protobusybox.h", \
"-DAPPLET_MAIN=" applet_name "_main", \
RECIPES_STAGE1"/protobusybox.c", \
## files, \
TMP_STAGE1"/protobusybox/libbb.a", \
"-o", STORE_PROTOBUSYBOX"/bin/" applet_name);
compile_applet("echo", PROTOSRC"/protobusybox/coreutils/echo.c")
run0(STORE_PROTOBUSYBOX"/bin/echo",
"Hello from protobusybox!");
compile_applet("ash",
PROTOSRC"/protobusybox/shell/shell_common.c",
PROTOSRC"/protobusybox/shell/ash_ptr_hack.c",
PROTOSRC"/protobusybox/shell/math.c",
PROTOSRC"/protobusybox/coreutils/printf.c",
PROTOSRC"/protobusybox/coreutils/test_ptr_hack.c",
PROTOSRC"/protobusybox/coreutils/test.c",
PROTOSRC"/protobusybox/shell/ash.c")
run(42, STORE_PROTOBUSYBOX"/bin/ash", "-c",
"printf 'Hello from ash!\n'; exit 42");
compile_applet("basename",
PROTOSRC"/protobusybox/coreutils/basename.c")
compile_applet("cat", PROTOSRC"/protobusybox/coreutils/cat.c")
compile_applet("chmod", PROTOSRC"/protobusybox/coreutils/chmod.c")
compile_applet("cp",
PROTOSRC"/protobusybox/coreutils/libcoreutils/cp_mv_stat.c",
PROTOSRC"/protobusybox/coreutils/cp.c");
compile_applet("cut", PROTOSRC"/protobusybox/coreutils/cut.c");
compile_applet("dirname", PROTOSRC"/protobusybox/coreutils/dirname.c")
compile_applet("env", PROTOSRC"/protobusybox/coreutils/env.c");
compile_applet("expr", PROTOSRC"/protobusybox/coreutils/expr.c");
compile_applet("head", PROTOSRC"/protobusybox/coreutils/head.c");
compile_applet("install", PROTOSRC"/protobusybox/coreutils/install.c");
compile_applet("ln", PROTOSRC"/protobusybox/coreutils/ln.c");
compile_applet("ls", PROTOSRC"/protobusybox/coreutils/ls.c");
compile_applet("mkdir", PROTOSRC"/protobusybox/coreutils/mkdir.c");
compile_applet("mktemp", PROTOSRC"/protobusybox/coreutils/mktemp.c");
compile_applet("mv",
PROTOSRC"/protobusybox/coreutils/libcoreutils/cp_mv_stat.c",
PROTOSRC"/protobusybox/coreutils/mv.c");
compile_applet("od", PROTOSRC"/protobusybox/coreutils/od.c");
compile_applet("pwd", PROTOSRC"/protobusybox/coreutils/pwd.c");
compile_applet("rm", PROTOSRC"/protobusybox/coreutils/rm.c");
compile_applet("rmdir", PROTOSRC"/protobusybox/coreutils/rmdir.c");
compile_applet("sleep", PROTOSRC"/protobusybox/coreutils/sleep.c");
compile_applet("sort", PROTOSRC"/protobusybox/coreutils/sort.c");
compile_applet("touch", PROTOSRC"/protobusybox/coreutils/touch.c");
compile_applet("tr", PROTOSRC"/protobusybox/coreutils/tr.c");
compile_applet("true", PROTOSRC"/protobusybox/coreutils/true.c");
compile_applet("uname", PROTOSRC"/protobusybox/coreutils/uname.c");
compile_applet("uniq", PROTOSRC"/protobusybox/coreutils/uniq.c");
compile_applet("wc", PROTOSRC"/protobusybox/coreutils/wc.c");
#define LIBARCHIVE PROTOSRC"/protobusybox/archival/libarchive"
compile_applet("tar",
LIBARCHIVE "/data_align.c",
LIBARCHIVE "/data_extract_all.c",
LIBARCHIVE "/data_extract_to_stdout.c",
LIBARCHIVE "/data_skip.c",
LIBARCHIVE "/decompress_bunzip2.c",
LIBARCHIVE "/decompress_gunzip.c",
LIBARCHIVE "/decompress_unxz.c",
LIBARCHIVE "/filter_accept_all.c",
LIBARCHIVE "/filter_accept_reject_list.c",
LIBARCHIVE "/find_list_entry.c",
LIBARCHIVE "/get_header_tar.c",
LIBARCHIVE "/header_list.c",
LIBARCHIVE "/header_skip.c",
LIBARCHIVE "/header_verbose_list.c",
LIBARCHIVE "/init_handle.c",
LIBARCHIVE "/open_transformer.c",
LIBARCHIVE "/seek_by_jump.c",
LIBARCHIVE "/seek_by_read.c",
LIBARCHIVE "/unsafe_prefix.c",
LIBARCHIVE "/unsafe_symlink_target.c",
PROTOSRC"/protobusybox/archival/chksum_and_xwrite_tar_header.c",
PROTOSRC"/protobusybox/archival/tar.c");
compile_applet("bzip2", PROTOSRC"/protobusybox/archival/bzip2.c",
PROTOSRC"/protobusybox/archival/bbunzip.c",
LIBARCHIVE "/decompress_bunzip2.c",
LIBARCHIVE "/decompress_gunzip.c",
LIBARCHIVE "/decompress_unxz.c",
LIBARCHIVE "/open_transformer.c"
);
compile_applet("awk", PROTOSRC"/protobusybox/editors/awk.c");
compile_applet("cmp", PROTOSRC"/protobusybox/editors/cmp.c");
compile_applet("diff", PROTOSRC"/protobusybox/editors/diff.c");
compile_applet("sed", PROTOSRC"/protobusybox/editors/sed.c");
compile_applet("grep", PROTOSRC"/protobusybox/findutils/grep.c");
compile_applet("find", PROTOSRC"/protobusybox/findutils/find.c");
compile_applet("xargs", PROTOSRC"/protobusybox/findutils/xargs.c");
}
// Little things we'll do now when we have a shell /////////////////////////////
void verify_tcc_stability(void) {
run0(STORE_PROTOBUSYBOX"/bin/cp",
STORE_TINYCC"/bin/tcc", TMP_STAGE1"/tcc-bak");
compile_tcc(STORE_TINYCC"/bin/tcc");
run0(STORE_PROTOBUSYBOX"/bin/diff",
STORE_TINYCC"/bin/tcc", TMP_STAGE1"/tcc-bak");
}
void tweak_output_in_store(void) {
run0(STORE_PROTOBUSYBOX"/bin/ash", "-uexvc",
":> "TMP_STAGE1"/empty.c\n"
STORE_TINYCC"/bin/tcc -c "TMP_STAGE1"/empty.c "
"-o "TMP_STAGE1"/empty.o\n"
STORE_TINYCC"/bin/tcc -ar "TMP_STAGE1"/empty.a "
TMP_STAGE1"/empty.o\n"
STORE_PROTOBUSYBOX"/bin/cp "TMP_STAGE1"/empty.a "
STORE_PROTOMUSL"/lib/libm.a\n"
STORE_PROTOBUSYBOX"/bin/cp "TMP_STAGE1"/empty.a "
STORE_PROTOMUSL"/lib/libpthread.a\n"
STORE_PROTOBUSYBOX"/bin/rm -rf "
STORE_PROTOMUSL"/include\n"
STORE_PROTOBUSYBOX"/bin/mkdir -p "
STORE_PROTOMUSL"/include/bits\n"
STORE_PROTOBUSYBOX"/bin/cp -rf "
PROTOSRC"/protomusl/host-generated/sed1/bits "
PROTOSRC"/protomusl/host-generated/sed2/bits "
PROTOSRC"/protomusl/arch/generic/* "
PROTOSRC"/protomusl/arch/x86_64/* "
PROTOSRC"/protomusl/include/* "
STORE_PROTOMUSL"/include/\n"
);
}
void wrap_tcc_tools(void) {
#define EXECTCC "#!"STORE_PROTOBUSYBOX"/bin/ash\n" \
"exec "STORE_TINYCC"/bin/tcc"
#define PASSTHROUGH "\\\"\\$@\\\"" // i.e., \"\$@\", i.e, "$@"
run0(STORE_PROTOBUSYBOX"/bin/ash", "-uexvc",
"PATH="STORE_PROTOBUSYBOX"/bin\n"
"mkdir -p "STORE_TINYCC"/wrappers\n"
"cd "STORE_TINYCC"/wrappers\n"
"_CPP_ARGS=\"-I"STORE_PROTOMUSL"/include\"\n"
"_LD_ARGS='-static'\n"
"echo -e \"" EXECTCC " $_LD_ARGS " PASSTHROUGH"\" > cc\n"
"echo -e \"" EXECTCC " -E $_CPP_ARGS " PASSTHROUGH"\" > cpp\n"
"echo -e \"" EXECTCC " $_LD_ARGS " PASSTHROUGH"\" > ld\n"
"echo -e \"" EXECTCC " -ar " PASSTHROUGH "\" > ar\n"
"chmod +x cc cpp ld ar\n"
);
}
// The main plot ///////////////////////////////////////////////////////////////
int _start() {
struct args_accumulator aa_cmd;
struct args_accumulator aa_link_objs;
log("hello from stage1!");
#ifdef INSIDE_NIX
log("executed inside nix");
log("TCC_SEED=" TCC_SEED);
log("PROTOSRC=" PROTOSRC);
log("RECIPES_STAGE1=" RECIPES_STAGE1);
log("TMP_STAGE1=" TMP_STAGE1);
log("STORE_PROTOBUSYBOX=" STORE_PROTOBUSYBOX);
log("STORE_PROTOMUSL=" STORE_PROTOMUSL);
log("STORE_TINYCC=" STORE_TINYCC);
#endif
log("creating directories...");
mkdirs_at("/",
TMP_STAGE1, STORE_PROTOBUSYBOX, STORE_PROTOMUSL, STORE_TINYCC);
sanity_test();
// starting with the seeded TCC
compile_libtcc1_1st_time_nostd(TCC_SEED);
compile_protomusl(TCC_SEED);
test_example_1st_time_nostd(TCC_SEED);
// build the first TCC that comes from our sources
compile_tcc_1st_time_nostd(TCC_SEED);
test_example_intermediate(STORE_TINYCC"/bin/tcc");
// rebuild everything with it
compile_libtcc1(STORE_TINYCC"/bin/tcc");
compile_protomusl(STORE_TINYCC"/bin/tcc");
test_example_intermediate(STORE_TINYCC"/bin/tcc");
// this is the final tcc we'll build, should not be worth repeating
compile_tcc(STORE_TINYCC"/bin/tcc");
// recompile everything else with the final tcc (could be an overkill)
compile_libtcc1(STORE_TINYCC"/bin/tcc");
compile_protomusl(STORE_TINYCC"/bin/tcc");
test_example_intermediate(STORE_TINYCC"/bin/tcc");
compile_standalone_busybox_applets(STORE_TINYCC"/bin/tcc");
verify_tcc_stability();
tweak_output_in_store();
wrap_tcc_tools();
test_example_final(STORE_TINYCC"/wrappers/cc");
log("done");
#ifndef CHAINLOAD
return 0;
#else
assert(execve(CHAINLOAD, (char*[]) {CHAINLOAD, 0}, NULL));
log("could not exec into next stages (ok when building with make)");
return 99;
#endif
}

View file

@ -0,0 +1,21 @@
#include <stdio.h>
#ifndef RECIPES_STAGE1
#define RECIPES_STAGE1 "/recipes/1-stage1"
#endif
#define SOURCE_PATH RECIPES_STAGE1"/hello.c"
int main(int argc, char** argv) {
printf("Hello world!\n2*2=%d\n", 2*2);
printf("Own source (%s):\n", SOURCE_PATH);
FILE* f = fopen(SOURCE_PATH, "r");
while (!feof(f)) {
fputc(fgetc(f), stdout);
}
if (ferror(f))
return 99;
fclose(f);
return 42;
}

View file

@ -0,0 +1,46 @@
extern int APPLET_MAIN(int argc, char** argv); // templated in
#include <string.h>
#include <unistd.h>
#include <errno.h>
static inline int *get_perrno(void) { return &errno; }
int *const bb_errno;
char bb_common_bufsiz1[1024];
const char *applet_name;
int _argc;
const char **_argv;
int main(int argc, char** argv) {
int** bb_errno_ptr = &((int*) bb_errno);
*bb_errno_ptr = ((int*) get_perrno());
asm volatile ("":::"memory"); // counter optimizations
_argc = argc; _argv = argv;
applet_name = strrchr(argv[0], '/') \
? strrchr(argv[0], '/') + 1 \
: argv[0];
return APPLET_MAIN(argc, argv);
}
void bb_show_usage(void) {
int i;
write(2 /* STDERR */, "protobusybox's show_usage stub\n", 31);
write(2 /* STDERR */, "ho help for you, sorry. argv[]: \n", 33);
for (i < 0; i < _argc; i++) {
write(2 /* STDERR */, "* `", 3);
write(2 /* STDERR */, _argv[i], strlen(_argv[i]));
write(2 /* STDERR */, "`\n", 2);
}
exit(1);
}
// appletlib replacement
unsigned string_array_len(char **argv) {
unsigned i;
for (i = 0; argv[i]; i++);
return i;
}

View file

@ -0,0 +1,240 @@
#define NUM_APPLETS 1
#define BB_GLOBAL_CONST
#define BB_VER "1.36.1"
#define AUTOCONF_TIMESTAMP
#define _GNU_SOURCE
extern char bb_common_bufsiz1[];
#define setup_common_bufsiz() ((void)0)
enum { COMMON_BUFSIZE = 1024 };
#define CONFIG_BUSYBOX_EXEC_PATH "/proc/self/exe"
#define CONFIG_FEATURE_COPYBUF_KB 256
#define CONFIG_FEATURE_EDITING_MAX_LEN 1024
#define CONFIG_GZIP_FAST 2
#define CONFIG_UNAME_OSNAME "Linux"
#define ENABLE_ASH_ALIAS 0
#define ENABLE_ASH_BASH_COMPAT 0
#define ENABLE_ASH_CMDCMD 1
#define ENABLE_ASH_ECHO 0
#define ENABLE_ASH_GETOPTS 1
#define ENABLE_ASH_JOB_CONTROL 0
#define ENABLE_ASH_MAIL 0
#define ENABLE_ASH_PRINTF 1
#define ENABLE_ASH_SLEEP 0
#define ENABLE_ASH_TEST 1
#define ENABLE_BB_ARCH 1
#define ENABLE_BUNZIP2 0
#define ENABLE_BZCAT 0
#define ENABLE_DEBUG 0
#define ENABLE_DESKTOP 1
#define ENABLE_EGREP 0
#define ENABLE_FEATURE_ALLOW_EXEC 0
#define ENABLE_FEATURE_AWK_LIBM 0
#define ENABLE_FEATURE_BZIP2_DECOMPRESS 1
#define ENABLE_FEATURE_CLEAN_UP 0
#define ENABLE_FEATURE_CP_REFLINK 0
#define ENABLE_FEATURE_CROND_D 0
#define ENABLE_FEATURE_CUT_REGEX 0
#define ENABLE_FEATURE_EDITING 0
#define ENABLE_FEATURE_FANCY_ECHO 1
#define ENABLE_FEATURE_FIND_NOT 1
#define ENABLE_FEATURE_FIND_PAREN 1
#define ENABLE_FEATURE_FIND_PRUNE 1
#define ENABLE_FEATURE_FIND_TYPE 1
#define ENABLE_FEATURE_GZIP_DECOMPRESS 1
#define ENABLE_FEATURE_HUMAN_READABLE 0
#define ENABLE_FEATURE_LS_COLOR 0
#define ENABLE_FEATURE_LS_FILETYPES 0
#define ENABLE_FEATURE_LS_FOLLOWLINKS 0
#define ENABLE_FEATURE_LS_RECURSIVE 0
#define ENABLE_FEATURE_LS_SORTFILES 0
#define ENABLE_FEATURE_LS_TIMESTAMPS 1
#define ENABLE_FEATURE_LS_WIDTH 0
#define ENABLE_FEATURE_NON_POSIX_CP 0
#define ENABLE_FEATURE_PRESERVE_HARDLINKS 0
#define ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS 0
#define ENABLE_FEATURE_SEAMLESS_BZ2 1
#define ENABLE_FEATURE_SEAMLESS_GZ 1
#define ENABLE_FEATURE_SEAMLESS_LZMA 0
#define ENABLE_FEATURE_SEAMLESS_XZ 1
#define ENABLE_FEATURE_SEAMLESS_Z 0
#define ENABLE_FEATURE_SHOW_THREADS 0
#define ENABLE_FEATURE_SH_MATH 1
#define ENABLE_FEATURE_SH_READ_FRAC 0
#define ENABLE_FEATURE_SYSLOG 0
#define ENABLE_FEATURE_TAR_AUTODETECT 1
#define ENABLE_FEATURE_TAR_CREATE 1
#define ENABLE_FEATURE_TAR_GNU_EXTENSIONS 1
#define ENABLE_FEATURE_TAR_LONG_OPTIONS 1
#define ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY 1
#define ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY 0
#define ENABLE_FEATURE_TOPMEM 1
#define ENABLE_FEATURE_TOP_SMP_PROCESS 0
#define ENABLE_FEATURE_TOUCH_SUSV3 1
#define ENABLE_FEATURE_TR_CLASSES 0
#define ENABLE_FEATURE_TR_EQUIV 0
#define ENABLE_FEATURE_USE_SENDFILE 0
#define ENABLE_FEATURE_VERBOSE 0
#define ENABLE_FGREP 0
#define ENABLE_FTPD 0
#define ENABLE_HUSH_PRINTF 0
#define ENABLE_HUSH_TEST 0
#define ENABLE_KILLALL 0
#define ENABLE_LOCALE_SUPPORT 1
#define ENABLE_LONG_OPTS 1
#define ENABLE_LZCAT 0
#define ENABLE_PGREP 0
#define ENABLE_PIDOF 0
#define ENABLE_PKILL 0
#define ENABLE_SELINUX 0
#define ENABLE_SESTATUS 0
#define ENABLE_TAR 1
#define ENABLE_TEST1 0
#define ENABLE_TEST2 0
#define ENABLE_UNAME 0
#define ENABLE_UNLZMA 0
#define ENABLE_ZCAT 0
#define IF_AR(...)
#define IF_ASH_ALIAS(...)
#define IF_ASH_BASH_COMPAT(...)
#define IF_ASH_EXPAND_PRMT(...)
#define IF_ASH_HELP(...)
#define IF_ASH_OPTIMIZE_FOR_SIZE(...)
#define IF_BASENAME(...)
#define IF_BUNZIP2(...)
#define IF_BZCAT(...)
#define IF_BZIP2(...) __VA_ARGS__
#define IF_CAT(...)
#define IF_CHGRP(...)
#define IF_CHMOD(...)
#define IF_CHOWN(...)
#define IF_CHROOT(...)
#define IF_CHVT(...)
#define IF_CKSUM(...)
#define IF_CLEAR(...)
#define IF_CPIO(...)
#define IF_DEALLOCVT(...)
#define IF_DESKTOP(...) __VA_ARGS__
#define IF_DPKG(...)
#define IF_DPKG_DEB(...)
#define IF_DUMPKMAP(...)
#define IF_ECHO(...) __VA_ARGS__
#define IF_EXTRA_COMPAT(...)
#define IF_FEATURE_AWK_GNU_EXTENSIONS(...)
#define IF_FEATURE_BZIP2_DECOMPRESS(...) __VA_ARGS__
#define IF_FEATURE_CATN(...)
#define IF_FEATURE_CATV(...)
#define IF_FEATURE_CP_REFLINK(...)
#define IF_FEATURE_CUT_REGEX(...)
#define IF_FEATURE_FIND_AMIN(...)
#define IF_FEATURE_FIND_ATIME(...)
#define IF_FEATURE_FIND_CMIN(...)
#define IF_FEATURE_FIND_CONTEXT(...)
#define IF_FEATURE_FIND_CTIME(...)
#define IF_FEATURE_FIND_DELETE(...)
#define IF_FEATURE_FIND_DEPTH(...)
#define IF_FEATURE_FIND_EMPTY(...)
#define IF_FEATURE_FIND_EXEC(...)
#define IF_FEATURE_FIND_EXECUTABLE(...)
#define IF_FEATURE_FIND_EXEC_PLUS(...)
#define IF_FEATURE_FIND_GROUP(...)
#define IF_FEATURE_FIND_INUM(...)
#define IF_FEATURE_FIND_LINKS(...)
#define IF_FEATURE_FIND_MAXDEPTH(...)
#define IF_FEATURE_FIND_MMIN(...)
#define IF_FEATURE_FIND_MTIME(...)
#define IF_FEATURE_FIND_NEWER(...)
#define IF_FEATURE_FIND_NOT(...) __VA_ARGS__
#define IF_FEATURE_FIND_PAREN(...) __VA_ARGS__
#define IF_FEATURE_FIND_PATH(...)
#define IF_FEATURE_FIND_PERM(...)
#define IF_FEATURE_FIND_PRINT0(...)
#define IF_FEATURE_FIND_PRUNE(...) __VA_ARGS__
#define IF_FEATURE_FIND_QUIT(...)
#define IF_FEATURE_FIND_REGEX(...)
#define IF_FEATURE_FIND_SAMEFILE(...)
#define IF_FEATURE_FIND_SIZE(...)
#define IF_FEATURE_FIND_TYPE(...) __VA_ARGS__
#define IF_FEATURE_FIND_USER(...)
#define IF_FEATURE_FIND_XDEV(...)
#define IF_FEATURE_GREP_CONTEXT(...)
#define IF_FEATURE_GZIP_DECOMPRESS(...) __VA_ARGS__
#define IF_FEATURE_HUMAN_READABLE(...)
#define IF_FEATURE_INSTALL_LONG_OPTIONS(...)
#define IF_FEATURE_LS_COLOR(...)
#define IF_FEATURE_LS_FILETYPES(...)
#define IF_FEATURE_LS_FOLLOWLINKS(...)
#define IF_FEATURE_LS_RECURSIVE(...)
#define IF_FEATURE_LS_SORTFILES(...)
#define IF_FEATURE_LS_TIMESTAMPS(...) __VA_ARGS__
#define IF_FEATURE_LS_WIDTH(...)
#define IF_FEATURE_SEAMLESS_BZ2(...) __VA_ARGS__
#define IF_FEATURE_SEAMLESS_GZ(...) __VA_ARGS__
#define IF_FEATURE_SEAMLESS_LZMA(...)
#define IF_FEATURE_SEAMLESS_XZ(...) __VA_ARGS__
#define IF_FEATURE_SEAMLESS_Z(...)
#define IF_FEATURE_SHOW_THREADS(...)
#define IF_FEATURE_SH_MATH(...) __VA_ARGS__
#define IF_FEATURE_TAR_AUTODETECT(...) __VA_ARGS__
#define IF_FEATURE_TAR_CREATE(...) __VA_ARGS__
#define IF_FEATURE_TAR_FROM(...) __VA_ARGS__
#define IF_FEATURE_TAR_LONG_OPTIONS(...) __VA_ARGS__
#define IF_FEATURE_TAR_NOPRESERVE_TIME(...) __VA_ARGS__
#define IF_FEATURE_TAR_OLDGNU_COMPATIBILITY(...) __VA_ARGS__
#define IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(...)
#define IF_FEATURE_TAR_TO_COMMAND(...)
#define IF_FEATURE_TIMEZONE(...)
#define IF_FEATURE_TOUCH_SUSV3(...) __VA_ARGS__
#define IF_FEATURE_VERBOSE(...)
#define IF_FEATURE_XARGS_SUPPORT_ARGS_FILE(...)
#define IF_FEATURE_XARGS_SUPPORT_CONFIRMATION(...)
#define IF_FEATURE_XARGS_SUPPORT_PARALLEL(...)
#define IF_FEATURE_XARGS_SUPPORT_QUOTES(...)
#define IF_FEATURE_XARGS_SUPPORT_REPL_STR(...)
#define IF_FEATURE_XARGS_SUPPORT_TERMOPT(...)
#define IF_FEATURE_XARGS_SUPPORT_ZERO_TERM(...)
#define IF_FGCONSOLE(...)
#define IF_GUNZIP(...) __VA_ARGS__
#define IF_GZIP(...) __VA_ARGS__
#define IF_KBD_MODE(...)
#define IF_LOADFONT(...)
#define IF_LOADKMAP(...)
#define IF_LONG_OPTS(...) __VA_ARGS__
#define IF_LS(...) __VA_ARGS__
#define IF_LZCAT(...)
#define IF_LZMA(...)
#define IF_LZOP(...)
#define IF_LZOPCAT(...)
#define IF_NOT_ASH_OPTIMIZE_FOR_SIZE(...) __VA_ARGS__
#define IF_NOT_DESKTOP(...)
#define IF_NOT_FEATURE_FIND_MAXDEPTH(...) __VA_ARGS__
#define IF_NOT_FEATURE_TAR_CREATE(...)
#define IF_NOT_FEATURE_TOUCH_SUSV3(...)
#define IF_OPENVT(...)
#define IF_PRINTF(...) __VA_ARGS__
#define IF_RESET(...)
#define IF_RESIZE(...)
#define IF_RPM(...)
#define IF_RPM2CPIO(...)
#define IF_SELINUX(...)
#define IF_SETCONSOLE(...)
#define IF_SETFONT(...)
#define IF_SETKEYCODES(...)
#define IF_SETLOGCONS(...)
#define IF_SHELL_ASH(...) __VA_ARGS__
#define IF_SHELL_HUSH(...)
#define IF_SHOWKEY(...)
#define IF_SLEEP(...)
#define IF_TAR(...)
#define IF_UNAME(...) __VA_ARGS__
#define IF_UNCOMPRESS(...)
#define IF_UNLZMA(...)
#define IF_UNLZOP(...)
#define IF_UNXZ(...) __VA_ARGS__
#define IF_UNZIP(...)
#define IF_XZ(...)
#define IF_XZCAT(...)
#define IF_ZCAT(...)

View file

@ -0,0 +1,89 @@
#!/usr/bin/env bash
# 1st stage is special
# in that we don't have any semblance of a system to start with,
# meaning we can't even unpack sources, let alone patch them or something.
# For stage 1, we pre-unpack sources on the host and then fix them up with
# host's sed.
#> FETCH 7a35eae33d5372a7c0da1188de798726f68825513b7ae3ebe97aaaa52114f039
#> FROM http://musl.libc.org/releases/musl-1.2.4.tar.gz
#> FETCH f5a71d05664340ae46cda9579c6079a0f2fa809d24386d284f0d091e4d576a4e
#> FROM https://github.com/TinyCC/tinycc/archive/af1abf1f45d45b34f0b02437f559f4dfdba7d23c.tar.gz
#> AS tinycc-mob-af1abf1.tar.gz
#> FETCH b8cc24c9574d809e7279c3be349795c5d5ceb6fdf19ca709f80cde50e47de314
#> FROM https://busybox.net/downloads/busybox-1.36.1.tar.bz2
set -ueo pipefail
TGT="$DESTDIR/tmp/1-stage1"
echo "### $0: unpacking protomusl sources..."
mkdir -p "$DESTDIR/protosrc/protomusl"
tar --strip-components=1 -xzf downloads/musl-1.2.4.tar.gz \
-C "$DESTDIR/protosrc/protomusl"
echo "### $0: unpacking tinycc sources..."
mkdir -p "$DESTDIR/protosrc/tinycc"
tar --strip-components=1 -xzf downloads/tinycc-mob-af1abf1.tar.gz \
-C $DESTDIR/protosrc/tinycc
echo "### $0: unpacking protobusybox sources..."
mkdir -p "$DESTDIR/protosrc/protobusybox"
tar --strip-components=1 -xjf downloads/busybox-1.36.1.tar.bz2 \
-C "$DESTDIR/protosrc/protobusybox"
echo "### $0: patching up protomusl stage 1 sources..."
# original syscall_arch.h is not tcc-compatible, our syscall.h is dual-role
cp recipes/1-stage1/syscall.h \
"$DESTDIR/protosrc/protomusl/arch/x86_64/syscall_arch.h"
pushd "$DESTDIR/protosrc/protomusl/" >/dev/null
# eliminiate a source path reference
sed -i 's/__FILE__/"__FILE__"/' include/assert.h
# two files have to be generated with host sed
mkdir -p host-generated/{sed1,sed2}/bits
sed -f ./tools/mkalltypes.sed \
./arch/x86_64/bits/alltypes.h.in \
./include/alltypes.h.in \
> host-generated/sed1/bits/alltypes.h
sed -n -e s/__NR_/SYS_/p \
< arch/x86_64/bits/syscall.h.in \
> host-generated/sed2/bits/syscall.h
# more frivolous patching
echo '#define VERSION "1.2.2"' > src/internal/version.h
sed -i 's/@PLT//' src/signal/x86_64/sigsetjmp.s
rm -f src/signal/restore.c # *BIG URGH*
rm -f src/thread/clone.c # *BIG URGH #2*
rm -f src/thread/__set_thread_area.c # possible double-define
rm -f src/thread/__unmapself.c # double-define
rm -f src/math/sqrtl.c # tcc-incompatible
rm -f src/math/{acoshl,acosl,asinhl,asinl,hypotl}.c # sqrtl dep
sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \
src/stdio/popen.c src/process/system.c
sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\
src/misc/wordexp.c
popd >/dev/null
echo "### $0: patching up tinycc stage 1 sources..."
pushd "$DESTDIR/protosrc/tinycc" >/dev/null
:> config.h
# eliminate a source path reference
sed -i 's/__FILE__/"__FILE__"/' tcc.h
# don't hardcode paths
sed -i 's/SHN_ABS, filename);/SHN_ABS, "FILE stub");/' tccdbg.c
# break a circular dependency
sed -i 's/abort();//' lib/va_list.c
popd >/dev/null
echo "### $0: patching up protobusybox stage 1 sources..."
pushd "$DESTDIR/protosrc/protobusybox" >/dev/null
:> include/NUM_APPLETS.h
:> include/common_bufsiz.h
# eliminate a source path reference
sed -i 's/__FILE__/"__FILE__"/' miscutils/fbsplash.c include/libbb.h
# already fixed in an unreleased version
sed -i 's/extern struct test_statics \*const test_ptr_to_statics/extern struct test_statics *BB_GLOBAL_CONST test_ptr_to_statics/' coreutils/test.c
popd >/dev/null
echo "### $0: done"

View file

@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2021 Alexander Sosedkin <monk@unboiled.info>
// SPDX-License-Identifier: MIT
// constants/macro for this file to serve as a drop-in replacement
// for musl-1.2.2's arch/x86_64/syscall_arch.h
#define __SYSCALL_LL_E(x) (x)
#define __SYSCALL_LL_O(x) (x)
#define VDSO_USEFUL
#define VDSO_CGT_SYM "__vdso_clock_gettime"
#define VDSO_CGT_VER "LINUX_2.6"
#define VDSO_GETCPU_SYM "__vdso_getcpu"
#define VDSO_GETCPU_VER "LINUX_2.6"
#define IPC_64 0
// a different, tcc-compatible implementation of syscall invocations functions
static long __syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6);
asm (
//".globl __syscall6;"
".type __syscall6, @function;"
"__syscall6:;"
"movq %rdi, %rax;"
"movq %rsi, %rdi;"
"movq %rdx, %rsi;"
"movq %rcx, %rdx;"
"movq %r8, %r10;"
"movq %r9, %r8;"
"movq 8(%rsp),%r9;"
"syscall;"
"ret"
);
static __inline long __syscall5(long n, long a1, long a2, long a3, long a4, long a5) {
return __syscall6(n, a1, a2, a3, a4, a5, 0);
}
static __inline long __syscall4(long n, long a1, long a2, long a3, long a4) {
return __syscall6(n, a1, a2, a3, a4, 0, 0);
}
static __inline long __syscall3(long n, long a1, long a2, long a3) {
return __syscall6(n, a1, a2, a3, 0, 0, 0);
}
static __inline long __syscall2(long n, long a1, long a2) {
return __syscall6(n, a1, a2, 0, 0, 0, 0);
}
static __inline long __syscall1(long n, long a1) {
return __syscall6(n, a1, 0, 0, 0, 0, 0);
}
static __inline long __syscall0(long n) {
return __syscall6(n, 0, 0, 0, 0, 0, 0);
}

View file

@ -0,0 +1,54 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH dd16fb1d67bfab79a72f5e8390735c49e3e8e70b4945a15ab1f81ddb78658fb3
#> FROM http://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz
set -uex
export PATH=/store/1-stage1/tinycc/wrappers:/store/1-stage1/protobusybox/bin
mkdir -p /store/2a0-static-gnumake /tmp/2a0-static-gnumake
cd /tmp/2a0-static-gnumake
echo "### $0: unpacking static GNU Make sources..."
tar --strip-components=1 -xf /downloads/make-4.4.1.tar.gz
echo "### $0: fixing up static GNU Make sources..."
sed -i 's|/bin/sh|/store/1-stage1/protobusybox/bin/ash|' \
src/job.c build-aux/install-sh po/Makefile.in.in
# this is part of stdlib, no idea how it's supposed to not clash
rm src/getopt.h
for f in src/getopt.c src/getopt1.c; do :> $f; done
for f in lib/fnmatch.c lib/glob.c lib/xmalloc.c lib/error.c; do :> $f; done
# embrace chaos
shuffle_comment='\/\* Handle shuffle mode argument. \*\/'
shuffle_default='if (!shuffle_mode) shuffle_mode = xstrdup(\"random\");'
sed -i "s|$shuffle_comment|$shuffle_comment\n$shuffle_default|" src/main.c
grep 'if (!shuffle_mode) shuffle_mode = xstrdup("random");' src/main.c
echo "### $0: building static GNU Make..."
ash ./configure \
--build x86_64-linux \
--disable-dependency-tracking \
--prefix=/store/2a0-static-gnumake \
CONFIG_SHELL='/store/1-stage1/protobusybox/bin/ash' \
SHELL='/store/1-stage1/protobusybox/bin/ash'
ash ./build.sh
echo "### $0: testing static GNU Make by remaking it with itself..."
mv make make-intermediate
./make-intermediate -j $NPROC clean
./make-intermediate -j $NPROC CFLAGS=-O2
echo "### $0: installing static GNU Make..."
./make -j $NPROC install
echo "### $0: creating a wrapper that respects \$SHELL..."
# FIXME: patch make to use getenv?
mkdir /store/2a0-static-gnumake/wrappers; cd /store/2a0-static-gnumake/wrappers
echo "#!/store/1-stage1/protobusybox/bin/ash" > make
echo "exec /store/2a0-static-gnumake/bin/make SHELL=\$SHELL \"\$@\"" \ >> make
chmod +x make
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2a0 /store/2a0-static-gnumake )

View file

@ -0,0 +1,47 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH 645c25f563b8adc0a81dbd6a41cffbf4d37083a382e02d5d3df4f65c09516d00
#> FROM https://ftp.gnu.org/gnu/binutils/binutils-2.39.tar.xz
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/1-stage1/tinycc/wrappers"
export PATH="$PATH:/store/2a0-static-gnumake/bin"
mkdir -p /tmp/2a1-static-binutils; cd /tmp/2a1-static-binutils
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking binutils sources..."
tar --strip-components=1 -xf /downloads/binutils-2.39.tar.xz
echo "### $0: building static binutils..."
sed -i 's|/bin/sh|/store/1-stage1/protobusybox/bin/ash|' \
missing install-sh mkinstalldirs
mkdir aliases
ln -s /store/1-stage1/protobusybox/bin/true aliases/makeinfo
PATH="/tmp/2a1-static-binutils/aliases:$PATH"
export lt_cv_sys_max_cmd_len=32768
# see libtool's 74c8993c178a1386ea5e2363a01d919738402f30
sed -i 's/| \$NL2SP/| sort | $NL2SP/' ltmain.sh
ash configure \
CONFIG_SHELL=/store/1-stage1/protobusybox/bin/ash \
SHELL=/store/1-stage1/protobusybox/bin/ash \
CFLAGS='-O2 -D__LITTLE_ENDIAN__=1' \
CFLAGS_FOR_TARGET=-O2 \
MAKEINFO=/store/1-stage1/protobusybox/bin/true \
--disable-gprofng \
--enable-deterministic-archives \
--host x86_64-linux --build x86_64-linux \
--prefix=/store/2a1-static-binutils
make -j $NPROC all-libiberty all-gas all-bfd all-libctf all-zlib all-gprof
make all-ld # race condition on ld/.deps/ldwrite.Po, serialize
make -j $NPROC
echo "### $0: installing static binutils..."
make -j $NPROC install
rm /store/2a1-static-binutils/lib/*.la # broken, reference builddir
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2a1 /store/2a1-static-binutils )

View file

@ -0,0 +1,71 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH f69eff1bc3d15d4e59011d587c57462a8d3d32cf2378d32d30d008a42a863325
#> FROM https://gmplib.org/download/gmp/archive/gmp-4.3.2.tar.xz
#> FETCH d7271bbfbc9ddf387d3919df8318cd7192c67b232919bfa1cb3202d07843da1b
#> FROM https://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.xz
#> FETCH e664603757251fd8a352848276497a4c79b7f8b21fd8aedd5cc0598a38fee3e4
#> FROM http://www.multiprecision.org/downloads/mpc-0.8.1.tar.gz
#> FETCH 92e61c6dc3a0a449e62d72a38185fda550168a86702dea07125ebd3ec3996282
#> FROM https://ftp.gnu.org/gnu/gcc/gcc-4.7.4/gcc-4.7.4.tar.bz2
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/1-stage1/tinycc/wrappers"
export PATH="$PATH:/store/2a0-static-gnumake/bin"
mkdir -p /tmp/2a2-static-gnugcc4-c; cd /tmp/2a2-static-gnugcc4-c
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: aliasing ash to sh..."
mkdir aliases; ln -s /store/1-stage1/protobusybox/bin/ash aliases/sh
export PATH="/tmp/2a2-static-gnugcc4-c/aliases:$PATH"
echo "### $0: unpacking GNU GCC sources..."
mkdir mpfr mpc gmp
tar --strip-components=1 -xf /downloads/gcc-4.7.4.tar.bz2
tar --strip-components=1 -xf /downloads/mpfr-2.4.2.tar.xz -C mpfr
tar --strip-components=1 -xf /downloads/mpc-0.8.1.tar.gz -C mpc
tar --strip-components=1 -xf /downloads/gmp-4.3.2.tar.xz -C gmp
echo "### $0: building static GNU GCC 4 (statically linked, C only)"
sed -i 's|/bin/sh|/store/1-stage1/protobusybox/bin/ash|' \
missing move-if-change mkdep mkinstalldirs symlink-tree \
gcc/genmultilib */*.sh gcc/exec-tool.in \
install-sh */install-sh
sed -i 's|^\(\s*\)sh |\1/store/1-stage1/protobusybox/bin/ash |' \
Makefile* */Makefile*
sed -i 's|LIBGCC2_DEBUG_CFLAGS = -g|LIBGCC2_DEBUG_CFLAGS = |' \
libgcc/Makefile.in
# see libtool's 74c8993c178a1386ea5e2363a01d919738402f30
sed -i 's/| \$NL2SP/| sort | $NL2SP/' ltmain.sh */ltmain.sh
ash configure \
CONFIG_SHELL='/store/1-stage1/protobusybox/bin/ash' \
SHELL='/store/1-stage1/protobusybox/bin/ash' \
CFLAGS=-O2 CFLAGS_FOR_TARGET=-O2 \
--with-sysroot=/store/1-stage1/protomusl \
--with-native-system-header-dir=/include \
--with-build-time-tools=/store/2a1-static-binutils/bin \
--prefix=/store/2a2-static-gnugcc4-c \
--enable-languages=c \
--disable-bootstrap \
--disable-libquadmath --disable-decimal-float --disable-fixed-point \
--disable-lto \
--disable-libgomp \
--disable-multilib \
--disable-multiarch \
--disable-libmudflap \
--disable-libssp \
--disable-nls \
--host x86_64-linux --build x86_64-linux
make -j $NPROC
echo "### $0: installing static GNU GCC 4 (statically linked, C only)"
make -j $NPROC install
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2a2 /store/2a2-static-gnugcc4-c )

View file

@ -0,0 +1,36 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH 7a35eae33d5372a7c0da1188de798726f68825513b7ae3ebe97aaaa52114f039
#> FROM http://musl.libc.org/releases/musl-1.2.4.tar.gz
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/2a0-static-gnumake/bin"
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a2-static-gnugcc4-c/bin"
mkdir -p /tmp/2a3-intermediate-musl; cd /tmp/2a3-intermediate-musl
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking musl sources..."
tar --strip-components=1 -xf /downloads/musl-1.2.4.tar.gz
echo "### $0: building musl with GNU GCC..."
sed -i 's|/bin/sh|/store/1-stage1/protobusybox/bin/ash|' \
tools/*.sh \
# patch popen/system to search in PATH instead of hardcoding /bin/sh
sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \
src/stdio/popen.c src/process/system.c
sed -i 's|execl("/bin/sh", "sh", "-c",|execlp("sh", "-c",|'\
src/misc/wordexp.c
# eliminiate a source path reference
sed -i 's/__FILE__/"__FILE__"/' include/assert.h
ash ./configure --prefix=/store/2a3-intermediate-musl
make -j $NPROC
echo "### $0: installing musl..."
make -j $NPROC install
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2a3 /store/2a3-intermediate-musl )

97
06/recipes/2a4-gnugcc4-cpp.sh Executable file
View file

@ -0,0 +1,97 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH f69eff1bc3d15d4e59011d587c57462a8d3d32cf2378d32d30d008a42a863325
#> FROM https://gmplib.org/download/gmp/archive/gmp-4.3.2.tar.xz
#> FETCH d7271bbfbc9ddf387d3919df8318cd7192c67b232919bfa1cb3202d07843da1b
#> FROM https://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.xz
#> FETCH e664603757251fd8a352848276497a4c79b7f8b21fd8aedd5cc0598a38fee3e4
#> FROM http://www.multiprecision.org/downloads/mpc-0.8.1.tar.gz
#> FETCH 92e61c6dc3a0a449e62d72a38185fda550168a86702dea07125ebd3ec3996282
#> FROM https://ftp.gnu.org/gnu/gcc/gcc-4.7.4/gcc-4.7.4.tar.bz2
set -uex
export PATH='/store/_2a0-ccache/wrappers/c' # may or may not exist
export PATH="$PATH:/store/1-stage1/protobusybox/bin"
export PATH="$PATH:/store/2a0-static-gnumake/bin"
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a2-static-gnugcc4-c/bin"
mkdir -p /tmp/2a4-gnugcc4-cpp; cd /tmp/2a4-gnugcc4-cpp
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: aliasing ash to sh..."
mkdir aliases; ln -s /store/1-stage1/protobusybox/bin/ash aliases/sh
export PATH="/tmp/2a4-gnugcc4-cpp/aliases:$PATH"
echo "### $0: creating wrappers that make previous GNU GCC target new musl..."
SYSROOT=/store/2a3-intermediate-musl
export _SYSROOT="--sysroot $SYSROOT"
export _LDFLAG="--dynamic-linker=$SYSROOT/lib/libc.so"
export _NEWINC="-I$SYSROOT/include"
export _REALCC="-I$SYSROOT/include"
mkdir wrappers
echo '#!/store/1-stage1/protobusybox/bin/ash' > wrappers/cc
echo '#!/store/1-stage1/protobusybox/bin/ash' > wrappers/cpp
echo '#!/store/1-stage1/protobusybox/bin/ash' > wrappers/ld
echo 'exec gcc $_SYSROOT -Wl,$_LDFLAG "$@"' >> wrappers/cc
echo 'exec /store/2a2-static-gnugcc4-c/bin/cpp $_NEWINC "$@"' >> wrappers/cpp
echo 'exec /store/2a1-static-binutils/bin/ld $_LDFLAG "$@"' >> wrappers/ld
chmod +x wrappers/cc wrappers/cpp wrappers/ld
export PATH="/tmp/2a4-gnugcc4-cpp/wrappers:$PATH"
echo "### $0: unpacking GNU GCC 4 sources..."
mkdir mpfr mpc gmp
tar --strip-components=1 -xf /downloads/gcc-4.7.4.tar.bz2
tar --strip-components=1 -xf /downloads/mpfr-2.4.2.tar.xz -C mpfr
tar --strip-components=1 -xf /downloads/mpc-0.8.1.tar.gz -C mpc
tar --strip-components=1 -xf /downloads/gmp-4.3.2.tar.xz -C gmp
echo "### $0: fixing up GNU GCC 4 sources..."
sed -i 's|/bin/sh|/store/1-stage1/protobusybox/bin/ash|' \
missing move-if-change mkdep mkinstalldirs symlink-tree \
gcc/genmultilib */*.sh gcc/exec-tool.in \
install-sh */install-sh
sed -i 's|^\(\s*\)sh |\1/store/1-stage1/protobusybox/bin/ash |' \
Makefile* */Makefile*
sed -i 's|LIBGCC2_DEBUG_CFLAGS = -g|LIBGCC2_DEBUG_CFLAGS = |' \
libgcc/Makefile.in
sed -i "s|/lib64/ld-linux-x86-64.so.2|$SYSROOT/lib/libc.so|" \
gcc/config/i386/linux64.h
sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host
# see libtool's 74c8993c178a1386ea5e2363a01d919738402f30
sed -i 's/| \$NL2SP/| sort | $NL2SP/' ltmain.sh */ltmain.sh
echo "### $0: building GNU GCC 4 (dynamically linked, with C++ support)"
ash configure \
cache_file=nonex \
CONFIG_SHELL='/store/1-stage1/protobusybox/bin/ash' \
SHELL='/store/1-stage1/protobusybox/bin/ash' \
CC=cc CPP=cpp LD=ld \
CFLAGS=-O2 CFLAGS_FOR_TARGET=-O2 \
--with-sysroot=$SYSROOT \
--with-native-system-header-dir=/include \
--with-build-time-tools=/store/2a1-static-binutils/bin \
--prefix=/store/2a4-gnugcc4-cpp \
--with-specs='%{!static:%x{-rpath=/store/2a4-gnugcc4-cpp/lib64}}' \
--enable-languages=c,c++ \
--disable-bootstrap \
--disable-libquadmath --disable-decimal-float --disable-fixed-point \
--disable-lto \
--disable-libgomp \
--disable-multilib \
--disable-multiarch \
--disable-libmudflap \
--disable-libssp \
--disable-nls \
--disable-libitm \
--host x86_64-linux --build x86_64-linux
make -j $NPROC
echo "### $0: installing GNU GCC 4 (dynamically linked, with C++ support)"
make -j $NPROC install-strip
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2a4 /store/2a4-gnugcc4-cpp )

90
06/recipes/2a5-gnugcc10.sh Executable file
View file

@ -0,0 +1,90 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH 68dadacce515b0f8a54f510edf07c1b636492bcdb8e8d54c56eb216225d16989
#> FROM https://gmplib.org/download/gmp/gmp-6.1.0.tar.xz
#> FETCH 761413b16d749c53e2bfd2b1dfaa3b027b0e793e404b90b5fbaeef60af6517f5
#> FROM https://www.mpfr.org/mpfr-3.1.4/mpfr-3.1.4.tar.xz
#> FETCH 617decc6ea09889fb08ede330917a00b16809b8db88c29c31bfbb49cbf88ecc3
#> FROM http://www.multiprecision.org/downloads/mpc-1.0.3.tar.gz
#> FETCH 6b8b0fd7f81d0a957beb3679c81bbb34ccc7568d5682844d8924424a0dadcb1b
#> FROM http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
#> FETCH 25109543fdf46f397c347b5d8b7a2c7e5694a5a51cce4b9c6e1ea8a71ca307c1
#> FROM https://ftp.gnu.org/gnu/gcc/gcc-10.5.0/gcc-10.5.0.tar.xz
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/2a0-static-gnumake/bin"
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a4-gnugcc4-cpp/bin"
mkdir -p /tmp/2a5-gnugcc10; cd /tmp/2a5-gnugcc10
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: aliasing ash to sh..."
mkdir aliases; ln -s /store/1-stage1/protobusybox/bin/ash aliases/sh
export PATH="/tmp/2a5-gnugcc10/aliases:$PATH"
SYSROOT=/store/2a3-intermediate-musl
echo "### $0: unpacking GNU GCC 10 sources..."
mkdir gmp mpfr mpc isl
tar --strip-components=1 -xf /downloads/gcc-10.5.0.tar.xz
tar --strip-components=1 -xf /downloads/gmp-6.1.0.tar.xz -C gmp
tar --strip-components=1 -xf /downloads/mpfr-3.1.4.tar.xz -C mpfr
tar --strip-components=1 -xf /downloads/mpc-1.0.3.tar.gz -C mpc
tar --strip-components=1 -xf /downloads/isl-0.18.tar.bz2 -C isl
echo "### $0: fixing up GNU GCC 10 sources..."
sed -i 's|/bin/sh|/store/1-stage1/protobusybox/bin/ash|' \
missing move-if-change mkdep mkinstalldirs symlink-tree install-sh \
gcc/exec-tool.in libgcc/mkheader.sh
sed -i 's|^\(\s*\)sh |\1/store/1-stage1/protobusybox/bin/ash |' \
libgcc/Makefile.in
sed -i 's|LIBGCC2_DEBUG_CFLAGS = -g|LIBGCC2_DEBUG_CFLAGS = |' \
libgcc/Makefile.in
sed -i "s|/lib/ld-musl-x86_64.so.1|$SYSROOT/lib/libc.so|" \
gcc/config/i386/linux64.h
sed -i 's|m64=../lib64|m64=../lib|' gcc/config/i386/t-linux64
sed -i 's|"os/gnu-linux"|"os/generic"|' libstdc++-v3/configure.host
# see libtool's 74c8993c178a1386ea5e2363a01d919738402f30
sed -i 's/| \$NL2SP/| sort | $NL2SP/' ltmain.sh */ltmain.sh
echo "### $0: building GNU GCC 10"
ash configure \
CONFIG_SHELL='/store/1-stage1/protobusybox/bin/ash' \
SHELL='/store/1-stage1/protobusybox/bin/ash' \
CFLAGS=-O2 CXX_FLAGS=-O2 \
CFLAGS_FOR_TARGET=-O2 CXXFLAGS_FOR_TARGET=-O2 \
--with-sysroot=$SYSROOT \
--with-native-system-header-dir=/include \
--with-build-time-tools=/store/2a1-static-binutils/bin \
--prefix=/store/2a5-gnugcc10 \
--with-specs='%{!static:%x{-rpath=/store/2a5-gnugcc10/lib}}' \
--enable-languages=c,c++ \
--disable-bootstrap \
--disable-libquadmath --disable-decimal-float --disable-fixed-point \
--disable-lto \
--disable-libgomp \
--disable-multilib \
--disable-multiarch \
--disable-libmudflap \
--disable-libssp \
--disable-nls \
--disable-libitm \
--disable-libsanitizer \
--disable-cet \
--disable-gnu-unique-object \
--disable-gcov \
--disable-checking \
--host x86_64-linux-musl --build x86_64-linux-musl
make -j $NPROC
echo "### $0: installing GNU GCC 10"
make -j $NPROC install-strip
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2a5 /store/2a5-gnugcc10 )

36
06/recipes/2a6-linux-headers.sh Executable file
View file

@ -0,0 +1,36 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH cca91be956fe081f8f6da72034cded96fe35a50be4bfb7e103e354aa2159a674
#> FROM https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.4.12.tar.xz
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/2a0-static-gnumake/bin"
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a5-gnugcc10/bin"
mkdir -p /tmp/2a6-linux-headers; cd /tmp/2a6-linux-headers
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking Linux sources..."
tar --strip-components=1 -xf /downloads/linux-6.4.12.tar.xz \
linux-6.4.12/Makefile \
linux-6.4.12/arch/x86 \
linux-6.4.12/include \
linux-6.4.12/scripts \
linux-6.4.12/tools
echo "### $0: building Linux headers..."
make -j $NPROC \
CONFIG_SHELL=/store/1-stage1/protobusybox/bin/ash \
CC=gcc HOSTCC=gcc ARCH=x86_64 \
headers
echo "### $0: installing Linux headers..."
mkdir -p /store/2a6-linux-headers/
find usr/include -name '.*' | xargs rm
cp -rv usr/include /store/2a6-linux-headers/
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2a6 /store/2a6-linux-headers )

48
06/recipes/2a7-cmake.sh Executable file
View file

@ -0,0 +1,48 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH 0a905ca8635ca81aa152e123bdde7e54cbe764fdd9a70d62af44cad8b92967af
#> FROM https://github.com/Kitware/CMake/releases/download/v3.27.4/cmake-3.27.4.tar.gz
set -uex
export PATH='/store/1-stage1/protobusybox/bin/'
export PATH="$PATH:/store/2a0-static-gnumake/wrappers"
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a5-gnugcc10/bin"
export SHELL=/store/1-stage1/protobusybox/bin/ash
mkdir -p /tmp/2a7-cmake; cd /tmp/2a7-cmake
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking CMake sources..."
tar --strip-components=1 -xf /downloads/cmake-3.27.4.tar.gz
echo "### $0: fixing up CMake sources..."
sed -i "s|/bin/sh|$SHELL|" bootstrap
sed -i 's|__FILE__|"__FILE__"|' \
Source/CPack/IFW/cmCPackIFWCommon.h \
Source/CPack/cmCPack*.h \
Source/cmCTest.h
echo "### $0: bundling libraries..."
# poor man's static linking, a way for cmake to be self-contained later
mkdir -p /store/2a7-cmake/bundled-runtime
cp -H /store/2a5-gnugcc10/lib/libstdc++.so.6 /store/2a7-cmake/bundled-runtime/
cp -H /store/2a5-gnugcc10/lib/libgcc_s.so.1 /store/2a7-cmake/bundled-runtime/
echo "### $0: building CMake..."
ash configure \
CFLAGS="-DCPU_SETSIZE=128 -D_GNU_SOURCE" \
CXXFLAGS="-isystem /store/2a6-linux-headers/include" \
LDFLAGS="-Wl,-rpath /store/2a7-cmake/bundled-runtime" \
--prefix=/store/2a7-cmake \
--parallel=$NPROC \
-- \
-DCMAKE_USE_OPENSSL=OFF
make -j $NPROC
echo "### $0: installing CMake..."
make -j $NPROC install/strip
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2a7 /store/2a7-cmake )

70
06/recipes/2a8-python.sh Executable file
View file

@ -0,0 +1,70 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH 795c34f44df45a0e9b9710c8c71c15c671871524cd412ca14def212e8ccb155d
#> FROM https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tar.xz
set -uex
export PATH='/store/1-stage1/protobusybox/bin/'
export PATH="$PATH:/store/2a0-static-gnumake/wrappers"
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a5-gnugcc10/bin"
export SHELL=/store/1-stage1/protobusybox/bin/ash
mkdir -p /tmp/2a8-python; cd /tmp/2a8-python
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: aliasing ash to sh..."
mkdir aliases; ln -s /store/1-stage1/protobusybox/bin/ash aliases/sh
export PATH="/tmp/2a8-python/aliases:$PATH"
echo "### $0: unpacking CPython sources..."
tar --strip-components=1 -xf /downloads/Python-3.12.0.tar.xz
echo "### $0: fixing up CPython sources..."
sed -i "s|/bin/sh|$SHELL|" configure install-sh
sed -i 's|ac_sys_system=`uname -s`|ac_sys_system=Linux|' configure
# the precompiled pyc files aren't reproducible,
# but it's not like I need to waste time on them anyway.
# break their generation
mv Lib/compileall.py Lib/compileall.py.bak
echo 'import sys; sys.exit(0)' > Lib/compileall.py; chmod +x Lib/compileall.py
sed -i 's|__FILE__|"__FILE__"|' \
Python/errors.c \
Include/pyerrors.h \
Include/cpython/object.h \
Modules/pyexpat.c
sed -i 's|TIME __TIME__|TIME "xx:xx:xx"|' Modules/getbuildinfo.c
sed -i 's|DATE __DATE__|DATE "xx/xx/xx"|' Modules/getbuildinfo.c
# different build path length leads to different wrapping. avoid
sed -i 's|vars, stream=f|vars, stream=f, width=2**24|' Lib/sysconfig.py
echo "### $0: building CPython..."
mkdir -p /store/2a8-python/lib
ash configure \
ac_cv_broken_sem_getvalue=yes \
ac_cv_posix_semaphores_enabled=no \
OPT='-DNDEBUG -fwrapv -O3 -Wall' \
LDFLAGS='-Wl,-rpath /store/2a8-python/lib' \
--without-static-libpython \
--build x86_64-linux-musl \
--prefix=/store/2a8-python \
--enable-shared \
--with-ensurepip=no
# ensure reproducibility in case of no /dev/shm
grep 'define POSIX_SEMAPHORES_NOT_ENABLED 1' pyconfig.h
grep 'define HAVE_BROKEN_SEM_GETVALUE 1' pyconfig.h
make -j $NPROC
echo "### $0: installing CPython..."
make -j $NPROC install
# strip builddir mentions
sed -i "s|/tmp/2a8-python|...|g" \
/store/2a8-python/lib/python3.*/_sysconfigdata__*.py \
/store/2a8-python/lib/python3.*/config-3.*-x86_64-linux-musl/Makefile
# restore compileall just in case
cat Lib/compileall.py.bak > /store/2a8-python/lib/python3.12/compileall.py
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2a8 /store/2a8-python )

View file

@ -0,0 +1,142 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH b0e42aafc01ece2ca2b42e3526f54bebc4b1f1dc8de6e34f46a0446a13e882b9
#> FROM https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.1/llvm-project-17.0.1.src.tar.xz
set -uex
export PATH='/store/1-stage1/protobusybox/bin/'
export PATH="$PATH:/store/2a0-static-gnumake/wrappers"
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a5-gnugcc10/bin"
export PATH="$PATH:/store/2a7-cmake/bin"
export PATH="$PATH:/store/2a8-python/bin"
export SHELL=/store/1-stage1/protobusybox/bin/ash
GCC_PATH=/store/2a5-gnugcc10
mkdir -p /tmp/2a9-intermediate-clang; cd /tmp/2a9-intermediate-clang
# clang's cmake configuration should pick up ccache automatically from PATH
#if [ -e /ccache/setup ]; then . /ccache/setup; fi
export PATH="$PATH:/ccache/bin"
command -v ccache && USE_CCACHE=YES || USE_CCACHE=NO
echo "### $0: preparing future sysroot..."
OUT=/store/2a9-intermediate-clang
SYSROOT=$OUT/sysroot
mkdir -p $SYSROOT/lib $SYSROOT/include
ln -s /store/2a3-intermediate-musl/lib/* $SYSROOT/lib/
ln -s /store/2a3-intermediate-musl/include/* $SYSROOT/include/
echo "### $0: unpacking LLVM/Clang sources..."
tar --strip-components=1 -xf /downloads/llvm-project-17.0.1.src.tar.xz
echo "### $0: fixing up LLVM/Clang sources..."
sed -i "s|COMMAND sh|COMMAND $SHELL|" \
llvm/cmake/modules/GetHostTriple.cmake clang/CMakeLists.txt
echo 'echo x86_64-unknown-linux-musl' > llvm/cmake/config.guess
LOADER=/store/2a3-intermediate-musl/lib/libc.so
sed -i "s|/lib/ld-musl-\" + ArchName + \".so.1|$LOADER|" \
clang/lib/Driver/ToolChains/Linux.cpp
BEGINEND='const bool HasCRTBeginEndFiles'
sed -i "s|${BEGINEND} =|${BEGINEND} = false; ${BEGINEND}_unused =|" \
clang/lib/Driver/ToolChains/Gnu.cpp
REL_ORIGIN='_install_rpath \"\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}\"'
sed -i "s|_install_rpath \"\\\\\$ORIGIN/..|_install_rpath \"$OUT|" \
llvm/cmake/modules/AddLLVM.cmake
sed -i 's|numShards = 32;|numShards = 1;|' lld/*/SyntheticSections.*
sed -i 's|numShards = 256;|numShards = 1;|' lld/*/ICF.cpp
sed -i 's|__FILE__|"__FILE__"|' compiler-rt/lib/builtins/int_util.h
sed -i 's|"@LLVM_SRC_ROOT@"|"REDACTED"|' \
llvm/tools/llvm-config/BuildVariables.inc.in
sed -i 's|"@LLVM_OBJ_ROOT@"|"REDACTED"|' \
llvm/tools/llvm-config/BuildVariables.inc.in
echo "### $0: building LLVM/Clang (stage 1)..."
export LD_LIBRARY_PATH='/store/2a5-gnugcc10/lib'
EXTRA_INCL='/tmp/2a9-intermediate-clang/extra_includes'
mkdir -p $EXTRA_INCL
cp clang/lib/Headers/*intrin*.h $EXTRA_INCL/
cp clang/lib/Headers/mm_malloc.h $EXTRA_INCL/
[ -e $EXTRA_INCL/immintrin.h ]
BOTH_STAGES_OPTS=''
add_opt() {
BOTH_STAGES_OPTS="$BOTH_STAGES_OPTS -D$1 -DBOOTSTRAP_$1"
}
add_opt CMAKE_BUILD_TYPE=MinSizeRel
add_opt LLVM_OPTIMIZED_TABLEGEN=YES
add_opt LLVM_CCACHE_BUILD=$USE_CCACHE
add_opt DEFAULT_SYSROOT=$SYSROOT
add_opt CMAKE_INSTALL_PREFIX=$OUT
add_opt LLVM_INSTALL_BINUTILS_SYMLINKS=YES
add_opt LLVM_INSTALL_CCTOOLS_SYMLINKS=YES
add_opt CMAKE_INSTALL_DO_STRIP=YES
add_opt LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=YES
add_opt LLVM_TARGET_ARCH=X86
add_opt LLVM_TARGETS_TO_BUILD=Native
add_opt LLVM_BUILTIN_TARGETS=x86_64-unknown-linux-musl
add_opt LLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-musl
add_opt LLVM_HOST_TRIPLE=x86_64-unknown-linux-musl
add_opt COMPILER_RT_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-musl
add_opt LLVM_APPEND_VC_REV=NO
add_opt LLVM_INCLUDE_TESTS=NO
add_opt LLVM_INCLUDE_EXAMPLES=NO
add_opt LLVM_INCLUDE_BENCHMARKS=NO
add_opt LLVM_ENABLE_BACKTRACES=NO
add_opt LLVM_ENABLE_EH=YES
add_opt LLVM_ENABLE_RTTI=YES
add_opt CLANG_ENABLE_ARCMT=NO
add_opt CLANG_ENABLE_STATIC_ANALYZER=NO
add_opt COMPILER_RT_BUILD_SANITIZERS=NO
add_opt COMPILER_RT_BUILD_XRAY=NO
add_opt COMPILER_RT_BUILD_LIBFUZZER=NO
add_opt COMPILER_RT_BUILD_PROFILE=NO
add_opt COMPILER_RT_BUILD_MEMPROF=NO
add_opt COMPILER_RT_BUILD_ORC=NO
add_opt COMPILER_RT_USE_BUILTINS_LIBRARY=YES
add_opt CLANG_DEFAULT_CXX_STDLIB=libc++
add_opt CLANG_DEFAULT_LINKER=lld
add_opt CLANG_DEFAULT_RTLIB=compiler-rt
add_opt LIBCXX_HAS_MUSL_LIBC=YES
add_opt LIBCXX_USE_COMPILER_RT=YES
add_opt LIBCXX_INCLUDE_BENCHMARKS=NO
add_opt LIBCXX_CXX_ABI=libcxxabi
add_opt LIBCXX_ADDITIONAL_COMPILE_FLAGS=-I/store/2a6-linux-headers/include
add_opt LIBCXXABI_USE_COMPILER_RT=YES
add_opt LIBCXXABI_USE_LLVM_UNWINDER=YES
add_opt LLVM_INSTALL_TOOLCHAIN_ONLY=YES
add_opt LIBUNWIND_USE_COMPILER_RT=YES
add_opt LLVM_ENABLE_THREADS=NO
cmake -S llvm -B build -G 'Unix Makefiles' \
-DLLVM_ENABLE_PROJECTS='clang;lld' \
-DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind' \
-DGCC_INSTALL_PREFIX=$GCC_PATH \
-DCMAKE_C_FLAGS=--sysroot=$SYSROOT \
"-DBOOTSTRAP_CMAKE_C_FLAGS=-isystem $EXTRA_INCL" \
"-DBOOTSTRAP_CMAKE_CXX_FLAGS=-isystem $EXTRA_INCL" \
-DCLANG_ENABLE_BOOTSTRAP=YES $BOTH_STAGES_OPTS
make -C build -j $NPROC clang lld runtimes
echo "### $0: building LLVM/Clang (stage 2)..."
NEW_LIB_DIR="$(pwd)/build/lib/x86_64-unknown-linux-musl"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$NEW_LIB_DIR"
make -C build -j $NPROC stage2
echo "### $0: installing LLVM/Clang..."
make -C build -j $NPROC stage2-install
ln -s $OUT/lib/x86_64-unknown-linux-musl/* $OUT/lib/
echo "### $0: setting up generic names..."
mkdir $OUT/bin/generic-names
ln -s $OUT/bin/clang $OUT/bin/generic-names/cc
ln -s $OUT/bin/clang++ $OUT/bin/generic-names/c++
ln -s $OUT/bin/clang-cpp $OUT/bin/generic-names/cpp
echo "### $0: mixing new stuff into sysroot..."
ln -s $OUT/lib/* $OUT/sysroot/lib/
echo "### $0: NOT checking for build path leaks - see _2a9.test.sh"

36
06/recipes/2b0-musl.sh Executable file
View file

@ -0,0 +1,36 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH 7a35eae33d5372a7c0da1188de798726f68825513b7ae3ebe97aaaa52114f039
#> FROM http://musl.libc.org/releases/musl-1.2.4.tar.gz
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/2a0-static-gnumake/bin"
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a9-intermediate-clang/bin/generic-names"
mkdir -p /tmp/2b0-musl; cd /tmp/2b0-musl
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking musl sources..."
tar --strip-components=1 -xf /downloads/musl-1.2.4.tar.gz
echo "### $0: building musl..."
sed -i 's|/bin/sh|/store/1-stage1/protobusybox/bin/ash|' \
tools/*.sh \
# patch popen/system to search in PATH instead of hardcoding /bin/sh
sed -i 's|posix_spawn(&pid, "/bin/sh",|posix_spawnp(\&pid, "sh",|' \
src/stdio/popen.c src/process/system.c
# avoid absolute path references
sed -i 's/__FILE__/__FILE_NAME__/' include/assert.h
ash ./configure --prefix=/store/2b0-musl CFLAGS=-O2
make -j $NPROC
echo "### $0: installing musl..."
make -j $NPROC install
mkdir /store/2b0-musl/bin
ln -s /store/2b0-musl/lib/libc.so /store/2b0-musl/bin/ldd
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2b0 /store/2b0-musl )

153
06/recipes/2b1-clang.sh Executable file
View file

@ -0,0 +1,153 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH b0e42aafc01ece2ca2b42e3526f54bebc4b1f1dc8de6e34f46a0446a13e882b9
#> FROM https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.1/llvm-project-17.0.1.src.tar.xz
set -uex
export PATH='/store/1-stage1/protobusybox/bin/'
export PATH="$PATH:/store/2a0-static-gnumake/wrappers"
export PATH="$PATH:/store/2a7-cmake/bin"
export PATH="$PATH:/store/2a8-python/bin"
# 2a9-intermediate-clang intentionally not added to $PATH to prevent confusion
export SHELL=/store/1-stage1/protobusybox/bin/ash
PREV_CLANG=/store/2a9-intermediate-clang
mkdir -p /tmp/2b1-clang; cd /tmp/2b1-clang
# clang's cmake configuration should pick up ccache automatically from PATH
#if [ -e /ccache/setup ]; then . /ccache/setup; fi
export PATH="$PATH:/ccache/bin"
command -v ccache && USE_CCACHE=YES || USE_CCACHE=NO
echo "### $0: preparing future sysroot..."
OUT=/store/2b1-clang
SYSROOT=$OUT/sysroot
mkdir -p $SYSROOT/lib $SYSROOT/include
ln -s /store/2b0-musl/lib/* $SYSROOT/lib/
ln -s /store/2b0-musl/include/* $SYSROOT/include/
echo "### $0: unpacking LLVM/Clang sources..."
tar --strip-components=1 -xf /downloads/llvm-project-17.0.1.src.tar.xz
echo "### $0: fixing up LLVM/Clang sources..."
sed -i "s|COMMAND sh|COMMAND $SHELL|" \
llvm/cmake/modules/GetHostTriple.cmake clang/CMakeLists.txt
echo 'echo x86_64-unknown-linux-musl' > llvm/cmake/config.guess
LOADER=/store/2b0-musl/lib/libc.so
sed -i "s|/lib/ld-musl-\" + ArchName + \".so.1|$LOADER|" \
clang/lib/Driver/ToolChains/Linux.cpp
BEGINEND='const bool HasCRTBeginEndFiles'
sed -i "s|${BEGINEND} =|${BEGINEND} = false; ${BEGINEND}_unused =|" \
clang/lib/Driver/ToolChains/Gnu.cpp
REL_ORIGIN='_install_rpath \"\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}\"'
sed -i "s|_install_rpath \"\\\\\$ORIGIN/..|_install_rpath \"$OUT|" \
llvm/cmake/modules/AddLLVM.cmake
sed -i 's|numShards = 32;|numShards = 1;|' lld/*/SyntheticSections.*
sed -i 's|numShards = 256;|numShards = 1;|' lld/*/ICF.cpp
sed -i 's|__FILE__|__FILE_NAME__|' compiler-rt/lib/builtins/int_util.h
sed -i 's|"@LLVM_SRC_ROOT@"|"REDACTED"|' \
llvm/tools/llvm-config/BuildVariables.inc.in
sed -i 's|"@LLVM_OBJ_ROOT@"|"REDACTED"|' \
llvm/tools/llvm-config/BuildVariables.inc.in
echo "### $0: building LLVM/Clang..."
export LD_LIBRARY_PATH="/store/2b0-musl/lib:$PREV_CLANG/lib"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/tmp/2b1-clang/build/lib" # libLLVM
EXTRA_INCL='/tmp/2b1-clang/extra_includes'
mkdir -p $EXTRA_INCL
cp clang/lib/Headers/*intrin*.h $EXTRA_INCL/
cp clang/lib/Headers/mm_malloc.h $EXTRA_INCL/
[ -e $EXTRA_INCL/immintrin.h ]
OPTS=''
add_opt() {
OPTS="$OPTS -D$1"
}
add_opt CMAKE_BUILD_TYPE=Release
add_opt LLVM_OPTIMIZED_TABLEGEN=YES
add_opt LLVM_CCACHE_BUILD=$USE_CCACHE
add_opt DEFAULT_SYSROOT=$SYSROOT
add_opt CMAKE_INSTALL_PREFIX=$OUT
add_opt LLVM_INSTALL_BINUTILS_SYMLINKS=YES
add_opt LLVM_INSTALL_CCTOOLS_SYMLINKS=YES
add_opt CMAKE_INSTALL_DO_STRIP=YES
add_opt LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=YES
add_opt LLVM_TARGET_ARCH=X86
add_opt LLVM_TARGETS_TO_BUILD=Native
add_opt LLVM_BUILTIN_TARGETS=x86_64-unknown-linux-musl
add_opt LLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-musl
add_opt LLVM_HOST_TRIPLE=x86_64-unknown-linux-musl
add_opt COMPILER_RT_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-musl
add_opt LLVM_APPEND_VC_REV=NO
add_opt LLVM_INCLUDE_TESTS=NO
add_opt LLVM_INCLUDE_EXAMPLES=NO
add_opt LLVM_INCLUDE_BENCHMARKS=NO
add_opt LLVM_ENABLE_BACKTRACES=NO
add_opt LLVM_ENABLE_EH=YES
add_opt LLVM_ENABLE_RTTI=YES
add_opt CLANG_ENABLE_ARCMT=NO
add_opt CLANG_ENABLE_STATIC_ANALYZER=NO
add_opt COMPILER_RT_BUILD_SANITIZERS=NO
add_opt COMPILER_RT_BUILD_XRAY=NO
add_opt COMPILER_RT_BUILD_LIBFUZZER=NO
add_opt COMPILER_RT_BUILD_PROFILE=NO
add_opt COMPILER_RT_BUILD_MEMPROF=NO
add_opt COMPILER_RT_BUILD_ORC=NO
add_opt COMPILER_RT_USE_BUILTINS_LIBRARY=YES
add_opt CLANG_DEFAULT_CXX_STDLIB=libc++
add_opt CLANG_DEFAULT_LINKER=lld
add_opt CLANG_DEFAULT_RTLIB=compiler-rt
add_opt LIBCXX_HAS_MUSL_LIBC=YES
add_opt LIBCXX_USE_COMPILER_RT=YES
add_opt LIBCXX_INCLUDE_BENCHMARKS=NO
add_opt LIBCXX_CXX_ABI=libcxxabi
add_opt LIBCXXABI_USE_COMPILER_RT=YES
add_opt LIBCXXABI_USE_LLVM_UNWINDER=YES
add_opt LIBCXX_ADDITIONAL_COMPILE_FLAGS=-I/store/2a6-linux-headers/include
add_opt LLVM_INSTALL_TOOLCHAIN_ONLY=YES
add_opt LIBUNWIND_USE_COMPILER_RT=YES
add_opt LLVM_ENABLE_THREADS=NO
REWRITE="-ffile-prefix-map=$(pwd)=/builddir/"
CFLAGS="--sysroot=$SYSROOT -I$EXTRA_INCL $REWRITE"
LDFLAGS="-Wl,--dynamic-linker=$LOADER"
cmake -S llvm -B build -G 'Unix Makefiles' \
-DCMAKE_ASM_COMPILER=$PREV_CLANG/bin/clang \
-DCMAKE_C_COMPILER=$PREV_CLANG/bin/clang \
-DCMAKE_CXX_COMPILER=$PREV_CLANG/bin/clang++ \
-DLLVM_ENABLE_PROJECTS='clang;lld' \
-DLLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind' \
-DCMAKE_C_FLAGS="$CFLAGS" \
-DCMAKE_CXX_FLAGS="$CFLAGS" \
-DCMAKE_C_LINK_FLAGS="$LDFLAGS" \
-DCMAKE_CXX_LINK_FLAGS="$LDFLAGS" \
-DLLVM_BUILD_LLVM_DYLIB=YES \
-DLLVM_LINK_LLVM_DYLIB=YES \
-DCLANG_LINK_LLVM_DYLIB=YES \
$OPTS
make -C build -j $NPROC clang lld runtimes
echo "### $0: installing LLVM/Clang..."
make -C build -j $NPROC install/strip
ln -s $OUT/lib/x86_64-unknown-linux-musl/* $OUT/lib/
echo "### $0: setting up generic names..."
ln -s $OUT/bin/clang $OUT/bin/cc
ln -s $OUT/bin/clang++ $OUT/bin/c++
ln -s $OUT/bin/clang-cpp $OUT/bin/cpp
ln -s $OUT/bin/lld $OUT/bin/ld
echo "### $0: HACK making linux target work..."
# FIXME boost wants it at lib/clang/17/lib/linux/libclang_rt.builtins-x86_64.a
OUTLIB=$OUT/lib/clang/17/lib
ln -s $OUTLIB/x86_64-unknown-linux-musl $OUTLIB/linux
ln -s $OUTLIB/x86_64-unknown-linux-musl/libclang_rt.builtins.a \
$OUTLIB/x86_64-unknown-linux-musl/libclang_rt.builtins-x86_64.a
echo "### $0: mixing new stuff into sysroot..."
ln -s $OUT/lib/* $OUT/sysroot/lib/
echo "### $0: NOT checking for build path leaks - see _2b1.test.sh"

48
06/recipes/2b2-busybox.sh Executable file
View file

@ -0,0 +1,48 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH b8cc24c9574d809e7279c3be349795c5d5ceb6fdf19ca709f80cde50e47de314
#> FROM https://busybox.net/downloads/busybox-1.36.1.tar.bz2
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/2a0-static-gnumake/bin"
export PATH="$PATH:/store/2b1-clang/bin"
mkdir -p /tmp/2b2-busybox; cd /tmp/2b2-busybox
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: aliasing ash to sh..."
mkdir aliases; ln -s /store/1-stage1/protobusybox/bin/ash aliases/sh
export PATH="/tmp/2b2-busybox/aliases:$PATH"
echo "### $0: unpacking busybox sources..."
tar --strip-components=1 -xf /downloads/busybox-1.36.1.tar.bz2
echo "### $0: configuring busybox..."
BUSYBOX_FLAGS='CONFIG_SHELL=/store/1-stage1/protobusybox/bin/ash'
BUSYBOX_FLAGS="$BUSYBOX_FLAGS CC=cc HOSTCC=cc"
BUSYBOX_FLAGS="$BUSYBOX_FLAGS KCONFIG_NOTIMESTAMP=y"
BUSYBOX_CFLAGS='CFLAGS=-O2 -isystem /store/2a6-linux-headers/include'
echo -e '#!/store/1-stage1/protobusybox/bin/ash\nprintf 9999' \
> scripts/gcc-version.sh
sed -i 's|/bin/sh|/store/1-stage1/protobusybox/bin/ash|g' \
scripts/gen_build_files.sh \
scripts/mkconfigs scripts/embedded_scripts scripts/trylink \
scripts/generate_BUFSIZ.sh \
applets/usage_compressed applets/busybox.mkscripts applets/install.sh
make -j $NPROC $BUSYBOX_FLAGS "$BUSYBOX_CFLAGS" defconfig
sed -i 's|CONFIG_INSTALL_NO_USR=y|CONFIG_INSTALL_NO_USR=n|' .config
sed -i 's|CONFIG_FEATURE_COMPRESS_USAGE=y|CONFIG_FEATURE_COMPRESS_USAGE=n|' \
.config
echo "### $0: building busybox..."
make -j $NPROC $BUSYBOX_FLAGS "$BUSYBOX_CFLAGS" busybox busybox.links
sed -i 's|^/usr/s\?bin/|/bin/|' busybox.links
echo "### $0: installing busybox..."
make -j $NPROC $BUSYBOX_FLAGS "$BUSYBOX_CFLAGS" \
install CONFIG_PREFIX=/store/2b2-busybox
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2b2 /store/2b2-busybox )

45
06/recipes/2b3-gnumake.sh Executable file
View file

@ -0,0 +1,45 @@
#!/store/2b2-busybox/bin/ash
#> FETCH dd16fb1d67bfab79a72f5e8390735c49e3e8e70b4945a15ab1f81ddb78658fb3
#> FROM http://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2a0-static-gnumake/bin"
export PATH="$PATH:/store/2b1-clang/bin"
mkdir -p /tmp/2b3-gnumake; cd /tmp/2b3-gnumake
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking GNU Make sources..."
tar --strip-components=1 -xf /downloads/make-4.4.1.tar.gz
echo "### $0: fixing up GNU Make sources..."
# embrace chaos
shuffle_comment='\/\* Handle shuffle mode argument. \*\/'
shuffle_default='if (!shuffle_mode) shuffle_mode = xstrdup(\"random\");'
sed -i "s|$shuffle_comment|$shuffle_comment\n$shuffle_default|" src/main.c
grep 'if (!shuffle_mode) shuffle_mode = xstrdup("random");' src/main.c
echo "### $0: building GNU Make..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' build-aux/install-sh
ash ./configure \
CONFIG_SHELL=ash SHELL=ash MAKEINFO=true \
--build x86_64-linux \
--prefix=/store/2b3-gnumake \
--disable-dependency-tracking
make -j $NPROC CFLAGS=-O2
echo "### $0: installing GNU Make with itself to test it..."
./make -j $NPROC SHELL=ash install-strip
echo "### $0: creating a wrapper that respects \$SHELL..."
# FIXME: patch make to use getenv?
mkdir /store/2b3-gnumake/wrappers; cd /store/2b3-gnumake/wrappers
echo "#!/store/2b2-busybox/bin/ash" > make
echo "exec /store/2b3-gnumake/bin/make SHELL=\$SHELL \"\$@\"" \ >> make
chmod +x make
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2b3 /store/2b3-gnumake )

50
06/recipes/3a-boost.sh Executable file
View file

@ -0,0 +1,50 @@
#!/store/2b2-busybox/bin/ash
#> FETCH 6478edfe2f3305127cffe8caf73ea0176c53769f4bf1585be237eb30798c3b8e
#> FROM https://archives.boost.io/release/1.83.0/source/boost_1_83_0.tar.bz2
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
export LD_LIBRARY_PATH=/store/2b1-clang/lib
mkdir -p /tmp/3a-boost; cd /tmp/3a-boost
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: aliasing ash to sh..."
mkdir aliases; ln -s /store/2b2-busybox/bin/ash aliases/sh
export PATH="/tmp/3a-boost/aliases:$PATH"
echo "### $0: unpacking Boost sources..."
tar --strip-components=1 -xf /downloads/boost_1_83_0.tar.bz2
echo "### $0: patching up Boost sources..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' \
bootstrap.sh
sed -i 's|/usr/bin/env sh|/store/2b2-busybox/bin/ash|' \
tools/build/src/engine/build.sh
sed -i 's|/bin/sh|sh|' \
tools/build/src/engine/execunix.cpp \
boost/process/detail/posix/shell_path.hpp
EXTRA_INCL='/tmp/3a-boost/extra_includes'
mkdir -p $EXTRA_INCL
cp /store/2b1-clang/lib/clang/17/include/*intrin*.h $EXTRA_INCL/
cp /store/2b1-clang/lib/clang/17/include/mm_malloc.h $EXTRA_INCL/
cp /store/2b1-clang/lib/clang/17/include/unwind.h $EXTRA_INCL/
echo "### $0: building Boost..."
ash bootstrap.sh
./b2 -j $NPROC \
include=/store/2a6-linux-headers/include \
include=$EXTRA_INCL \
include=/store/2b1-clang/include/x86_64-unknown-linux-musl/c++/v1 \
--with-context --with-thread --with-system
echo "### $0: installing Boost..."
./b2 install --prefix=/store/3a-boost \
--with-context --with-thread --with-system
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-boost )

46
06/recipes/3a-brotli.sh Executable file
View file

@ -0,0 +1,46 @@
#!/store/2b2-busybox/bin/ash
#> FETCH f9e8d81d0405ba66d181529af42a3354f838c939095ff99930da6aa9cdf6fe46
#> FROM https://github.com/google/brotli/archive/refs/tags/v1.0.9.tar.gz
#> AS brotli-1.0.9.tar.gz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
mkdir -p /tmp/3a-brotli; cd /tmp/3a-brotli
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking brotli sources..."
tar --strip-components=1 -xf /downloads/brotli-1.0.9.tar.gz
echo "### $0: building brotli..."
ash configure --prefix=/store/3a-brotli --help #--disable-dependency-tracking
CFLAGS='-fPIC'
CFLAGS="$CFLAGS -DBROTLICOMMON_SHARED_COMPILATION"
CFLAGS="$CFLAGS -DBROTLI_SHARED_COMPILATION"
make -j $NPROC lib CFLAGS="$CFLAGS"
clang -shared bin/obj/c/common/*.o -o libbrotlicommon.so
clang -shared bin/obj/c/enc/*.o libbrotlicommon.so -o libbrotlienc.so
clang -shared bin/obj/c/dec/*.o libbrotlicommon.so -o libbrotlidec.so
echo "### $0: installing brotli..."
mkdir -p /store/3a-brotli/lib /store/3a-brotli/include
cp libbrotlicommon.so libbrotlienc.so libbrotlidec.so /store/3a-brotli/lib/
cp -r c/include/brotli /store/3a-brotli/include/
mkdir -p /store/3a-brotli/lib/pkgconfig
for l in common enc dec; do
sed < scripts/libbrotli${l}.pc.in \
-e 's|@PACKAGE_VERSION@|1.0.9|g' \
-e 's|@prefix@|/store/3a-brotli|g' \
-e 's|@exec_prefix@|/store/3a-brotli/bin|g' \
-e 's|@includedir@|/store/3a-brotli/include|g' \
-e 's|@libdir@|/store/3a-brotli/lib|g' \
-e 's|-R|-Wl,-rpath=|g' \
> /store/3a-brotli/lib/pkgconfig/libbrotli${l}.pc
done
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-brotli )

31
06/recipes/3a-curl.sh Executable file
View file

@ -0,0 +1,31 @@
#!/store/2b2-busybox/bin/ash
#> FETCH dd322f6bd0a20e6cebdfd388f69e98c3d183bed792cf4713c8a7ef498cba4894
#> FROM https://curl.se/download/curl-8.2.1.tar.xz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
export PATH="$PATH:/store/3a-pkg-config/bin"
mkdir -p /tmp/3a-curl; cd /tmp/3a-curl
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking curl sources..."
tar --strip-components=1 -xf /downloads/curl-8.2.1.tar.xz
echo "### $0: building curl..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' configure install-sh
ash configure --prefix=/store/3a-curl \
--with-mbedtls=/store/3a-mbedtls \
--disable-dependency-tracking
make -j $NPROC
echo "### $0: installing curl..."
make -j $NPROC install-strip
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-curl )

29
06/recipes/3a-editline.sh Executable file
View file

@ -0,0 +1,29 @@
#!/store/2b2-busybox/bin/ash
#> FETCH df223b3333a545fddbc67b49ded3d242c66fadf7a04beb3ada20957fcd1ffc0e
#> FROM https://github.com/troglobit/editline/releases/download/1.17.1/editline-1.17.1.tar.xz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
mkdir -p /tmp/3a-editline; cd /tmp/3a-editline
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking editline sources..."
tar --strip-components=1 -xf /downloads/editline-1.17.1.tar.xz
echo "### $0: fixing up editline sources..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' configure aux/install-sh
echo "### $0: building editline..."
ash configure --prefix=/store/3a-editline --disable-dependency-tracking
make -j $NPROC
echo "### $0: installing editline..."
make -j $NPROC install-strip
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-editline )

33
06/recipes/3a-gnugperf.sh Executable file
View file

@ -0,0 +1,33 @@
#!/store/2b2-busybox/bin/ash
#> FETCH 588546b945bba4b70b6a3a616e80b4ab466e3f33024a352fc2198112cdbb3ae2
#> FROM http://ftp.gnu.org/pub/gnu/gperf/gperf-3.1.tar.gz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
mkdir -p /tmp/3a-gnugperf; cd /tmp/3a-gnugperf
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking GNU gperf sources..."
tar --strip-components=1 -xf /downloads/gperf-3.1.tar.gz
echo "### $0: patching up GNU gperf sources..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' \
configure lib/configure src/configure tests/configure doc/configure \
Makefile.in src/Makefile.in doc/Makefile.in
echo "### $0: building GNU gperf..."
REWRITE="-ffile-prefix-map=$(pwd)=/builddir/"
ash configure --prefix=/store/3a-gnugperf \
CFLAGS=$REWRITE CXXFLAGS="$REWRITE -Wno-register"
make -j $NPROC
echo "### $0: installing GNU gperf..."
make -j $NPROC install
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-gnugperf )

33
06/recipes/3a-libarchive.sh Executable file
View file

@ -0,0 +1,33 @@
#!/store/2b2-busybox/bin/ash
#> FETCH b17403ce670ff18d8e06fea05a9ea9accf70678c88f1b9392a2e29b51127895f
#> FROM http://libarchive.org/downloads/libarchive-3.7.1.tar.xz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
export PATH="$PATH:/store/3a-pkg-config/bin"
mkdir -p /tmp/3a-libarchive; cd /tmp/3a-libarchive
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking libarchive sources..."
tar --strip-components=1 -xf /downloads/libarchive-3.7.1.tar.xz
echo "### $0: fixing up libarchive sources..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' \
configure build/autoconf/install-sh
echo "### $0: building libarchive..."
ash configure --prefix=/store/3a-libarchive \
--disable-dependency-tracking \
--without-openssl
make -j $NPROC
echo "### $0: installing libarchive..."
make -j $NPROC install-strip
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-libarchive )

34
06/recipes/3a-libsodium.sh Executable file
View file

@ -0,0 +1,34 @@
#!/store/2b2-busybox/bin/ash
#> FETCH 6f504490b342a4f8a4c4a02fc9b866cbef8622d5df4e5452b46be121e46636c1
#> FROM https://github.com/jedisct1/libsodium/releases/download/1.0.18-RELEASE/libsodium-1.0.18.tar.gz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
export PATH="$PATH:/store/3a-pkg-config/bin"
export PKG_CONFIG_PATH='/store/3a-openssl/lib64/pkgconfig'
mkdir -p /tmp/3a-libsodium; cd /tmp/3a-libsodium
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking libsodium sources..."
tar --strip-components=1 -xf /downloads/libsodium-1.0.18.tar.gz
echo "### $0: fixing up libsodium sources..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' \
configure build-aux/install-sh
echo "### $0: building libsodium..."
ash configure --prefix=/store/3a-libsodium \
--disable-dependency-tracking
make -j $NPROC
echo "### $0: installing libsodium..."
make -j $NPROC install-strip
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-libsodium )

33
06/recipes/3a-lowdown.sh Executable file
View file

@ -0,0 +1,33 @@
#!/store/2b2-busybox/bin/ash
#> FETCH 049b7883874f8a8e528dc7c4ed7b27cf7ceeb9ecf8fe71c3a8d51d574fddf84b
#> FROM https://github.com/kristapsdz/lowdown/archive/refs/tags/VERSION_1_0_2.tar.gz
#> AS lowdown-1.0.2.tar.gz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/wrappers"
export PATH="$PATH:/store/3a-pkg-config/bin"
export PKG_CONFIG_PATH='/store/3a-openssl/lib64/pkgconfig'
export SHELL='/store/2b2-busybox/bin/ash'
mkdir -p /tmp/3a-lowdown; cd /tmp/3a-lowdown
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking lowdown sources..."
tar --strip-components=1 -xf /downloads/lowdown-1.0.2.tar.gz
echo "### $0: fixing up lowdown sources..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' configure
echo "### $0: building lowdown..."
ash configure PREFIX=/store/3a-lowdown
make -j $NPROC CFLAGS=-ffile-prefix-map=$(pwd)=/builddir/
echo "### $0: installing lowdown..."
make -j $NPROC install_shared
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-lowdown )

32
06/recipes/3a-mbedtls.sh Executable file
View file

@ -0,0 +1,32 @@
#!/store/2b2-busybox/bin/ash
#> FETCH a420fcf7103e54e775c383e3751729b8fb2dcd087f6165befd13f28315f754f5
#> FROM https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v3.4.1.tar.gz
#> AS mbedtls-3.4.1.tar.gz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/wrappers"
export SHELL=/store/2b2-busybox/bin/ash
mkdir -p /tmp/3a-mbedtls; cd /tmp/3a-mbedtls
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking mbedtls sources..."
tar --strip-components=1 -xf /downloads/mbedtls-3.4.1.tar.gz
echo "### $0: fixing up mbedtls sources..."
sed -i 's|^DESTDIR=.*|DESTDIR=/store/3a-mbedtls|' Makefile
sed -i 's|programs: lib mbedtls_test|programs: lib|' Makefile
sed -i 's|install: no_test|install: lib|' Makefile
echo "### $0: building mbedtls..."
make -j $NPROC lib
echo "### $0: installing mbedtls..."
make -j $NPROC install
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-mbedtls )

29
06/recipes/3a-nlohmann-json.sh Executable file
View file

@ -0,0 +1,29 @@
#!/store/2b2-busybox/bin/ash
#> FETCH 8c4b26bf4b422252e13f332bc5e388ec0ab5c3443d24399acb675e68278d341f
#> FROM https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz
#> AS nlohmann-json-3.11.2.tar.xz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
mkdir -p /tmp/3a-nlohmann-json; cd /tmp/3a-nlohmann-json
echo "### $0: unpacking nlohmann-json sources..."
tar --strip-components=1 -xf /downloads/nlohmann-json-3.11.2.tar.xz
echo "### $0: installing nlohmann-json..."
mkdir /store/3a-nlohmann-json
cp -rv include /store/3a-nlohmann-json
mkdir -p /store/3a-nlohmann-json/lib/pkgconfig
sed < cmake/pkg-config.pc.in \
-e 's|${PROJECT_NAME}|nlohmann_json|' \
-e 's|${PROJECT_VERSION}|3.11.2|' \
-e 's|${CMAKE_INSTALL_FULL_INCLUDEDIR}|/store/3a-nlohmann-json/include|' \
> /store/3a-nlohmann-json/lib/pkgconfig/nlohmann_json.pc
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-nlohmann-json )

32
06/recipes/3a-pkg-config.sh Executable file
View file

@ -0,0 +1,32 @@
#!/store/2b2-busybox/bin/ash
#> FETCH 6fc69c01688c9458a57eb9a1664c9aba372ccda420a02bf4429fe610e7e7d591
#> FROM https://pkgconfig.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
mkdir -p /tmp/3a-pkg-config; cd /tmp/3a-pkg-config
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking pkg-config sources..."
tar --strip-components=1 -xf /downloads/pkg-config-0.29.2.tar.gz
echo "### $0: patching pkg-config..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' \
configure glib/configure \
install-sh glib/install-sh
echo "### $0: building pkg-config..."
ash configure --prefix=/store/3a-pkg-config --with-internal-glib \
CFLAGS=-Wno-int-conversion
make -j $NPROC
echo "### $0: installing pkg-config..."
make -j $NPROC install-strip
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-pkg-config )

31
06/recipes/3a-seccomp.sh Executable file
View file

@ -0,0 +1,31 @@
#!/store/2b2-busybox/bin/ash
#> FETCH d82902400405cf0068574ef3dc1fe5f5926207543ba1ae6f8e7a1576351dcbdb
#> FROM https://github.com/seccomp/libseccomp/releases/download/v2.5.4/libseccomp-2.5.4.tar.gz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
export PATH="$PATH:/store/3a-gnugperf/bin"
mkdir -p /tmp/3a-seccomp; cd /tmp/3a-seccomp
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking seccomp sources..."
tar --strip-components=1 -xf /downloads/libseccomp-2.5.4.tar.gz
echo "### $0: patching up seccomp sources..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' configure build-aux/install-sh
echo "### $0: building seccomp..."
ash configure --prefix=/store/3a-seccomp --disable-dependency-tracking \
CFLAGS=-I/store/2a6-linux-headers/include
make -j $NPROC
echo "### $0: installing seccomp..."
make -j $NPROC install-strip
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-seccomp )

28
06/recipes/3a-sqlite.sh Executable file
View file

@ -0,0 +1,28 @@
#!/store/2b2-busybox/bin/ash
#> FETCH 49008dbf3afc04d4edc8ecfc34e4ead196973034293c997adad2f63f01762ae1
#> FROM https://sqlite.org/2023/sqlite-autoconf-3430000.tar.gz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"
mkdir -p /tmp/3a-sqlite; cd /tmp/3a-sqlite
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking SQLite archive..."
tar --strip-components=1 -xf /downloads/sqlite-autoconf-3430000.tar.gz
echo "### $0: building SQLite..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' configure install-sh
ash configure --prefix=/store/3a-sqlite
make -j $NPROC
echo "### $0: installing SQLite..."
make -j $NPROC install-strip
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3a /store/3a-sqlite )

49
06/recipes/3b-busybox-static.sh Executable file
View file

@ -0,0 +1,49 @@
#!/store/2b2-busybox/bin/ash
#> FETCH b8cc24c9574d809e7279c3be349795c5d5ceb6fdf19ca709f80cde50e47de314
#> FROM https://busybox.net/downloads/busybox-1.36.1.tar.bz2
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/wrappers"
mkdir -p /tmp/3b-busybox-static; cd /tmp/3b-busybox-static
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: aliasing ash to sh..."
mkdir aliases; ln -s /store/2b2-busybox/bin/ash aliases/sh
export PATH="/tmp/3b-busybox-static/aliases:$PATH"
echo "### $0: unpacking busybox sources..."
tar --strip-components=1 -xf /downloads/busybox-1.36.1.tar.bz2
echo "### $0: configuring busybox..."
BUSYBOX_FLAGS='CONFIG_SHELL=/store/2b2-busybox/bin/ash'
BUSYBOX_FLAGS='SHELL=/store/2b2-busybox/bin/ash'
BUSYBOX_FLAGS="$BUSYBOX_FLAGS CC=cc HOSTCC=cc"
BUSYBOX_FLAGS="$BUSYBOX_FLAGS KCONFIG_NOTIMESTAMP=y"
BUSYBOX_CFLAGS='CFLAGS=-O2 -isystem /store/2a6-linux-headers/include'
echo -e '#!/store/2b2-busybox/bin/ash\nprintf 9999' \
> scripts/gcc-version.sh
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|g' \
scripts/gen_build_files.sh \
scripts/mkconfigs scripts/embedded_scripts scripts/trylink \
scripts/generate_BUFSIZ.sh \
applets/usage_compressed applets/busybox.mkscripts applets/install.sh
make -j $NPROC $BUSYBOX_FLAGS defconfig
sed -i 's|CONFIG_INSTALL_NO_USR=y|CONFIG_INSTALL_NO_USR=n|' .config
sed -i 's|CONFIG_FEATURE_SHARED_BUSYBOX=y|CONFIG_FEATURE_SHARED_BUSYBOX=n|' \
.config
echo "### $0: building busybox..."
make -j $NPROC $BUSYBOX_FLAGS "$BUSYBOX_CFLAGS" busybox busybox.links
sed -i 's|^/usr/s\?bin/|/bin/|' busybox.links
echo "### $0: installing busybox..."
make -j $NPROC $BUSYBOX_FLAGS "$BUSYBOX_CFLAGS" \
install CONFIG_PREFIX=/store/3b-busybox-static
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3b /store/3b-busybox-static )

100
06/recipes/3b-nix.sh Executable file
View file

@ -0,0 +1,100 @@
#!/store/2b2-busybox/bin/ash
#> FETCH f3f8016621cf3971e0768404f05b89d4a7fc1911dddae5a9a7ed4bf62519302c
#> FROM https://github.com/ZilchOS/nix/releases/download/nix-2.17.0-zilched/nix-2.17.0-zilched.tar.xz
#> FETCH 3659cd137c320991a78413dd370a92fd18e0a8bc36d017d554f08677a37d7d5a
#> FROM https://raw.githubusercontent.com/somasis/musl-compat/c12ea3af4e6ee53158a175d992049c2148db5ff6/include/sys/queue.h
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/wrappers"
export PATH="$PATH:/store/3a-pkg-config/bin"
export PATH="$PATH:/store/3a-lowdown/bin"
export SHELL='/store/2b2-busybox/bin/ash'
#export PKG_CONFIG_PATH='/store/3a-openssl/lib64/pkgconfig'
export PKG_CONFIG_PATH=''
#export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-bzip2/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-sqlite/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-curl/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-editline/lib/pkgconfig"
#export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-xz/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-brotli/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-seccomp/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-libarchive/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-libsodium/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-lowdown/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-nlohmann-json/lib/pkgconfig"
#LIBDIRS="$(pkg-config --variable=libdir openssl)"
LIBDIRS=""
#LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir bzip2)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir sqlite3)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libeditline)"
#LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir liblzma)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libbrotlicommon)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libseccomp)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libarchive)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libsodium)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir lowdown)"
export LD_LIBRARY_PATH=$LIBDIRS
export BOOST_ROOT=/store/3a-boost/include
mkdir -p /tmp/3b-nix; cd /tmp/3b-nix
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking Nix sources..."
tar --strip-components=1 \
-xf /downloads/nix-2.17.0-zilched.tar.xz
echo "### $0: copying queue.h..."
mkdir -p compat-includes/sys
cp /downloads/queue.h compat-includes/sys/
echo "### $0: stubbing out commands..."
mkdir stubs; export PATH="$(pwd)/stubs:$PATH"
ln -s /store/2b2-busybox/bin/true stubs/jq
ln -s /store/2b2-busybox/bin/true stubs/expr
ln -s /store/2b2-busybox/bin/ash stubs/bash
echo "### $0: patching up Nix sources..."
sed -i 's|/bin/sh|/store/2b2-busybox/bin/ash|' configure
sed -i 's|/bin/sh|${stdenv.busybox}/bin/ash|' configure
# avoid an expression confusing ash
nl configure | grep 7217 | tee configure-problematic-line
grep -F "'X\(//\)$'" configure-problematic-line
sed -i '7217d' configure
nl configure | grep 7217 | tee configure-problematic-line
! grep -F "'X\(//\)$'" configure-problematic-line
# replace the declare confusing ash
sed -i 's|declare \$name=.*|:|' configure
echo "### $0: building Nix..."
PCDEPS='libbrotlicommon libbrotlienc libbrotlidec sqlite3 libseccomp lowdown'
PCDEPS="$PCDEPS nlohmann_json"
INC="-I/store/2a6-linux-headers/include -I$(pwd)/compat-includes"
REWRITE="-ffile-prefix-map=$(pwd)=/builddir/"
export CFLAGS="$(pkg-config --cflags $PCDEPS) $INC $REWRITE"
export CXXFLAGS="$CFLAGS"
export GLOBAL_CXXFLAGS="$CFLAGS"
export LDFLAGS="$(pkg-config --libs $PCDEPS) -L/store/3a-boost/lib -v"
ash configure --prefix=/store/3b-nix \
--with-boost=$BOOST_ROOT \
--disable-doc-gen \
--disable-gc \
--disable-cpuid \
--disable-gtest \
--with-sandbox-shell=/store/3b-busybox-static/bin/busybox
sed -i "s|\${prefix}|/store/3b-nix|g" config.status
sed -i "s|\${exec_prefix}|/store/3b-nix|g" config.status
make -j $NPROC V=1
echo "### $0: installing Nix..."
make -j $NPROC install
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3b /store/3b-nix )

42
06/recipes/3b-tinycc-static.sh Executable file
View file

@ -0,0 +1,42 @@
#!/store/2b2-busybox/bin/ash
#> FETCH f5a71d05664340ae46cda9579c6079a0f2fa809d24386d284f0d091e4d576a4e
#> FROM https://github.com/TinyCC/tinycc/archive/af1abf1f45d45b34f0b02437f559f4dfdba7d23c.tar.gz
#> AS tinycc-mob-af1abf1.tar.gz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/wrappers"
export SHELL="/store/2b2-busybox/bin/ash"
mkdir -p /tmp/3b-tinycc-static; cd /tmp/3b-tinycc-static
if [ -e /ccache/setup ]; then . /ccache/setup; fi
echo "### $0: unpacking TinyCC sources..."
tar --strip-components=1 -xf /downloads/tinycc-mob-af1abf1.tar.gz
#echo "### $0: fixing up TinyCC sources..."
sed -i "s|^VERSION = .*|VERSION = mob-af1abf1|" configure
sed -i "s|^GITHASH := .*|GITHASH = mob:af1abf1|" configure
echo "### $0: configuring TinyCC..."
$SHELL configure \
--prefix=/store/3b-tinycc-static \
--cc=cc \
--extra-cflags="-O3 -static" \
--extra-ldflags="-static" \
--enable-static \
--config-musl
echo "### $0: building TinyCC..."
make -j $NPROC tcc
echo "### $0: installing TinyCC..."
mkdir -p /store/3b-tinycc-static/bin
cp tcc /store/3b-tinycc-static/bin/
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/3b /store/3b-tinycc-static )

14
06/recipes/3b-zig.sh Normal file
View file

@ -0,0 +1,14 @@
#!/store/2b2-busybox/bin/ash
#> FETCH
#> FROM https://github.com/ziglang/zig-bootstrap/archive/refs/tags/0.14.0.tar.gz
#> AS zig-bootstrap-0.14.0.tar.gz
mkdir -p /tmp/3a-zig; cd /tmp/3a-zig
echo "### $0: unpacking zig-boostrap sources..."
tar --strip-components=1 -xf /downloads/zig-bootstrap-0.14.0.tar.gz
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/2b1-clang/bin"
export PATH="$PATH:/store/2b3-gnumake/bin"

View file

@ -0,0 +1,98 @@
#!/store/2b2-busybox/bin/ash
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/3a-pkg-config/bin"
export PATH="$PATH:/store/3a-sqlite/bin"
export PATH="$PATH:/store/3b-nix/bin"
export SHELL='/store/2b2-busybox/bin/ash'
export PKG_CONFIG_PATH=''
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-sqlite/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-curl/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-editline/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-seccomp/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-libarchive/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-libsodium/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-lowdown/lib/pkgconfig"
LIBDIRS=''
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir sqlite3)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libcurl)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libeditline)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libseccomp)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libarchive)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libsodium)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir lowdown)"
LIBDIRS="$LIBDIRS:/store/3a-boost/lib"
LIBDIRS="$LIBDIRS:/store/2b1-clang/lib"
export LD_LIBRARY_PATH=$LIBDIRS
mkdir -p /tmp/4-rebootstrap-using-nix; cd /tmp/4-rebootstrap-using-nix
echo "### $0: preparing stuff for nix to work..."
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
ln -s /dev/pts/ptmx /dev/ptmx
echo "### $0: faking lots of stuff for nix to work..."
mkdir shelter
export HOME=/tmp/4-rebootstrap-using-nix/shelter
export USER=notauser
echo 'oh come on' >/dev/urandom
echo "### $0: fixing up paths to shell..."
cp -a --reflink=auto /using-nix /default.nix /recipes ./
sed -i 's|/bin/sh|/store/3b-busybox-static/bin/ash|' using-nix/1-stage1.nix
echo "### $0: pointing to local downloads..."
sed -i 's| url =| #remote_url =|' using-nix/*.nix
sed -i 's|# local = \(.*\);|url = "file://\1";|' using-nix/*.nix
if [ -e /prev/nix/store ] && [ -e /prev/nix-db.tar ]; then
echo "### $0: restoring nix store & db from previous build..."
mkdir -p /nix
cp -a --reflink=auto /prev/nix/store /nix
tar -xf /prev/nix-db.tar -C /
sqlite3 /nix/var/nix/db/db.sqlite \
< /nix/var/nix/db/db.sqlite.dump
rm /nix/var/nix/db/db.sqlite.dump
fi
echo "### $0: writing a 0.nix that simply injects what we've built..."
# Makefile bootstrap injects it as /stage/protosrc, regular --- as /protosrc
[ -e /protosrc ] && PROTOSRC="/protosrc" || PROTOSRC=/stage/protosrc
echo "{ tinycc = /store/3b-tinycc-static/bin/tcc; protosrc = $PROTOSRC; }" \
> using-nix/0.nix
echo "### $0: rebuilding everything using nix..."
nix-build \
--extra-experimental-features ca-derivations \
--option build-users-group '' \
--option compress-build-log false \
--no-substitute \
--cores $NPROC \
--keep-failed \
-vvv \
default.nix
rm -f /dev/urandom
rm /dev/ptmx
umount /dev/pts
umount /dev/pts || true
rm -r /dev/pts
rm -r shelter
rm -rf /build
# this one is special wrt how the results are saved, see Makefile/USE_NIX_CACHE
echo "### $0: exporting resulting /nix/store (reproducible)..."
mkdir -p /store/4-rebootstrap-using-nix/nix
cp -a --reflink=auto /nix/store /store/4-rebootstrap-using-nix/nix/
echo "### $0: exporting /nix/var/nix/db to restore it (non-reproducible)..."
cp /nix/var/nix/db/db.sqlite db.sqlite
sqlite3 db.sqlite 'UPDATE ValidPaths SET registrationTime = 1;'
sqlite3 db.sqlite .dump > /nix/var/nix/db/db.sqlite.dump
tar --exclude nix/var/nix/db/db.sqlite \
-cf /store/4-rebootstrap-using-nix/nix-db.tar /nix/var/nix/db
rm /nix/var/nix/db/db.sqlite.dump

View file

@ -0,0 +1,203 @@
#!/store/2b2-busybox/bin/ash
#> FETCH 10fa524294f58c805411ddd6e5522c02a0b69ad14e036b141cc80fb53a3ef1a0
#> FROM https://github.com/ZilchOS/core/archive/2023.10.1.tar.gz
#> AS ZilchOS-core-2023.10.1.tar.gz
#> FETCH ddd417f9caab3ef0f3031b938815a5c33367c3a50c09830138d208bd3126c98f
#> FROM https://github.com/limine-bootloader/limine/releases/download/v5.20230830.0/limine-5.20230830.0.tar.xz
#> FETCH 1952b2a782ba576279c211ee942e341748fdb44997f704dd53def46cd055470b
#> FROM https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0.tar.bz2
#> FETCH 9bba0214ccf7f1079c5d59210045227bcf619519840ebfa80cd3849cff5a5bf2
#> FROM https://ftp.gnu.org/gnu/bison/bison-3.8.2.tar.xz
#> FETCH 63aede5c6d33b6d9b13511cd0be2cac046f2e70fd0a07aa9573a04a82783af96
#> FROM https://ftp.gnu.org/gnu/m4/m4-1.4.19.tar.xz
#> FETCH e87aae032bf07c26f85ac0ed3250998c37621d95f8bd748b31f15b33c45ee995
#> FROM https://github.com/westes/flex/files/981163/flex-2.6.4.tar.gz
#> FETCH 541e179665dc4e272b9602f2074243591a157da89cc47064da8c5829dbd2b339
#> FROM http://ftp.gnu.org/gnu/mtools/mtools-4.0.43.tar.bz2
#> FETCH 786f9f5df9865cc5b0c1fecee3d2c0f5e04cab8c9a859bd1c9c7ccd4964fdae1
#> FROM https://www.gnu.org/software/xorriso/xorriso-1.5.6.pl02.tar.gz
#> FETCH 9c4396cc829cfae319a6e2615202e82aad41372073482fce286fac78646d3ee4
#> FROM https://github.com/facebook/zstd/releases/download/v1.5.5/zstd-1.5.5.tar.gz
#> FETCH 23c2469e2a568362a62eecf1b49ed90a15621e6fa30e29947ded3436422de9b9
#> FROM https://curl.se/ca/cacert-2023-08-22.pem
#> FETCH 85cd12e9cf1d6d5a45f17f7afe1cebe7ee628d3282281c492e86adf636defa3f
#> FROM https://www.python.org/ftp/python/3.11.5/Python-3.11.5.tar.xz
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/3a-pkg-config/bin"
export PATH="$PATH:/store/3a-sqlite/bin"
export PATH="$PATH:/store/3b-nix/bin"
export SHELL='/store/2b2-busybox/bin/ash'
export PKG_CONFIG_PATH=''
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-sqlite/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-curl/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-editline/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-seccomp/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-libarchive/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-libsodium/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-lowdown/lib/pkgconfig"
LIBDIRS=''
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir sqlite3)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libcurl)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libeditline)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libseccomp)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libarchive)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libsodium)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir lowdown)"
LIBDIRS="$LIBDIRS:/store/3a-boost/lib"
LIBDIRS="$LIBDIRS:/store/2b1-clang/lib"
export LD_LIBRARY_PATH=$LIBDIRS
mkdir -p /tmp/5-go-beyond-using-nix; cd /tmp/5-go-beyond-using-nix
echo "### $0: preparing stuff for nix to work..."
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
ln -s /dev/pts/ptmx /dev/ptmx
echo "### $0: faking lots of stuff for nix to work..."
mkdir shelter
export HOME=/tmp/5-go-beyond-using-nix/shelter
export USER=notauser
echo 'oh come on' >/dev/urandom
printf '\0\0\0\0\0\0\0\0\0\0' > 10x0
cat 10x0 10x0 10x0 10x0 10x0 10x0 10x0 10x0 10x0 10x0 > 100x0
cat 100x0 100x0 100x0 100x0 100x0 100x0 100x0 100x0 100x0 100x0 > 1Kx0
cat 1Kx0 1Kx0 1Kx0 1Kx0 1Kx0 1Kx0 1Kx0 1Kx0 1Kx0 1Kx0 > 10Kx0
cat 10Kx0 10Kx0 10Kx0 10Kx0 10Kx0 10Kx0 10Kx0 10Kx0 10Kx0 10Kx0 > 100Kx0
cat 100Kx0 100Kx0 100Kx0 100Kx0 100Kx0 100Kx0 100Kx0 100Kx0 100Kx0 100Kx0 \
> 1Mx0
cat 1Mx0 1Mx0 1Mx0 1Mx0 1Mx0 1Mx0 1Mx0 1Mx0 1Mx0 1Mx0 > 10Mx0
mv 10Mx0 /dev/zero
rm *x0
echo "### $0: fixing up paths to shell..."
sed -i 's|/bin/sh|/store/3b-busybox-static/bin/ash|' /using-nix/1-stage1.nix
if [ -e /prev/nix/store ] && [ -e /prev/nix-db.tar ]; then
echo "### $0: restoring nix store & db from previous build..."
mkdir -p /nix
mv /prev/nix/store /nix
tar -xf /prev/nix-db.tar -C /
sqlite3 /nix/var/nix/db/db.sqlite \
< /nix/var/nix/db/db.sqlite.dump
rm /nix/var/nix/db/db.sqlite.dump
elif [ ! -e /nix/store ]; then
echo "### $0: restoring nix store & db from previous stage..."
mkdir -p /nix
cp -a /store/4-rebootstrap-using-nix/nix/store /nix/
tar -xf /store/4-rebootstrap-using-nix/nix-db.tar -C /
sqlite3 /nix/var/nix/db/db.sqlite \
< /nix/var/nix/db/db.sqlite.dump
rm /nix/var/nix/db/db.sqlite.dump
fi
echo "### $0: creating a ZilchOS/bootstrap flake..."
mkdir ZilchOS-bootstrap
cp -r /flake.nix /default.nix /using-nix /recipes \
ZilchOS-bootstrap/
echo "### $0: pointing to local files..."
sed -i 's| url =| #remote_url =|' ZilchOS-bootstrap/using-nix/*.nix
sed -i 's|# local = \(.*\);|url = "file://\1";|' ZilchOS-bootstrap/using-nix/*.nix
echo "### $0: writing a 0.nix that simply injects what we've built..."
# Makefile bootstrap injects it as /stage/protosrc, regular --- as /protosrc
[ -e /protosrc ] && PROTOSRC="/protosrc" || PROTOSRC=/stage/protosrc
echo "{ tinycc = /store/3b-tinycc-static/bin/tcc; protosrc = $PROTOSRC; }" \
> ZilchOS-bootstrap/using-nix/0.nix
if [[ ! -e ZilchOS-core ]]; then
echo "### $0: unpacking ZilchOS/core archive..."
mkdir ZilchOS-core
tar -xf /downloads/ZilchOS-core-2023.10.1.tar.gz --strip-components=1 \
-C ZilchOS-core
fi
[[ -e ZilchOS-core/flake.nix ]]
cd ZilchOS-core
nix flake lock \
--extra-experimental-features 'ca-derivations flakes nix-command' \
--update-input bootstrap-from-tcc \
--override-input bootstrap-from-tcc path:../ZilchOS-bootstrap
pwd
cd ..
ls -l ZilchOS-core
echo "### $0: pointing to local downloads..."
sed -i 's| url =| #remote_url =|' \
ZilchOS-core/*/*.nix ZilchOS-core/*/*/*.nix
sed -i 's|# local = \(.*\);|url = "file://\1";|' \
ZilchOS-core/*/*.nix ZilchOS-core/*/*/*.nix
if [ -e /ccache/setup ]; then
echo "### $0: configuring ccache..."
export CCACHE_COMPILERCHECK=content
export CCACHE_SLOPPINESS=include_file_ctime,include_file_mtime
export CCACHE_MAXSIZE=0
export CCACHE_DIR=/ccache
MAYBE_CCACHE='ccachedPackages.'
else
MAYBE_CCACHE=''
fi
echo "### $0: building ZilchOS/core using nix..."
mkdir -p /store/5-go-beyond-using-nix
: > /store/5-go-beyond-using-nix/hashes
while IFS=' ' read -r _unused_old_hash pkg; do
# can't have sandbox, need deterministic build paths
nix build \
--extra-experimental-features 'ca-derivations flakes nix-command' \
--option build-users-group '' \
--option compress-build-log false \
--no-substitute \
--cores $NPROC \
--keep-failed \
--show-trace \
-L \
-vvv \
-o .tmp \
"./ZilchOS-core#${MAYBE_CCACHE}${pkg}"
new_path=$(readlink .tmp*)
new_hash=$(echo $new_path | sed -E 's|.*/([a-z0-9]{32})-.*|\1|')
if [ "$pkg" != 'live-cd^iso' ]; then rm .tmp*; fi
echo "$new_hash $pkg" >> /store/5-go-beyond-using-nix/hashes
done < ./ZilchOS-core/.maint/hashes
sha256sum .tmp*-iso # the last one is the iso
rm -f /dev/urandom
rm -f /dev/zero
rm /dev/ptmx
umount /dev/pts
umount /dev/pts || true
rm -r /dev/pts
rm -r shelter
rm -rf /build
# this one is special wrt how the results are saved, see Makefile/USE_NIX_CACHE
echo "### $0: exporting resulting /nix/store (reproducible)..."
mkdir -p /store/5-go-beyond-using-nix/nix
cp -a --reflink=auto /nix/store /store/5-go-beyond-using-nix/nix/
echo "### $0: exporting /nix/var/nix/db to restore it (non-reproducible)..."
cp /nix/var/nix/db/db.sqlite db.sqlite
sqlite3 db.sqlite 'UPDATE ValidPaths SET registrationTime = 1;'
sqlite3 db.sqlite .dump > /nix/var/nix/db/db.sqlite.dump
tar --exclude nix/var/nix/db/db.sqlite \
-cf /store/5-go-beyond-using-nix/nix-db.tar /nix/var/nix/db
rm /nix/var/nix/db/db.sqlite.dump
echo "### $0: exporting the iso as well..."
cat .tmp*-iso > /store/5-go-beyond-using-nix/ZilchOS-core.iso

40
06/recipes/_1.test.sh Executable file
View file

@ -0,0 +1,40 @@
#!/store/1-stage1/protobusybox/bin/ash
set -uex
export PATH=/store/1-stage1/tinycc/wrappers:/store/1-stage1/protobusybox/bin
mkdir -p /tmp/_1.test; cd /tmp/_1.test
echo "### $0: checking that /protosrc has not leaked into outputs..."
! grep -rF /protosrc /store/1-stage1
echo "### $0: checking compilation..."
cat > va_test.c <<\EOF
#include <stdio.h>
int main(int _, char* argv[]) { printf("%sargs\n", argv[1]); return 0; }
EOF
cat va_test.c
cc -o va_test.o va_test.c
cc -o va_test va_test.c
( ! grep /store/2a3-intermediate-musl/lib/libc.so va_test.o va_test )
( ! grep ld-linux va_test.o va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
echo "### $0: checking that we've got bzip2..."
hello=$(echo hello | bzip2 -1 | bzip2 -d)
[ "$hello" == hello ]
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/_1.test . )
( ! grep -rF /tmp/1-stage1 . )
( ! grep -rF /store/1-stage1 . )
( ! grep -rF va_test . )
( ! grep -rF /tmp/1-stage1 /store/1-stage1 )
( ! grep -rF /tmp/_1.test /store/1-stage1 )
touch /store/_1.test # indicator of successful completion

65
06/recipes/_2a0-ccache.sh Executable file
View file

@ -0,0 +1,65 @@
#!/store/1-stage1/protobusybox/bin/ash
#> FETCH a02f4e8360dc6618bc494ca35b0ae21cea080f804a4898eab1ad3fcd108eb400
#> FROM https://github.com/ccache/ccache/releases/download/v3.7.12/ccache-3.7.12.tar.xz
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/1-stage1/tinycc/wrappers"
export PATH="$PATH:/store/2a0-static-gnumake/bin"
echo "### $0: unpacking ccache sources..."
mkdir -p /tmp/_2a0-ccache; cd /tmp/_2a0-ccache
tar --strip-components=1 -xf /downloads/ccache-3.7.12.tar.xz
echo "### $0: building ccache..."
sed -i 's|/bin/sh|/store/1-stage1/protobusybox/bin/ash|' configure
ash configure \
--host x86_64-linux --build x86_64-linux \
--prefix=/store/_2a0-ccache
make -j $NPROC
echo "### $0: installing ccache..."
make -j $NPROC install
cat > /store/_2a0-ccache/wrap-available <<\EOF
mkdir -p .ccache-wrappers
for prefix in '' x86_64-linux- x86_64-linux-musl- x86_64-linux-unknown-; do
for name in cc c++ gcc g++ clang clang++ tcc; do
if command -v $prefix$name; then
ln -s /store/_2a0-ccache/bin/ccache \
.ccache-wrappers/$prefix$name
fi
done
done
pwd
export PATH="$(pwd)/.ccache-wrappers:$PATH"
EOF
chmod +x /store/_2a0-ccache/wrap-available
. /store/_2a0-ccache/wrap-available
mkdir /store/_2a0-ccache/etc
cat > /store/_2a0-ccache/etc/ccache.conf <<\EOF
cache_dir = /ccache
compiler_check = content
compression = false
sloppiness = include_file_ctime,include_file_mtime
max_size = 0
EOF
export PATH="/store/_2a0-ccache/wrappers/cc-only:$PATH"
echo "### $0: testing ccache on itself..."
/store/_2a0-ccache/bin/ccache -z
/store/_2a0-ccache/bin/ccache -s > _stats; cat _stats
grep '^cache miss 0$' _stats
grep '^cache hit rate 0.00 %$' _stats
ash configure --host x86_64-linux --build x86_64-linux CC=cc
make -j $NPROC -B
/store/_2a0-ccache/bin/ccache -z
make -j $NPROC -B
/store/_2a0-ccache/bin/ccache -s > _stats; cat _stats
grep '^cache miss 0$' _stats
grep '^cache hit rate 100.00 %' _stats
/store/_2a0-ccache/bin/ccache -z

37
06/recipes/_2a3.test.sh Executable file
View file

@ -0,0 +1,37 @@
#!/store/1-stage1/protobusybox/bin/ash
set -uex
export PATH='/store/2a0-static-gnumake/bin'
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a2-static-gnugcc4-c/bin"
export PATH="$PATH:/store/1-stage1/protobusybox/bin"
mkdir -p /tmp/_2a3.test; cd /tmp/_2a3.test
echo "### $0: preparing..."
cat > va_test.c <<\EOF
#include <stdio.h>
int main(int _, char* argv[]) { printf("%sargs\n", argv[1]); return 0; }
EOF
cat va_test.c
echo "### $0: testing (dynamic)..."
SYSROOT=/store/2a3-intermediate-musl
make va_test \
CC=gcc \
LDFLAGS="-Wl,--dynamic-linker=$SYSROOT/lib/libc.so --sysroot $SYSROOT"
grep /store/2a3-intermediate-musl/lib/libc.so va_test
( ! grep ld-linux va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
echo "### $0: testing (static)..."
make -B va_test CC=gcc LDFLAGS="-static --sysroot $SYSROOT"
( ! grep /store/2a3-intermediate-musl/lib/libc.so va_test )
( ! grep ld-linux va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
touch /store/_2a3.test # indicator of successful completion

46
06/recipes/_2a4.test.sh Executable file
View file

@ -0,0 +1,46 @@
#!/store/1-stage1/protobusybox/bin/ash
set -uex
export PATH='/store/2a0-static-gnumake/bin'
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a4-gnugcc4-cpp/bin"
export PATH="$PATH:/store/1-stage1/protobusybox/bin"
mkdir -p /tmp/_2a4.test; cd /tmp/_2a4.test
echo "### $0: preparing..."
cat > va_test.c <<\EOF
#include <stdio.h>
int main(int _, char* argv[]) { printf("%sargs\n", argv[1]); return 0; }
EOF
cat va_test.c
echo "### $0: testing (dynamic)..."
make va_test CC=gcc # neither linker nor sysroot need to be specified now
grep /store/2a3-intermediate-musl/lib/libc.so va_test
( ! grep ld-linux va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
echo "### $0: testing (static)..."
make -B va_test CC=gcc LDFLAGS=-static # no specifying sysroot anymore
( ! grep /store/2a3-intermediate-musl/lib/libc.so va_test )
( ! grep ld-linux va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
echo "### $0: testing (dynamic C++)..."
cat > cpp_test.cpp <<\EOF
#include <iostream>
using namespace std;
int main() { cout << "this is c+" << "+" << endl; return 0; }
EOF
make cpp_test
grep /store/2a3-intermediate-musl/lib/libc.so cpp_test
( ! grep ld-linux cpp_test )
./cpp_test
[ "$(./cpp_test)" == 'this is c++' ]
touch /store/_2a4.test # indicator of successful completion

46
06/recipes/_2a5.test.sh Executable file
View file

@ -0,0 +1,46 @@
#!/store/1-stage1/protobusybox/bin/ash
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/2a0-static-gnumake/bin"
export PATH="$PATH:/store/2a1-static-binutils/bin"
export PATH="$PATH:/store/2a5-gnugcc10/bin"
mkdir -p /tmp/_2a5.test; cd /tmp/_2a5.test
echo "### $0: preparing..."
cat > va_test.c <<\EOF
#include <stdio.h>
int main(int _, char* argv[]) { printf("%sargs\n", argv[1]); return 0; }
EOF
cat va_test.c
echo "### $0: testing (dynamic)..."
make va_test CC=gcc
grep /store/2a3-intermediate-musl/lib/libc.so va_test
( ! grep ld-linux va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
echo "### $0: testing (static)..."
make -B va_test CC=gcc LDFLAGS=-static
( ! grep /store/2a3-intermediate-musl/lib/libc.so va_test )
( ! grep ld-linux va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
echo "### $0: testing (dynamic C++)..."
cat > cpp_test.cpp <<\EOF
#include <iostream>
using namespace std;
int main() { cout << "this is c+" << "+" << endl; return 0; }
EOF
make cpp_test
grep /store/2a3-intermediate-musl/lib/libc.so cpp_test
( ! grep ld-linux cpp_test )
./cpp_test
[ "$(./cpp_test)" == 'this is c++' ]
touch /store/_2a5.test # indicator of successful completion

49
06/recipes/_2a9.test.sh Executable file
View file

@ -0,0 +1,49 @@
#!/store/1-stage1/protobusybox/bin/ash
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/2a0-static-gnumake/bin"
export PATH="$PATH:/store/2a9-intermediate-clang/bin/generic-names"
mkdir -p /tmp/_2a9.test; cd /tmp/_2a9.test
echo "### $0: preparing..."
cat > va_test.c <<\EOF
#include <stdio.h>
int main(int _, char* argv[]) { printf("%sargs\n", argv[1]); return 0; }
EOF
cat va_test.c
echo "### $0: testing (dynamic)..."
make va_test
grep /store/2a3-intermediate-musl/lib/libc.so va_test
( ! grep ld-linux va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
echo "### $0: testing (static)..."
make -B va_test LDFLAGS=-static
( ! grep libc.so va_test )
( ! grep ld-linux va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
echo "### $0: testing (dynamic C++)..."
cat > cpp_test.cpp <<\EOF
#include <iostream>
using namespace std;
int main() { cout << "this is c+" << "+" << endl; return 0; }
EOF
# FIXME flags!
make cpp_test CXX=c++ LDFLAGS='-rpath /store/2a9-intermediate-clang/lib'
grep /store/2a3-intermediate-musl/lib/libc.so cpp_test
( ! grep ld-linux cpp_test )
./cpp_test
[ "$(./cpp_test)" == 'this is c++' ]
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2a9 /store/2a9-intermediate-clang )
touch /store/_2a9.test # indicator of successful completion

51
06/recipes/_2b1.test.sh Executable file
View file

@ -0,0 +1,51 @@
#!/store/1-stage1/protobusybox/bin/ash
set -uex
export PATH='/store/1-stage1/protobusybox/bin'
export PATH="$PATH:/store/2a0-static-gnumake/bin"
export PATH="$PATH:/store/2b1-clang/bin"
mkdir -p /tmp/_2b1.test; cd /tmp/_2b1.test
echo "### $0: preparing..."
cat > va_test.c <<\EOF
#include <stdio.h>
int main(int _, char* argv[]) { printf("%sargs\n", argv[1]); return 0; }
EOF
cat va_test.c
echo "### $0: testing (dynamic)..."
make va_test
grep /store/2b0-musl/lib/libc.so va_test
( ! grep /store/2a3-intermediate-musl/lib/libc.so va_test )
( ! grep ld-linux va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
echo "### $0: testing (static)..."
make -B va_test LDFLAGS=-static
( ! grep libc.so va_test )
( ! grep ld-linux va_test )
./va_test var
[ "$(./va_test var)" == varargs ]
echo "### $0: testing (dynamic C++)..."
cat > cpp_test.cpp <<\EOF
#include <iostream>
using namespace std;
int main() { cout << "this is c+" << "+" << endl; return 0; }
EOF
# FIXME flags!
make cpp_test CXX=c++ LDFLAGS='-rpath /store/2b1-clang/lib'
grep /store/2b0-musl/lib/libc.so cpp_test
( ! grep /store/2a3-intermediate-musl/lib/libc.so cpp_test )
( ! grep ld-linux cpp_test )
./cpp_test
[ "$(./cpp_test)" == 'this is c++' ]
echo "### $0: checking for build path leaks..."
( ! grep -rF /tmp/2b1 /store/2b1-clang )
touch /store/_2b1.test # indicator of successful completion

54
06/recipes/_3b.test.sh Executable file
View file

@ -0,0 +1,54 @@
#!/store/2b2-busybox/bin/ash
set -uex
export PATH='/store/2b2-busybox/bin'
export PATH="$PATH:/store/3a-pkg-config/bin"
export PATH="$PATH:/store/3b-nix/bin"
export SHELL='/store/2b2-busybox/bin/ash'
export PKG_CONFIG_PATH=''
#export PKG_CONFIG_PATH='/store/3a-openssl/lib64/pkgconfig'
#export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-bzip2/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-sqlite/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-curl/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-editline/lib/pkgconfig"
#export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-xz/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-seccomp/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-libarchive/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-libsodium/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/store/3a-lowdown/lib/pkgconfig"
LIBDIRS=''
#LIBDIRS="$(pkg-config --variable=libdir openssl)"
#LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir bzip2)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir sqlite3)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libcurl)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libeditline)"
#LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir liblzma)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libseccomp)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libarchive)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir libsodium)"
LIBDIRS="$LIBDIRS:$(pkg-config --variable=libdir lowdown)"
LIBDIRS="$LIBDIRS:/store/3a-boost/lib"
LIBDIRS="$LIBDIRS:/store/2b1-clang/lib"
export LD_LIBRARY_PATH=$LIBDIRS
mkdir -p /tmp/_3b.test; cd /tmp/_3b.test
echo "### $0: faking lots of stuff for nix to work..."
mkdir shelter
export HOME=/tmp/_3b.test/shelter
export USER=notauser
echo 'oh come on' >/dev/urandom
echo "### $0: testing that derivation assumes a known input hash..."
nix repl > known-drv-hash.output <<\EOF
# see https://nixos.org/guides/nix-pills/our-first-derivation.html
derivation { name = "myname"; builder = "mybuilder"; system = "mysystem"; }
EOF
grep -Fx '«derivation /nix/store/z3hhlxbckx4g3n9sw91nnvlkjvyw754p-myname.drv»' \
known-drv-hash.output
rm -f /dev/urandom
touch /store/_3b.test # indicator of successful completion

39
06/recipes/all-past-stage1.sh Executable file
View file

@ -0,0 +1,39 @@
#!/store/1-stage1/protobusybox/bin/ash
set -uex
export SOURCE_DATE_EPOCH=0
/recipes/2a0-static-gnumake.sh
/recipes/2a1-static-binutils.sh
/recipes/2a2-static-gnugcc4-c.sh
/recipes/2a3-intermediate-musl.sh
/recipes/2a4-gnugcc4-cpp.sh
/recipes/2a5-gnugcc10.sh
/recipes/2a6-linux-headers.sh
/recipes/2a7-cmake.sh
/recipes/2a8-python.sh
/recipes/2a9-intermediate-clang.sh
/recipes/2b0-musl.sh
/recipes/2b1-clang.sh
/recipes/2b2-busybox.sh
/recipes/2b3-gnumake.sh
/recipes/3a-sqlite.sh
/recipes/3a-boost.sh
/recipes/3a-mbedtls.sh
/recipes/3a-pkg-config.sh
/recipes/3a-curl.sh
/recipes/3a-editline.sh
/recipes/3a-brotli.sh
/recipes/3a-gnugperf.sh
/recipes/3a-seccomp.sh
/recipes/3a-libarchive.sh
/recipes/3a-libsodium.sh
/recipes/3a-lowdown.sh
/recipes/3a-nlohmann-json.sh
/recipes/3b-busybox-static.sh
/recipes/3b-tinycc-static.sh
/recipes/3b-zig.sh
# /recipes/3b-nix.sh
# /recipes/4-rebootstrap-using-nix.sh
# /recipes/5-go-beyond-using-nix.sh