buninu-linux 0.8.56 → 0.10.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.
Files changed (77) hide show
  1. package/LICENSES/MIT-ZilchOS-bootstrap-from-tcc.txt +21 -0
  2. package/NOTICE.md +34 -0
  3. package/README.md +3 -0
  4. package/initramfs/bin/tar +34 -46
  5. package/initramfs/buninu/apps/bunmsh/CHANGELOG.md +103 -0
  6. package/initramfs/buninu/apps/bunmsh/PORTING.md +133 -15
  7. package/initramfs/buninu/apps/bunmsh/help/awk.md +38 -0
  8. package/initramfs/buninu/apps/bunmsh/help/break.md +21 -0
  9. package/initramfs/buninu/apps/bunmsh/help/chmod.md +8 -2
  10. package/initramfs/buninu/apps/bunmsh/help/cmp.md +29 -0
  11. package/initramfs/buninu/apps/bunmsh/help/continue.md +22 -0
  12. package/initramfs/buninu/apps/bunmsh/help/cp.md +4 -0
  13. package/initramfs/buninu/apps/bunmsh/help/diff.md +30 -0
  14. package/initramfs/buninu/apps/bunmsh/help/egrep.md +26 -0
  15. package/initramfs/buninu/apps/bunmsh/help/export.md +2 -2
  16. package/initramfs/buninu/apps/bunmsh/help/expr.md +30 -0
  17. package/initramfs/buninu/apps/bunmsh/help/fgrep.md +25 -0
  18. package/initramfs/buninu/apps/bunmsh/help/grep.md +4 -0
  19. package/initramfs/buninu/apps/bunmsh/help/ls.md +4 -2
  20. package/initramfs/buninu/apps/bunmsh/help/mkdir.md +1 -1
  21. package/initramfs/buninu/apps/bunmsh/help/print.md +3 -0
  22. package/initramfs/buninu/apps/bunmsh/help/return.md +23 -0
  23. package/initramfs/buninu/apps/bunmsh/help/sed.md +8 -3
  24. package/initramfs/buninu/apps/bunmsh/help/set.md +12 -3
  25. package/initramfs/buninu/apps/bunmsh/help/tr.md +4 -0
  26. package/initramfs/buninu/apps/bunmsh/help/trap.md +22 -0
  27. package/initramfs/buninu/apps/bunmsh/help/uniq.md +27 -0
  28. package/initramfs/buninu/apps/bunmsh/package.json +1 -1
  29. package/initramfs/buninu/apps/bunmsh/src/awk.js +203 -0
  30. package/initramfs/buninu/apps/bunmsh/src/diff.js +222 -0
  31. package/initramfs/buninu/apps/bunmsh/src/fancy-ls.js +15 -4
  32. package/initramfs/buninu/apps/bunmsh/src/main.js +21 -5
  33. package/initramfs/buninu/apps/bunmsh/src/sed.js +159 -0
  34. package/initramfs/buninu/apps/bunmsh/src/shell.js +1283 -540
  35. package/initramfs/buninu/apps/bunmsh/test/awk-reference.test.js +35 -0
  36. package/initramfs/buninu/apps/bunmsh/test/awk.test.js +62 -0
  37. package/initramfs/buninu/apps/bunmsh/test/posix-bootstrap.test.js +595 -0
  38. package/initramfs/buninu/apps/bunmsh/test/utility-reference-cases.mjs +98 -0
  39. package/initramfs/buninu/apps/bunmsh/test/utility-reference.test.js +23 -0
  40. package/initramfs/buninu/apps/jsgotty/client-kitty.mjs +61 -0
  41. package/initramfs/buninu/apps/jsgotty/client.mjs +16 -0
  42. package/initramfs/buninu/apps/jsgotty/package-lock.json +2 -2
  43. package/initramfs/buninu/apps/jsgotty/package.json +1 -1
  44. package/initramfs/buninu/apps/jsgotty/tests/client-kitty.test.mjs +43 -0
  45. package/initramfs/etc/resolv.conf +2 -1
  46. package/initramfs/usr/lib/bootstrap/1.prepare-rootfs.js +106 -0
  47. package/initramfs/usr/lib/bootstrap/10.build-m4.js +40 -0
  48. package/initramfs/usr/lib/bootstrap/11.build-flex.js +50 -0
  49. package/initramfs/usr/lib/bootstrap/12.build-gcc.js +261 -0
  50. package/initramfs/usr/lib/bootstrap/2.enter-rootfs.js +49 -0
  51. package/initramfs/usr/lib/bootstrap/3.gen-musl-dev.js +141 -0
  52. package/initramfs/usr/lib/bootstrap/4.build-tcc.js +61 -0
  53. package/initramfs/usr/lib/bootstrap/5.build-make.js +58 -0
  54. package/initramfs/usr/lib/bootstrap/6.build-binutils.js +77 -0
  55. package/initramfs/usr/lib/bootstrap/7.build-gmp.js +68 -0
  56. package/initramfs/usr/lib/bootstrap/8.build-mpfr.js +59 -0
  57. package/initramfs/usr/lib/bootstrap/9.build-mpc.js +55 -0
  58. package/initramfs/usr/lib/bootstrap/LICENSE +21 -0
  59. package/initramfs/usr/lib/bootstrap/LICENSES/MIT-ZilchOS-bootstrap-from-tcc.txt +21 -0
  60. package/initramfs/usr/lib/bootstrap/NOTICE.md +65 -0
  61. package/initramfs/usr/lib/bootstrap/README.md +204 -0
  62. package/initramfs/usr/lib/bootstrap/downloads.md +49 -0
  63. package/initramfs/usr/lib/bootstrap/lib/build.js +155 -0
  64. package/initramfs/usr/lib/bootstrap/lib/common.js +134 -0
  65. package/initramfs/usr/lib/bootstrap/lib/compile-object.c +14 -0
  66. package/initramfs/usr/lib/bootstrap/lib/musl-headers.js +59 -0
  67. package/initramfs/usr/lib/bootstrap/lib/seed.js +148 -0
  68. package/initramfs/usr/lib/bootstrap/lib/startup-check.c +14 -0
  69. package/initramfs/usr/lib/bootstrap/lib/tcc-build.js +53 -0
  70. package/initramfs/usr/lib/bootstrap/sources/musl-1.2.6.tar.gz +0 -0
  71. package/initramfs/usr/lib/bootstrap/sources/tinycc-05f0faf-upstream.tar.gz +0 -0
  72. package/initramfs/usr/lib/bootstrap/sources/tinycc-local-bootstrap-files.tar.gz +0 -0
  73. package/initramfs/usr/share/doc/buninu-linux/tar.md +11 -0
  74. package/package.json +1 -1
  75. package/scripts/fetch.js +2 -0
  76. package/test/bootstrap.test.js +65 -0
  77. package/test/tar-strip.test.js +36 -0
