buninu-linux 0.9.56 → 0.11.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSES/MIT-ZilchOS-bootstrap-from-tcc.txt +21 -0
- package/NOTICE.md +48 -2
- package/README.md +81 -12
- package/initramfs/bin/buninu-land +26 -0
- package/initramfs/bin/chroot +68 -47
- package/initramfs/buninu/CHANGELOG.md +22 -0
- package/initramfs/buninu/apps/jsgotty/package-lock.json +2 -2
- package/initramfs/buninu/apps/jsgotty/package.json +1 -1
- package/initramfs/buninu/apps/jsgotty/static/js/gotty.js +1 -0
- package/initramfs/buninu/package.json +1 -1
- package/initramfs/lib/bunterm/geometry.js +15 -0
- package/initramfs/lib/bunterm/pointer-report.js +10 -0
- package/initramfs/lib/bunterm/terminal.js +5 -4
- package/initramfs/lib/chroot-options.js +69 -0
- package/initramfs/usr/lib/bootstrap/1.prepare-rootfs.js +106 -0
- package/initramfs/usr/lib/bootstrap/10.build-m4.js +40 -0
- package/initramfs/usr/lib/bootstrap/11.build-flex.js +50 -0
- package/initramfs/usr/lib/bootstrap/12.build-gcc.js +261 -0
- package/initramfs/usr/lib/bootstrap/2.enter-rootfs.js +49 -0
- package/initramfs/usr/lib/bootstrap/3.gen-musl-dev.js +141 -0
- package/initramfs/usr/lib/bootstrap/4.build-tcc.js +61 -0
- package/initramfs/usr/lib/bootstrap/5.build-make.js +58 -0
- package/initramfs/usr/lib/bootstrap/6.build-binutils.js +77 -0
- package/initramfs/usr/lib/bootstrap/7.build-gmp.js +68 -0
- package/initramfs/usr/lib/bootstrap/8.build-mpfr.js +59 -0
- package/initramfs/usr/lib/bootstrap/9.build-mpc.js +55 -0
- package/initramfs/usr/lib/bootstrap/LICENSE +21 -0
- package/initramfs/usr/lib/bootstrap/LICENSES/MIT-ZilchOS-bootstrap-from-tcc.txt +21 -0
- package/initramfs/usr/lib/bootstrap/NOTICE.md +65 -0
- package/initramfs/usr/lib/bootstrap/README.md +204 -0
- package/initramfs/usr/lib/bootstrap/downloads.md +49 -0
- package/initramfs/usr/lib/bootstrap/lib/build.js +155 -0
- package/initramfs/usr/lib/bootstrap/lib/common.js +134 -0
- package/initramfs/usr/lib/bootstrap/lib/compile-object.c +14 -0
- package/initramfs/usr/lib/bootstrap/lib/musl-headers.js +59 -0
- package/initramfs/usr/lib/bootstrap/lib/seed.js +148 -0
- package/initramfs/usr/lib/bootstrap/lib/startup-check.c +14 -0
- package/initramfs/usr/lib/bootstrap/lib/tcc-build.js +53 -0
- package/initramfs/usr/lib/bootstrap/sources/musl-1.2.6.tar.gz +0 -0
- package/initramfs/usr/lib/bootstrap/sources/tinycc-05f0faf-upstream.tar.gz +0 -0
- package/initramfs/usr/lib/bootstrap/sources/tinycc-local-bootstrap-files.tar.gz +0 -0
- package/initramfs/usr/share/doc/buninu-linux/bunterm.md +4 -1
- package/initramfs/usr/share/doc/buninu-linux/chroot.md +37 -3
- package/package.json +1 -1
- package/scripts/npm-packages.md +8 -3
- package/test/bootstrap.test.js +65 -0
- package/test/bunterm-pixelmouse.test.js +27 -0
- package/test/chroot-bind.test.js +70 -0
- package/test/fetch-npm.test.js +2 -2
- package/test/stage-npm.test.js +42 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { cc } from "bun:ffi";
|
|
3
|
+
import {
|
|
4
|
+
mkdtempSync, readFileSync, renameSync,
|
|
5
|
+
rmSync, writeFileSync,
|
|
6
|
+
} from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import {
|
|
9
|
+
assertAbsent, bootstrap, cli,
|
|
10
|
+
requireRootfs, validateElf,
|
|
11
|
+
} from "./lib/common.js";
|
|
12
|
+
import {
|
|
13
|
+
generateHeaders,
|
|
14
|
+
} from "./lib/musl-headers.js";
|
|
15
|
+
|
|
16
|
+
async function main(args) {
|
|
17
|
+
// Run inside the prepared rootfs.
|
|
18
|
+
// This generates public headers
|
|
19
|
+
// and ordinary dynamic-link CRT.
|
|
20
|
+
// It does not build libc or rcrt1.
|
|
21
|
+
if (args.length) throw new Error(
|
|
22
|
+
"Usage: bun 3.gen-musl-dev.js"
|
|
23
|
+
);
|
|
24
|
+
const { arch } = requireRootfs();
|
|
25
|
+
const names = [
|
|
26
|
+
"crt1.o", "crti.o", "crtn.o",
|
|
27
|
+
];
|
|
28
|
+
assertAbsent("/usr/include");
|
|
29
|
+
for (const name of names) {
|
|
30
|
+
assertAbsent(`/usr/lib/${name}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Follow musl's Makefile rules in
|
|
34
|
+
// JS: public headers, arch bits,
|
|
35
|
+
// alltypes.h and syscall.h.
|
|
36
|
+
console.log(
|
|
37
|
+
"① Generating musl headers"
|
|
38
|
+
);
|
|
39
|
+
generateHeaders(
|
|
40
|
+
arch,
|
|
41
|
+
"/bootstrap/src/musl",
|
|
42
|
+
"/usr/include"
|
|
43
|
+
);
|
|
44
|
+
// chroot mounts /tmp separately;
|
|
45
|
+
// stage objects on the same FS as
|
|
46
|
+
// /usr/lib for the final rename.
|
|
47
|
+
const work = mkdtempSync(
|
|
48
|
+
"/usr/lib/.musl-crt-"
|
|
49
|
+
);
|
|
50
|
+
let compiler;
|
|
51
|
+
try {
|
|
52
|
+
// ARM64 TCC does not handle adrp.
|
|
53
|
+
// Ordinary crt1's _start_c uses
|
|
54
|
+
// x0, not x1 (_DYNAMIC). Omit just
|
|
55
|
+
// that unused argument in a
|
|
56
|
+
// temporary header override.
|
|
57
|
+
// Keep musl sources untouched.
|
|
58
|
+
if (arch === "aarch64") {
|
|
59
|
+
prepareArm64Startup(work);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Bun.cc builds libtcc.c in memory
|
|
63
|
+
// without standalone cc or CRT.
|
|
64
|
+
// TCC_OUTPUT_OBJ emits the three
|
|
65
|
+
// relocatable startup objects.
|
|
66
|
+
console.log(
|
|
67
|
+
"② Building CRT with Bun.cc"
|
|
68
|
+
);
|
|
69
|
+
compiler = cc({
|
|
70
|
+
source: join(
|
|
71
|
+
bootstrap,
|
|
72
|
+
"lib/compile-object.c"
|
|
73
|
+
),
|
|
74
|
+
library: ["gcc_s"],
|
|
75
|
+
flags: ["-L/usr/lib", "-L/lib"],
|
|
76
|
+
include: [
|
|
77
|
+
"/bootstrap/src/tinycc",
|
|
78
|
+
"/bootstrap/src/tinycc/include",
|
|
79
|
+
"/usr/include",
|
|
80
|
+
],
|
|
81
|
+
symbols: {
|
|
82
|
+
compile_object: {
|
|
83
|
+
args: [
|
|
84
|
+
"cstring", "cstring",
|
|
85
|
+
"cstring",
|
|
86
|
+
],
|
|
87
|
+
returns: "int",
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
compileCrt(
|
|
92
|
+
compiler, arch, work, names
|
|
93
|
+
);
|
|
94
|
+
for (const name of names) {
|
|
95
|
+
renameSync(
|
|
96
|
+
join(work, name),
|
|
97
|
+
`/usr/lib/${name}`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
console.log(
|
|
101
|
+
"Ready: musl headers and CRT."
|
|
102
|
+
);
|
|
103
|
+
console.log(
|
|
104
|
+
"Next: bun " +
|
|
105
|
+
"/bootstrap/" +
|
|
106
|
+
"4.build-tcc.js"
|
|
107
|
+
);
|
|
108
|
+
} finally {
|
|
109
|
+
compiler?.close();
|
|
110
|
+
rmSync(work, {
|
|
111
|
+
recursive: true, force: true,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function prepareArm64Startup(work) {
|
|
117
|
+
const original = readFileSync("/bootstrap/src/musl/arch/aarch64/crt_arch.h", "utf8");
|
|
118
|
+
const lines = original.split("\n");
|
|
119
|
+
const removed = lines.filter(line => line.includes("_DYNAMIC"));
|
|
120
|
+
if (removed.length !== 4 || !removed.some(line => line.includes("adrp x1"))) {
|
|
121
|
+
throw new Error("Unexpected musl ARM64 startup code; refusing compatibility edit");
|
|
122
|
+
}
|
|
123
|
+
writeFileSync(join(work, "crt_arch.h"), lines.filter(line => !line.includes("_DYNAMIC")).join("\n"));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function compileCrt(compiler, arch, work, names) {
|
|
127
|
+
const z = text => Buffer.from(text + "\0");
|
|
128
|
+
const flags = `-nostdinc -DCRT -D_XOPEN_SOURCE=700 -I${work} -I/bootstrap/src/musl/arch/${arch} -I/bootstrap/src/musl/arch/generic -I/bootstrap/src/musl/src/include -I/bootstrap/src/musl/src/internal -I/usr/include -I/bootstrap/src/tinycc/include`;
|
|
129
|
+
for (const name of names) {
|
|
130
|
+
const source = name === "crt1.o" ? "/bootstrap/src/musl/crt/crt1.c" : `/bootstrap/src/musl/crt/${arch}/${name.slice(0, -2)}.s`;
|
|
131
|
+
const output = join(work, name);
|
|
132
|
+
console.log(`${source} -> /usr/lib/${name}`);
|
|
133
|
+
const result = compiler.symbols.compile_object(z(source), z(output), z(flags));
|
|
134
|
+
if (result) throw new Error(`${name}: TinyCC returned ${result}`);
|
|
135
|
+
const bytes = readFileSync(output);
|
|
136
|
+
validateElf(name, bytes, arch);
|
|
137
|
+
if (bytes.readUInt16LE(16) !== 1) throw new Error(`${name} is not a relocatable ELF object`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (import.meta.main) await cli(main);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import {
|
|
5
|
+
bootstrap, cli, requireRootfs, run,
|
|
6
|
+
validateElf,
|
|
7
|
+
} from "./lib/common.js";
|
|
8
|
+
import {
|
|
9
|
+
buildTcc,
|
|
10
|
+
} from "./lib/tcc-build.js";
|
|
11
|
+
|
|
12
|
+
async function main(args) {
|
|
13
|
+
// Stage 3 must have generated
|
|
14
|
+
// headers and the three CRT files.
|
|
15
|
+
if (args.length) throw new Error(
|
|
16
|
+
"Usage: bun 4.build-tcc.js"
|
|
17
|
+
);
|
|
18
|
+
const { arch } = requireRootfs();
|
|
19
|
+
for (const name of [
|
|
20
|
+
"crt1.o", "crti.o", "crtn.o",
|
|
21
|
+
]) {
|
|
22
|
+
validateElf(
|
|
23
|
+
name,
|
|
24
|
+
readFileSync(`/usr/lib/${name}`),
|
|
25
|
+
arch
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Bun.cc -> standalone stage1 ->
|
|
30
|
+
// stage2, then compare bytes.
|
|
31
|
+
// Build x64 runtime helpers when
|
|
32
|
+
// needed and test /bin/cc.
|
|
33
|
+
await buildTcc();
|
|
34
|
+
|
|
35
|
+
// Exercise the generated CRT:
|
|
36
|
+
// argv, env, constructors,
|
|
37
|
+
// destructors and exit status.
|
|
38
|
+
await verifyStartup();
|
|
39
|
+
console.log(
|
|
40
|
+
"Ready: cc source.c -o program"
|
|
41
|
+
);
|
|
42
|
+
console.log(
|
|
43
|
+
"Next: bun /bootstrap/" +
|
|
44
|
+
"5.build-make.js"
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function verifyStartup() {
|
|
49
|
+
const output = "/bootstrap/build/tinycc/startup-check";
|
|
50
|
+
await run(["/bin/cc", join(bootstrap, "lib/startup-check.c"), "-o", output]);
|
|
51
|
+
const child = Bun.spawn([output, "hello", "two words"], {
|
|
52
|
+
env: { PATH: "/bin:/usr/bin", CRT_TEST: "seed-free" }, stdout: "pipe", stderr: "inherit",
|
|
53
|
+
});
|
|
54
|
+
const stdout = await new Response(child.stdout).text();
|
|
55
|
+
if (await child.exited !== 42 || stdout !== "argc/argv, environment, constructor OK\ndestructor OK\n") {
|
|
56
|
+
throw new Error(`CRT startup check failed: ${stdout}`);
|
|
57
|
+
}
|
|
58
|
+
console.log(stdout + "exit status 42: OK");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (import.meta.main) await cli(main);
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import {
|
|
3
|
+
chmodSync, copyFileSync,
|
|
4
|
+
} from "node:fs";
|
|
5
|
+
import { cli } from "./lib/common.js";
|
|
6
|
+
import {
|
|
7
|
+
buildRoot, command, configure,
|
|
8
|
+
installAdapters, makeIn, patch,
|
|
9
|
+
ready, shell, source, stage, tools,
|
|
10
|
+
} from "./lib/build.js";
|
|
11
|
+
|
|
12
|
+
async function main(args) {
|
|
13
|
+
const { triple } = stage(
|
|
14
|
+
5, "make", args
|
|
15
|
+
);
|
|
16
|
+
installAdapters();
|
|
17
|
+
const src = await source(
|
|
18
|
+
"make@4.4.1", "make-4.4.1"
|
|
19
|
+
);
|
|
20
|
+
const build = buildRoot + "/make";
|
|
21
|
+
prepareMake(src);
|
|
22
|
+
await configure(src, build, [
|
|
23
|
+
"--build=" + triple,
|
|
24
|
+
"--prefix=/bootstrap/toolchain",
|
|
25
|
+
"--disable-dependency-tracking",
|
|
26
|
+
"--without-guile", "--disable-nls",
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
// GNU Make provides its own
|
|
30
|
+
// no-make shell bootstrap builder.
|
|
31
|
+
await command(
|
|
32
|
+
[shell, src + "/build.sh"],
|
|
33
|
+
build
|
|
34
|
+
);
|
|
35
|
+
copyFileSync(
|
|
36
|
+
build + "/make", tools + "/make"
|
|
37
|
+
);
|
|
38
|
+
chmodSync(tools + "/make", 0o755);
|
|
39
|
+
await makeIn(build, ["clean"]);
|
|
40
|
+
await makeIn(build);
|
|
41
|
+
copyFileSync(
|
|
42
|
+
build + "/make", tools + "/make"
|
|
43
|
+
);
|
|
44
|
+
await command(
|
|
45
|
+
[tools + "/make", "--version"]
|
|
46
|
+
);
|
|
47
|
+
ready(5, "GNU Make self-rebuild");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function prepareMake(src) {
|
|
51
|
+
patch(src + "/build.sh", ' LIBOBJS="${LIBOBJS:+$LIBOBJS }lib/$lo"',
|
|
52
|
+
' lo=${lo#\'${LIBOBJDIR}\'}\n LIBOBJS="${LIBOBJS:+$LIBOBJS }lib/$lo"');
|
|
53
|
+
patch(src + "/src/mkcustom.h", "char *alloca ();", "void *alloca ();");
|
|
54
|
+
patch(src + "/lib/glob.c", "extern char *alloca ();", "extern void *alloca ();");
|
|
55
|
+
patch(src + "/lib/alloca.c", "memory_full ();", "abort ();");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (import.meta.main) await cli(main);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import {
|
|
3
|
+
existsSync, readdirSync,
|
|
4
|
+
readFileSync, statSync,
|
|
5
|
+
copyFileSync, writeFileSync,
|
|
6
|
+
} from "node:fs";
|
|
7
|
+
import { cli } from "./lib/common.js";
|
|
8
|
+
import {
|
|
9
|
+
buildRoot, command, configure,
|
|
10
|
+
makeIn, ready, source, stage,
|
|
11
|
+
toolchain, tools,
|
|
12
|
+
} from "./lib/build.js";
|
|
13
|
+
|
|
14
|
+
async function main(args) {
|
|
15
|
+
const { arch, triple } = stage(
|
|
16
|
+
6, "binutils", args
|
|
17
|
+
);
|
|
18
|
+
const src = await source(
|
|
19
|
+
"binutils@2.39", "binutils-2.39"
|
|
20
|
+
);
|
|
21
|
+
const build = buildRoot + "/binutils";
|
|
22
|
+
const env = {
|
|
23
|
+
CFLAGS: "-O2 -D__LITTLE_ENDIAN__=1",
|
|
24
|
+
};
|
|
25
|
+
await configure(src, build, [
|
|
26
|
+
"--build=" + triple,
|
|
27
|
+
"--host=" + triple,
|
|
28
|
+
"--target=" + triple,
|
|
29
|
+
"--prefix=" + toolchain,
|
|
30
|
+
"--disable-nls", "--disable-werror",
|
|
31
|
+
"--disable-gprofng",
|
|
32
|
+
"--disable-gold", "--disable-gdb",
|
|
33
|
+
"--disable-sim", "--disable-libctf",
|
|
34
|
+
"--disable-shared",
|
|
35
|
+
"--disable-multilib",
|
|
36
|
+
"--disable-dependency-tracking",
|
|
37
|
+
"--without-debuginfod",
|
|
38
|
+
"--without-zstd",
|
|
39
|
+
], env);
|
|
40
|
+
await makeIn(build, ["all"], env);
|
|
41
|
+
restoreManpages(src, build);
|
|
42
|
+
await makeIn(build, ["install"], env);
|
|
43
|
+
await runtime(arch);
|
|
44
|
+
await command([
|
|
45
|
+
toolchain + "/bin/as", "--version",
|
|
46
|
+
]);
|
|
47
|
+
await command([
|
|
48
|
+
toolchain + "/bin/ld", "--version",
|
|
49
|
+
]);
|
|
50
|
+
ready(6, "Binutils and TCC runtime");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function restoreManpages(src, build) {
|
|
54
|
+
for (const dir of ["gas/doc", "binutils/doc", "ld", "gprof"]) {
|
|
55
|
+
for (const name of readdirSync(src + "/" + dir).filter(n => n.endsWith(".1"))) {
|
|
56
|
+
const target = `${build}/${dir}/${name}`;
|
|
57
|
+
if (existsSync(target) && statSync(target).size === 0) copyFileSync(`${src}/${dir}/${name}`, target);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function runtime(arch) {
|
|
63
|
+
const cwd = buildRoot + "/tcc-runtime";
|
|
64
|
+
if (arch === "aarch64") {
|
|
65
|
+
await command([tools + "/cc", "-c", "/bootstrap/src/tinycc/lib/lib-arm64.c", "-o", "lib-arm64.o"], cwd);
|
|
66
|
+
await command([toolchain + "/bin/ar", "rcs", toolchain + "/lib/tcc/libbootstrap-tcc-arm64.a", "lib-arm64.o"], cwd);
|
|
67
|
+
}
|
|
68
|
+
const code = `static volatile long double a=1.5L,b=2.0L;
|
|
69
|
+
int main(void){long double x=a,y=b;return x*y!=3.0L||x/y!=0.75L||x+y!=3.5L||x-y!=-0.5L||!(x<y)||(double)(x*y)!=3.0;}`;
|
|
70
|
+
// command() creates the working directory before compilation.
|
|
71
|
+
await command([toolchain + "/bin/ar", "--version"], cwd);
|
|
72
|
+
writeFileSync(cwd + "/quad.c", code);
|
|
73
|
+
await command([tools + "/cc", "quad.c", "-o", "quad"], cwd);
|
|
74
|
+
await command([cwd + "/quad"], cwd);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (import.meta.main) await cli(main);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { cli } from "./lib/common.js";
|
|
4
|
+
import {
|
|
5
|
+
buildRoot, canonicalizers, configure,
|
|
6
|
+
makeIn, patch, deps, ready,
|
|
7
|
+
source, stage,
|
|
8
|
+
} from "./lib/build.js";
|
|
9
|
+
|
|
10
|
+
async function main(args) {
|
|
11
|
+
const { arch, triple } = stage(
|
|
12
|
+
7, "gmp", args
|
|
13
|
+
);
|
|
14
|
+
const src = await source(
|
|
15
|
+
"gmp@4.3.2", "gmp-4.3.2"
|
|
16
|
+
);
|
|
17
|
+
const build = buildRoot + "/gmp";
|
|
18
|
+
canonicalizers(src);
|
|
19
|
+
patch(
|
|
20
|
+
src + "/gmp-impl.h",
|
|
21
|
+
"char *alloca ();",
|
|
22
|
+
"void *alloca ();"
|
|
23
|
+
);
|
|
24
|
+
// GMP 4.3 uses CPU "none" for C;
|
|
25
|
+
// --disable-assembly is ignored.
|
|
26
|
+
// Keep build/host equal: native,
|
|
27
|
+
// with 64-bit unsigned-long limbs.
|
|
28
|
+
const generic = arch === "x86_64";
|
|
29
|
+
const host = generic
|
|
30
|
+
? "none-unknown-linux-musl"
|
|
31
|
+
: triple;
|
|
32
|
+
const env = {
|
|
33
|
+
ABI: generic ? "long" : "standard",
|
|
34
|
+
CPPFLAGS: "-DNO_ASM",
|
|
35
|
+
};
|
|
36
|
+
await configure(src, build, [
|
|
37
|
+
"--build=" + host,
|
|
38
|
+
"--host=" + host,
|
|
39
|
+
"--prefix=" + deps,
|
|
40
|
+
"--disable-shared",
|
|
41
|
+
"--enable-static",
|
|
42
|
+
"--disable-dependency-tracking",
|
|
43
|
+
"--disable-cxx",
|
|
44
|
+
"--enable-alloca=malloc-reentrant",
|
|
45
|
+
], env);
|
|
46
|
+
checkConfiguration(src, build);
|
|
47
|
+
await makeIn(build, ["all"], env);
|
|
48
|
+
await makeIn(build, ["install"], env);
|
|
49
|
+
ready(7, "GMP static library");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function checkConfiguration(src, build) {
|
|
53
|
+
const log = readFileSync(build + "/config.log", "utf8");
|
|
54
|
+
const recorded = log.slice(log.lastIndexOf("## confdefs.h. ##"));
|
|
55
|
+
const template = readFileSync(src + "/config.in", "utf8");
|
|
56
|
+
const config = readFileSync(build + "/config.h", "utf8");
|
|
57
|
+
const names = new Set([...template.matchAll(/^#undef (\w+)/gm)].map(m => m[1]));
|
|
58
|
+
const actual = new Map([...config.matchAll(/^#define (\w+)[ \t]+(.*)$/gm)].map(m => [m[1], m[2].trim()]));
|
|
59
|
+
let checked = 0;
|
|
60
|
+
for (const m of recorded.matchAll(/^#define (\w+)[ \t]+(.*)$/gm)) {
|
|
61
|
+
if (!names.has(m[1])) continue;
|
|
62
|
+
if (actual.get(m[1]) !== m[2].trim()) throw new Error(`GMP config.h mismatch: ${m[1]}`);
|
|
63
|
+
checked++;
|
|
64
|
+
}
|
|
65
|
+
if (checked < 20) throw new Error("Insufficient GMP configure definitions");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (import.meta.main) await cli(main);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import {
|
|
3
|
+
readFileSync, writeFileSync,
|
|
4
|
+
} from "node:fs";
|
|
5
|
+
import { cli } from "./lib/common.js";
|
|
6
|
+
import {
|
|
7
|
+
buildRoot, canonicalizers, command,
|
|
8
|
+
configure, makeIn, patch, deps,
|
|
9
|
+
ready, source, stage,
|
|
10
|
+
} from "./lib/build.js";
|
|
11
|
+
|
|
12
|
+
async function main(args) {
|
|
13
|
+
const { triple } = stage(
|
|
14
|
+
8, "mpfr", args
|
|
15
|
+
);
|
|
16
|
+
const src = await source(
|
|
17
|
+
"mpfr@2.4.2", "mpfr-2.4.2"
|
|
18
|
+
);
|
|
19
|
+
const build = buildRoot + "/mpfr";
|
|
20
|
+
canonicalizers(src);
|
|
21
|
+
prepareAllocation(src);
|
|
22
|
+
await configure(src, build, [
|
|
23
|
+
"--build=" + triple,
|
|
24
|
+
"--host=" + triple,
|
|
25
|
+
"--prefix=" + deps,
|
|
26
|
+
"--disable-shared",
|
|
27
|
+
"--enable-static",
|
|
28
|
+
"--disable-dependency-tracking",
|
|
29
|
+
"--with-gmp=" + deps,
|
|
30
|
+
]);
|
|
31
|
+
await makeIn(build);
|
|
32
|
+
await makeIn(build, [
|
|
33
|
+
"-C", "tests",
|
|
34
|
+
"tadd", "tdiv", "tsqrt",
|
|
35
|
+
]);
|
|
36
|
+
for (const name of [
|
|
37
|
+
"tadd", "tdiv", "tsqrt",
|
|
38
|
+
]) {
|
|
39
|
+
await command(
|
|
40
|
+
[build + "/tests/" + name],
|
|
41
|
+
build + "/tests",
|
|
42
|
+
{ srcdir: src + "/tests" }
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
await makeIn(build, ["install"]);
|
|
46
|
+
ready(8, "MPFR upstream tests");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function prepareAllocation(src) {
|
|
50
|
+
const path = src + "/mpfr-gmp.h";
|
|
51
|
+
patch(path, "char *alloca ();", "void *alloca ();");
|
|
52
|
+
const text = readFileSync(path, "utf8");
|
|
53
|
+
if (text.includes("/* Bootstrap: no working alloca. */")) return;
|
|
54
|
+
const start = text.indexOf("#define TMP_ALLOC(n)"), end = text.indexOf("#define TMP_DECL(m)", start);
|
|
55
|
+
if (start < 0 || end < 0) throw new Error("Unexpected MPFR allocation macros");
|
|
56
|
+
writeFileSync(path, text.slice(0, start) + "/* Bootstrap: no working alloca. */\n#ifdef C_ALLOCA\n#define TMP_ALLOC(n) mpfr_tmp_allocate (&tmp_marker, (n))\n#else\n" + text.slice(start, end) + "#endif\n" + text.slice(end));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (import.meta.main) await cli(main);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { writeFileSync } from "node:fs";
|
|
3
|
+
import { cli } from "./lib/common.js";
|
|
4
|
+
import {
|
|
5
|
+
buildRoot, canonicalizers, command,
|
|
6
|
+
configure, makeIn, deps, ready,
|
|
7
|
+
source, stage, tools,
|
|
8
|
+
} from "./lib/build.js";
|
|
9
|
+
|
|
10
|
+
async function main(args) {
|
|
11
|
+
const { triple } = stage(
|
|
12
|
+
9, "mpc", args
|
|
13
|
+
);
|
|
14
|
+
const src = await source(
|
|
15
|
+
"mpc@0.8.1", "mpc-0.8.1"
|
|
16
|
+
);
|
|
17
|
+
const build = buildRoot + "/mpc";
|
|
18
|
+
canonicalizers(src);
|
|
19
|
+
await configure(src, build, [
|
|
20
|
+
"--build=" + triple,
|
|
21
|
+
"--host=" + triple,
|
|
22
|
+
"--prefix=" + deps,
|
|
23
|
+
"--disable-shared",
|
|
24
|
+
"--enable-static",
|
|
25
|
+
"--disable-dependency-tracking",
|
|
26
|
+
"--with-gmp=" + deps,
|
|
27
|
+
"--with-mpfr=" + deps,
|
|
28
|
+
]);
|
|
29
|
+
await makeIn(build);
|
|
30
|
+
await makeIn(build, ["install"]);
|
|
31
|
+
await verifyMath(build);
|
|
32
|
+
ready(9, "GMP, MPFR and MPC math");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function verifyMath(build) {
|
|
36
|
+
writeFileSync(build + "/verify-math.c", `#include <gmp.h>
|
|
37
|
+
#include <mpfr.h>
|
|
38
|
+
#include <mpc.h>
|
|
39
|
+
int main(void){
|
|
40
|
+
mpz_t z;mpfr_t f;mpc_t c;
|
|
41
|
+
mpz_init(z);mpz_ui_pow_ui(z,2,100);
|
|
42
|
+
if(mpz_sizeinbase(z,2)!=101)return 1;
|
|
43
|
+
mpz_sub_ui(z,z,1);if(mpz_popcount(z)!=100)return 2;
|
|
44
|
+
mpfr_init2(f,128);mpfr_set_ui(f,144,GMP_RNDN);mpfr_sqrt(f,f,GMP_RNDN);
|
|
45
|
+
if(mpfr_cmp_ui(f,12))return 3;
|
|
46
|
+
mpc_init2(c,128);mpc_set_ui_ui(c,3,4,MPC_RNDNN);mpc_mul(c,c,c,MPC_RNDNN);
|
|
47
|
+
if(mpfr_cmp_si(mpc_realref(c),-7)||mpfr_cmp_ui(mpc_imagref(c),24))return 4;
|
|
48
|
+
mpc_clear(c);mpfr_clear(f);mpz_clear(z);return 0;}
|
|
49
|
+
`);
|
|
50
|
+
await command([tools + "/cc", "-I" + deps + "/include", "verify-math.c",
|
|
51
|
+
deps + "/lib/libmpc.a", deps + "/lib/libmpfr.a", deps + "/lib/libgmp.a", "-o", "verify-math"], build);
|
|
52
|
+
await command([build + "/verify-math"], build);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (import.meta.main) await cli(main);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dr. John (醫者小智)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Alexander Sosedkin.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Bootstrap credits and third-party notices
|
|
2
|
+
|
|
3
|
+
Original Buninu bootstrap work uses the MIT license in `LICENSE`.
|
|
4
|
+
Third-party components retain the terms below.
|
|
5
|
+
|
|
6
|
+
## ZilchOS bootstrap-from-tcc
|
|
7
|
+
|
|
8
|
+
- Credit: [ZilchOS/bootstrap-from-tcc](https://github.com/ZilchOS/bootstrap-from-tcc).
|
|
9
|
+
- Author/copyright: Copyright (c) 2021 Alexander Sosedkin.
|
|
10
|
+
- License: MIT; the complete, unmodified notice is in
|
|
11
|
+
[LICENSES/MIT-ZilchOS-bootstrap-from-tcc.txt](LICENSES/MIT-ZilchOS-bootstrap-from-tcc.txt).
|
|
12
|
+
- Reference checkout: `d2f9454b34fef570cfb32cf5b17d85a90dba81bf`.
|
|
13
|
+
- Buninu's TinyCC-to-GCC bootstrap route was developed with this project's
|
|
14
|
+
route and recipes as references, particularly GNU Make's no-make bootstrap
|
|
15
|
+
and self-rebuild, Binutils configuration, and the transition to GCC 4.
|
|
16
|
+
- Buninu adapts that approach to Bun.cc, bunmsh, musl and native ARM64/x64;
|
|
17
|
+
its JavaScript stages, layout and local compatibility edits differ from the
|
|
18
|
+
original recipes. This credit does not imply upstream verification or endorsement.
|
|
19
|
+
- ZilchOS's MIT license covers its own work, not the independent packages
|
|
20
|
+
downloaded or compiled by either project's recipes.
|
|
21
|
+
|
|
22
|
+
## Sources bundled with Buninu Linux
|
|
23
|
+
|
|
24
|
+
| Material | License/provenance |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| musl 1.2.6 | MIT; original `COPYRIGHT` remains in the source archive and `/bootstrap/src/musl/COPYRIGHT` |
|
|
27
|
+
| TinyCC `05f0faf` | Compiler principally LGPL-2.1-or-later; original `COPYING` and individual source notices remain in `/bootstrap/src/tinycc` |
|
|
28
|
+
| TinyCC runtime helpers | Per-file terms apply; for example `lib/libtcc1.c` carries GPL-2.0-or-later with an additional linking permission, retained verbatim in the upstream archive |
|
|
29
|
+
| Local bootstrap overlay and JS scripts | Buninu Linux's MIT terms for original local work; third-party material keeps its own terms and notices |
|
|
30
|
+
|
|
31
|
+
- Archives are under `sources/` in the outer package; SHA-256 pins are in
|
|
32
|
+
`lib/seed.js`. Stage 1 extracts them without stripping copyright notices.
|
|
33
|
+
- The overlay supplies local configuration, build entry points and smoke tests.
|
|
34
|
+
Compiling or including upstream TinyCC source does not relicense that source.
|
|
35
|
+
- The musl ARM64 startup adjustment is a temporary local header override;
|
|
36
|
+
the original musl source and copyright notice are retained.
|
|
37
|
+
|
|
38
|
+
## Sources fetched by stages 5–12
|
|
39
|
+
|
|
40
|
+
These archives and their resulting binaries are not prebundled in the npm
|
|
41
|
+
package. Fixed URLs and SHA-256 pins are in `downloads.md`. Downloads preserve
|
|
42
|
+
upstream license texts and individual file notices in `/bootstrap/src`.
|
|
43
|
+
|
|
44
|
+
| Stage | Package | Principal code license / upstream notice |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| 5 | GNU Make 4.4.1 | GPL-3.0-or-later; `COPYING` |
|
|
47
|
+
| 6 | GNU Binutils 2.39 | GPL-3.0-or-later for the main tools; component-specific terms also apply; `COPYING*` and source headers |
|
|
48
|
+
| 7 | GMP 4.3.2 | LGPL-3.0-or-later for the library; `COPYING.LIB`, with GPL text in `COPYING` |
|
|
49
|
+
| 8 | MPFR 2.4.2 | LGPL-2.1-or-later for the library; `COPYING.LIB` |
|
|
50
|
+
| 9 | MPC 0.8.1 | LGPL-2.1-or-later for the library; `COPYING.LIB` |
|
|
51
|
+
| 10 | GNU m4 1.4.18 | GPL-3.0-or-later; `COPYING` |
|
|
52
|
+
| 11 | Flex 2.6.4 | Upstream BSD-style license; preserve its exact `COPYING` text |
|
|
53
|
+
| 12 | GCC 4.7 vendor commit `9d2b63d100ae7c99ee8b128fb41086fd85c8f57d` | Compiler GPL-3.0-or-later; libgcc files carry their own notices and GCC Runtime Library Exception 3.1 where stated; `COPYING3`, `COPYING.RUNTIME`, other `COPYING*` and source headers |
|
|
54
|
+
|
|
55
|
+
- This table summarizes the principal code licenses; manuals, bundled support
|
|
56
|
+
code and individual files may carry other terms. Their original notices govern.
|
|
57
|
+
- Stage 12 preserves the top-level license texts for GCC, Binutils and linked
|
|
58
|
+
numerical libraries under `/bootstrap/result/share/licenses/`, together with
|
|
59
|
+
this bootstrap credit and the ZilchOS MIT license.
|
|
60
|
+
- License texts alone are not Corresponding Source. A distributor of compiled
|
|
61
|
+
results must also retain/provide the applicable source and local changes as
|
|
62
|
+
required by the relevant licenses; the pinned downloads and shipped recipes
|
|
63
|
+
document the inputs and modifications.
|
|
64
|
+
- Prebuilt Bun, musl, libgcc, libstdc++ and bunmsh remain separately licensed
|
|
65
|
+
seed components; see the outer package's `NOTICE.md` and application notices.
|