@@ -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.
@@ -0,0 +1,204 @@
1
+ # Bootstrap from Bun
2
+
3
+ - Route and recipe reference: [ZilchOS/bootstrap-from-tcc](https://github.com/ZilchOS/bootstrap-from-tcc),
4
+ by Alexander Sosedkin. See [NOTICE.md](NOTICE.md) for full credit and component licenses.
5
+
6
+ - Requires Bun with `Bun.cc`, `Bun.Archive` and `Bun.YAML` (tested with 1.4.2).
7
+ - Supported targets: native ARM64 and x86-64 Linux with musl.
8
+ - Run stages 1 and 2 outside the new rootfs; run stages 3–12 inside it.
9
+ - The numbered filenames are the execution order.
10
+ - Inside the new rootfs, use `cd /bootstrap`; scripts, `lib/`, `README.md` and
11
+ `downloads.md` live alongside `src`, `toolchain`, `deps`, `build` and `result`.
12
+ - Copies of scripts 1/2 are included for reference; run preparation/entry from
13
+ the outer package, which also contains the bundled seed archives.
14
+
15
+ ## 1. Prepare a new rootfs
16
+
17
+ ```sh
18
+ bun /usr/lib/bootstrap/1.prepare-rootfs.js
19
+ ```
20
+
21
+ - Default architecture: the running Bun's architecture.
22
+ - Default destination: `./roota` for ARM64, `./rootx` for x86-64.
23
+ - Optional arguments: `[ARCH] [ROOTFS]`.
24
+ - Architecture aliases: `a`, `arm64`, `aarch64`; `x`, `x64`, `x86_64`, `x86-64`.
25
+ - A single directory argument uses the default architecture.
26
+ - Destination must be new; its parent directory must already exist.
27
+
28
+ ```sh
29
+ bun /usr/lib/bootstrap/1.prepare-rootfs.js a ./my-root
30
+ bun /usr/lib/bootstrap/1.prepare-rootfs.js x
31
+ bun /usr/lib/bootstrap/1.prepare-rootfs.js ./my-root
32
+ ```
33
+
34
+ - On Buninu Linux (`ID=buninu-linux` in `/etc/os-release`), reuse the local
35
+ Bun, musl loader, libgcc, libstdc++, DNS configuration, bunmsh and extraction tools.
36
+ - For a different target architecture, or outside Buninu Linux:
37
+ - Fetch `buninu-linux@0.9.56` for the runtime libraries and JavaScript tools.
38
+ - Fetch musl Bun 1.4.2 for the target architecture (x64 uses baseline).
39
+ - Verify SHA-256 before using either download.
40
+ - Pins live in `downloads.md`; despite its extension, it is YAML with the same
41
+ URL/hash pair format as `scripts/npm-packages.md`.
42
+ - Cache: `${XDG_CACHE_HOME:-$HOME/.cache}/buninu-bootstrap/`; cached files are
43
+ verified again. A bad cache entry causes an error, not an unchecked fallback.
44
+ - No musl-dev APK, prebuilt CRT, installed headers or standalone compiler required.
45
+ - Bundled sources are hash-checked and extracted:
46
+ - `sources/musl-1.2.6.tar.gz` -> `/bootstrap/src/musl`.
47
+ - `sources/tinycc-05f0faf-upstream.tar.gz` -> `/bootstrap/src/tinycc`.
48
+ - `sources/tinycc-local-bootstrap-files.tar.gz` -> TinyCC recipes and `/bin/cc`.
49
+ - `/bin/sh` is an executable JavaScript file with `#!/bin/bun`.
50
+ - It prepends `/bootstrap/result/bin` and `/bootstrap/toolchain/bin` to PATH,
51
+ removes duplicates, then dynamically imports bunmsh. Missing bin directories
52
+ are harmless; child processes inherit the environment.
53
+ - Build stages use a separate shell launcher and explicit PATH so installed
54
+ result tools do not silently replace bootstrap tools during a rebuild.
55
+ - Scripts 1–12 and helpers are copied to `/bootstrap` in the new rootfs.
56
+ - Preparation can select another architecture; entering/building requires a
57
+ matching CPU or a separately configured emulator. These scripts do not set up emulation.
58
+
59
+ ## 2. Print the entry command
60
+
61
+ ```sh
62
+ bun /usr/lib/bootstrap/2.enter-rootfs.js
63
+ ```
64
+
65
+ - Accepts `[ARCH] [ROOTFS]`, with the same architecture aliases as stage 1.
66
+ - Without a destination (including an architecture-only invocation), prints
67
+ `/path/to/your/rootfs` as a placeholder instead of assuming `roota` or `rootx`.
68
+ - Prints commands only; it does not enter, modify or read the rootfs or its
69
+ marker file. The destination does not need to exist to print instructions.
70
+ - Reads the host's os-release only to choose chroot versus bunproot.
71
+ - Buninu Linux example (requires chroot privileges):
72
+
73
+ ```sh
74
+ chroot '/absolute/path/rootx' /bin/sh
75
+ ```
76
+
77
+ - Android/Termux and other hosts with bunproot:
78
+
79
+ ```sh
80
+ bun x bunproot -koe -r '/absolute/path/roota'
81
+ ```
82
+
83
+ ## 3. Generate musl development files, inside the rootfs
84
+
85
+ ```sh
86
+ cd /bootstrap
87
+ bun 3.gen-musl-dev.js
88
+ ```
89
+
90
+ - Generate 217 public headers from musl's source and architecture templates.
91
+ - Build TinyCC in memory using `Bun.cc`; emit `crt1.o`, `crti.o`, `crtn.o`.
92
+ - Install headers under `/usr/include`, CRT objects under `/usr/lib`.
93
+ - Preserve the original musl sources.
94
+ - ARM64 only: use a temporary startup-header override omitting the unused
95
+ `_DYNAMIC` argument, because TinyCC's ARM64 assembler does not support `adrp`.
96
+ - This override applies only to ordinary `crt1`; static PIE `rcrt1` and the
97
+ dynamic loader are not built here.
98
+ - Refuse existing headers/CRT instead of overwriting them.
99
+ - If this stage fails after headers were generated, preserve the rootfs for
100
+ diagnosis and prepare a fresh destination before repeating the full flow.
101
+
102
+ ## 4. Build a standalone C compiler, inside the rootfs
103
+
104
+ ```sh
105
+ bun /bootstrap/4.build-tcc.js
106
+ cc /bootstrap/src/tinycc/bun-hello-libc.c -o /tmp/hello
107
+ /tmp/hello
108
+ ```
109
+
110
+ - Build TinyCC stage1 through `Bun.cc`, using the generated CRT.
111
+ - Build the x64 compiler runtime helpers when needed.
112
+ - Rebuild stage2 with stage1 and require byte-identical executables.
113
+ - Verify libc, x64 conversions/variadic calls, and CRT startup behavior.
114
+ - `/bin/cc` launches `/bootstrap/toolchain/bin/tcc` with the headers, libraries and helpers.
115
+ - Stages 3/4 are offline; no host build tools are used.
116
+ - The seed Bun, musl shared library, libgcc and libstdc++ remain prebuilt inputs.
117
+ - Source licenses remain in the archives and extracted trees:
118
+ - musl: `/bootstrap/src/musl/COPYRIGHT`.
119
+ - TinyCC: `/bootstrap/src/tinycc/COPYING` and individual source-file notices.
120
+
121
+ ## 5–12. Build through GCC 4.7
122
+
123
+ - Run each numbered script inside the same rootfs, in order.
124
+ - Each stage fetches its source on demand and checks the SHA-256 in `downloads.md`.
125
+ - These eight large source archives are **not** included in the npm package or initramfs.
126
+ - Fixed version/commit URLs are used, never `latest` or a moving branch.
127
+ - Cache: `/root/.cache/buninu-bootstrap` by default.
128
+ - Source trees: `/bootstrap/src`; build trees and logs: `/bootstrap/build`.
129
+ - Reserve at least 3 GB of writable workspace; avoid a small RAM-only rootfs.
130
+ - Set `BOOTSTRAP_JOBS=1` to reduce build concurrency (default: 2).
131
+
132
+ | Stage | Command after `bun /bootstrap/` | Source |
133
+ | --- | --- | --- |
134
+ | 5 | `5.build-make.js` | GNU Make 4.4.1, official GNU release |
135
+ | 6 | `6.build-binutils.js` | Binutils 2.39, official GNU release |
136
+ | 7 | `7.build-gmp.js` | GMP 4.3.2, official GNU release |
137
+ | 8 | `8.build-mpfr.js` | MPFR 2.4.2, official version directory |
138
+ | 9 | `9.build-mpc.js` | MPC 0.8.1, GCC infrastructure archive |
139
+ | 10 | `10.build-m4.js` | GNU m4 1.4.18, official GNU release |
140
+ | 11 | `11.build-flex.js` | Flex 2.6.4, official GitHub release |
141
+ | 12 | `12.build-gcc.js` | GCC mirror, commit `9d2b63d100ae7c99ee8b128fb41086fd85c8f57d` |
142
+
143
+ - GNU Make first uses its shipped no-make builder, then rebuilds itself.
144
+ - Binutils supplies the assembler, linker and archive tools; stage 6 also
145
+ builds/tests the additional TinyCC runtime helpers needed by later stages.
146
+ - GMP/MPFR/MPC are static prerequisite libraries; MPFR runs upstream arithmetic
147
+ tests, and MPC's stage verifies all three libraries together.
148
+ - m4 and Flex are built from source and tested before GCC uses them.
149
+ - `configure` and build shell commands use bunmsh. External utility adapters
150
+ call its JavaScript builtins in POSIX mode; no host awk/sed/coreutils enter the build.
151
+ - Logs are streamed to the terminal and retained under `/bootstrap/build/logs/`.
152
+ - Re-running a failed stage revalidates the download, reconfigures and resumes
153
+ its existing build tree. Source compatibility patches are idempotent.
154
+ - GCC uses a vendor 4.7 branch containing both ARM64 and x64 backends. The pinned
155
+ GitHub snapshot's 76,720 regular source files match the earlier local archive.
156
+ - Stage 12 builds the C frontend and libgcc, then tests `-O0`/`-O2`, the musl
157
+ interpreter, architecture/type macros and 128-bit runtime arithmetic.
158
+ - Stage 12 runs GCC's `install-gcc` and `install-target-libgcc` rules with
159
+ `--prefix=/bootstrap/result`, and includes native Binutils executables.
160
+ - GCC's private `include` and `include-fixed` directories are installed using
161
+ JavaScript with symlinks dereferenced, avoiding the tar pipe and recursive
162
+ `cp -p` requirements and retaining headers after source/build removal.
163
+ - The installed compiler is `/bootstrap/result/bin/gcc`; it is not an `xgcc`
164
+ wrapper and needs no `-B` pointing into a build directory.
165
+ - The final check temporarily renames `src`, `toolchain`, `deps` and `build`
166
+ to sibling `*.verification-hidden` directories, compiles/runs ordinary and
167
+ shared-library checks using only result tools, then restores the directories.
168
+ - If interrupted by a forced kill, restore any `*.verification-hidden` directory
169
+ to its original name before resuming. Ordinary errors restore them automatically.
170
+ - Successful verification writes `/bootstrap/result/verified.json` and
171
+ `/bootstrap/result/verification.log`; stage 12's build log remains in `build/logs`.
172
+ - After stage 12 succeeds, `/bootstrap/build` can be deleted. The installed GCC
173
+ also does not need `src`, `deps` or `toolchain`; keep these to rebuild or use
174
+ the intermediate tools such as Make and TinyCC.
175
+ - Result still uses the rootfs's musl loader/libc, `/usr/include`, `/usr/lib`
176
+ startup objects and seed runtime libraries. It is not a self-contained rootfs.
177
+ - The installation prefix is fixed at `/bootstrap/result`; moving it into `/usr`
178
+ is not supported by simply copying it. A system installation should instead
179
+ configure `--prefix=/usr` and stage the installation with `DESTDIR`.
180
+ - This is the GCC 4.7 C + libgcc stopping milestone, not a full GCC three-stage
181
+ bootstrap or a completed Bun rebuild.
182
+ - This layout/install revision has only received static checks; validate it
183
+ by running the numbered stages in a new rootfs.
184
+
185
+ ## Directory layout
186
+
187
+ | Directory | Contents |
188
+ | --- | --- |
189
+ | `/bootstrap/src` | musl, TinyCC and downloaded package source trees |
190
+ | `/bootstrap/toolchain` | intermediate compiler, runtime helpers, Make, Binutils, m4, Flex and JS utility adapters |
191
+ | `/bootstrap/deps` | static GMP, MPFR and MPC libraries and headers |
192
+ | `/bootstrap/build` | intermediate objects, build trees and build logs |
193
+ | `/bootstrap/result` | installed GCC, libgcc, Binutils and final verification records |
194
+
195
+ ```sh
196
+ # Entering through /bin/sh already sets PATH.
197
+ gcc --version
198
+ gcc hello.c -o hello
199
+ ./hello
200
+ ```
201
+
202
+ - The generated musl headers and CRT remain in `/usr/include` and `/usr/lib`.
203
+ - The source archive download cache remains under `/root/.cache/buninu-bootstrap`.
204
+
@@ -0,0 +1,49 @@
1
+ # YAML: [immutable download URL, SHA-256]
2
+ # npm SHA-256 verified against registry SHA-512 integrity.
3
+ # Bun 1.4.2 pins match scripts/arch.js.
4
+
5
+ "buninu-linux@0.9.56":
6
+ - https://registry.npmjs.org/buninu-linux/-/buninu-linux-0.9.56.tgz
7
+ - sha256:972b46b5f0b1caaa0e64e352de68e37b28cc6955ed4240e91f0fe358b0d6f73d
8
+
9
+ "bun-linux-aarch64-musl@1.4.2":
10
+ - https://github.com/oven-sh/bun/releases/download/bun-v1.4.2/bun-linux-aarch64-musl.zip
11
+ - sha256:71760b6c8ea30623b81a4907cb815d48e2ea266f2e73e751534a44a0607950df
12
+
13
+ "bun-linux-x64-musl-baseline@1.4.2":
14
+ - https://github.com/oven-sh/bun/releases/download/bun-v1.4.2/bun-linux-x64-musl-baseline.zip
15
+ - sha256:76e1db84e98f22f78de0a87e309bfbbf297732847f9720db36750646c85c8c18
16
+
17
+ # Stages 5–12: fetched on demand, never bundled in the npm package.
18
+
19
+ "make@4.4.1":
20
+ - https://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz
21
+ - sha256:dd16fb1d67bfab79a72f5e8390735c49e3e8e70b4945a15ab1f81ddb78658fb3
22
+
23
+ "binutils@2.39":
24
+ - https://ftp.gnu.org/gnu/binutils/binutils-2.39.tar.gz
25
+ - sha256:d12ea6f239f1ffe3533ea11ad6e224ffcb89eb5d01bbea589e9158780fa11f10
26
+
27
+ "gmp@4.3.2":
28
+ - https://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.gz
29
+ - sha256:7be3ad1641b99b17f6a8be6a976f1f954e997c41e919ad7e0c418fe848c13c97
30
+
31
+ "mpfr@2.4.2":
32
+ - https://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.gz
33
+ - sha256:246d7e184048b1fc48d3696dd302c9774e24e921204221540745e5464022b637
34
+
35
+ "mpc@0.8.1":
36
+ - https://gcc.gnu.org/pub/gcc/infrastructure/mpc-0.8.1.tar.gz
37
+ - sha256:e664603757251fd8a352848276497a4c79b7f8b21fd8aedd5cc0598a38fee3e4
38
+
39
+ "m4@1.4.18":
40
+ - https://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.gz
41
+ - sha256:ab2633921a5cd38e48797bf5521ad259bdc4b979078034a3b790d7fec5493fab
42
+
43
+ "flex@2.6.4":
44
+ - https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
45
+ - sha256:e87aae032bf07c26f85ac0ed3250998c37621d95f8bd748b31f15b33c45ee995
46
+
47
+ "gcc@4.7-9d2b63d":
48
+ - https://codeload.github.com/gcc-mirror/gcc/tar.gz/9d2b63d100ae7c99ee8b128fb41086fd85c8f57d
49
+ - sha256:8ba051b9c7e2de8f3dd97d0092cffd17cafec2e2e2f70f1ec17a6c94972c8f80