selfhost: migrate tool sources to directory packages

Build w6a and w6l from package-main directories and expose the wcc backend through a narrow package API so w6c and wwdump no longer import implementation files. Retarget the remaining load-bearing fixtures and example sources to directory packages; retain the one intentional flat compiler collision as an explicitly composed raw unit.
This commit is contained in:
2026-08-12 17:12:03 +09:00
parent 90f9d60291
commit c7d9dc92de
38 changed files with 197 additions and 252 deletions

View File

@@ -112,13 +112,11 @@ main(void)
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
/* #93 sep layout: the selfhost tools no longer leave a single
* next-to-source main.s. Self-build one real tool via the explicit
* main.ww compatibility root and feed EVERY emitted
* next-to-source main.s. Self-build one real directory package and
* feed EVERY emitted
* <tool>.sepwork/<pkg>.s as
* the generated-asm corpus — the root tool code plus each dep
* package's .s (richer than the old 3 monolithic main.s). The directory
* intentionally contains package main plus legacy file-import packages,
* so it is not a directory-package root. */
* package's .s (richer than the old 3 monolithic main.s). */
char stem[256], cmd[4096];
int fail = 0;
int n = 0;
@@ -126,11 +124,11 @@ main(void)
snprintf(stem, sizeof stem, "/tmp/wwa_%d_sh", getpid());
snprintf(cmd, sizeof cmd,
"timeout 400 %s/ww build -o %s "
"%s/selfhost/cmd/w6a/main.ww >/dev/null 2>&1",
"%s/selfhost/cmd/w6a >/dev/null 2>&1",
bin, stem, cwd);
if (runwait(cmd) != 0) {
fprintf(stderr,
"w6a_ww FAIL: cannot sep-build selfhost/cmd/w6a/main.ww\n");
"w6a_ww FAIL: cannot sep-build selfhost/cmd/w6a\n");
/* a failed build can leave a partial stem/.sepwork tree. */
fail = 1;
goto cleanup;

View File

@@ -57,9 +57,8 @@ slurp(const char *path, char **outbuf, size_t *outlen)
* the linkable unit is now the per-package .o + reverse-topo .a set the
* sep driver assembles (a raw `w6l <root>.o *.a libwwrt.a` from the test
* side fails — `undefined reference` — because it can't reproduce the
* driver's topo order). The tools are legacy inline-package directories,
* so their explicit main.ww files remain the compatibility roots. Drive
* the full sep build twice; both compile directly and differ only in the
* driver's topo order). Drive each real directory package through the
* full sep build twice; both compile directly and differ only in the
* linker: once with the default C w6l, once with WW_W6L=w6l_ww. Diff
* the two real tool binaries. Exercises the full archive two-pass loader
* + reverse-topo .a resolution — a stronger link than the old single
@@ -77,7 +76,7 @@ build_and_diff(const char *bin, const char *cwd, const char *tool, int id)
snprintf(cmd, sizeof cmd,
"timeout 300 %s/ww build -o %s "
"%s/selfhost/cmd/%s/main.ww >/dev/null 2>&1",
"%s/selfhost/cmd/%s >/dev/null 2>&1",
bin, cstem, cwd, tool);
if (runwait(cmd) != 0) {
fprintf(stderr, "w6l_ww FAIL: C-link sep-build of %s\n", tool);
@@ -86,7 +85,7 @@ build_and_diff(const char *bin, const char *cwd, const char *tool, int id)
}
snprintf(cmd, sizeof cmd,
"WW_W6L=%s/w6l_ww timeout 300 %s/ww build "
"-o %s %s/selfhost/cmd/%s/main.ww >/dev/null 2>&1",
"-o %s %s/selfhost/cmd/%s >/dev/null 2>&1",
bin, bin, wstem, cwd, tool);
if (runwait(cmd) != 0) {
fprintf(stderr, "w6l_ww FAIL: ww-link sep-build of %s\n", tool);

View File

@@ -294,7 +294,7 @@ main(void)
static char wwdump_src[2048], wwdump_incs[4096];
snprintf(wwdump_src, sizeof wwdump_src, "%s/selfhost/cmd/wwdump/main.ww", cwd);
snprintf(wwdump_incs, sizeof wwdump_incs,
"%s/lib/ww:%s/lib/encoding/utf8:%s/selfhost/cmd/wcc",
"%s/lib/ww:%s/lib/encoding/utf8:%s/selfhost/cmd",
cwd, cwd, cwd);
cases[1].src = wwdump_src;
cases[1].incs = wwdump_incs;

View File

@@ -361,7 +361,7 @@ main(void)
{
char inc[4096], cmd[16384];
snprintf(inc, sizeof inc,
"-I %s/lib -I %s/lib/ww -I %s/selfhost/cmd/wcc", cwd, cwd, cwd);
"-I %s/lib -I %s/lib/ww -I %s/selfhost/cmd", cwd, cwd, cwd);
char root[2048];
snprintf(root, sizeof root, "%s/selfhost/cmd/w6c/main.ww", cwd);

View File

@@ -63,18 +63,15 @@ slurp_eq(const char *a, const char *b)
return rc;
}
/* Each tool builds via `ww_ww build -I <local> -I lib/ww -I selfhost/cmd/wcc src`.
/* Each tool builds via `ww_ww build -I lib/ww -I selfhost/cmd src`.
* lib/ww holds the language introspection (lex/tok/ast/parse/typ/sym);
* selfhost/cmd/wcc holds the compiler internals (mem/check/cgen*).
* selfhost/cmd holds the compiler-internal `wcc` directory package.
* Dotted `import encoding.utf8;` finds lib/encoding/utf8/ via the
* driver's default srclib path post-task-#22 dir-enum.
* Some tools have a local module dir (w6a, w6l with sibling .ww files).
* inc_local is "" for tools without one (w6c, ww, wwdump).
*/
struct buildjob {
const char *tool;
const char *src_rel;
const char *inc_local;
char workdir[64];
pid_t pid;
};
@@ -99,20 +96,11 @@ spawn_build(const char *bin, const char *cwd, struct buildjob *j)
}
char cmd[4096];
if (j->inc_local && j->inc_local[0]) {
snprintf(cmd, sizeof cmd,
"cd %s && timeout 180 %s/ww_ww build -o %s/main -I %s/%s "
"-I %s/lib/ww "
"-I %s/selfhost/cmd/wcc %s/%s >/dev/null 2>%s/build.err",
j->workdir, bin, j->workdir, cwd, j->inc_local,
cwd, cwd, cwd, j->src_rel, j->workdir);
} else {
snprintf(cmd, sizeof cmd,
"cd %s && timeout 180 %s/ww_ww build -o %s/main "
"-I %s/lib/ww "
"-I %s/selfhost/cmd/wcc %s/%s >/dev/null 2>%s/build.err",
j->workdir, bin, j->workdir, cwd, cwd, cwd, j->src_rel, j->workdir);
}
snprintf(cmd, sizeof cmd,
"cd %s && timeout 180 %s/ww_ww build -o %s/main "
"-I %s/lib/ww -I %s/selfhost/cmd "
"%s/%s >/dev/null 2>%s/build.err",
j->workdir, bin, j->workdir, cwd, cwd, cwd, j->src_rel, j->workdir);
pid_t p = fork();
if (p < 0) {
@@ -184,11 +172,11 @@ main(void)
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
struct buildjob jobs[] = {
{ "w6c", "selfhost/cmd/w6c/main.ww", "", {0}, 0 },
{ "w6a", "selfhost/cmd/w6a/main.ww", "selfhost/cmd/w6a", {0}, 0 },
{ "w6l", "selfhost/cmd/w6l/main.ww", "selfhost/cmd/w6l", {0}, 0 },
{ "ww", "selfhost/cmd/ww/main.ww", "", {0}, 0 },
{ "wwdump", "selfhost/cmd/wwdump/main.ww", "", {0}, 0 },
{ "w6c", "selfhost/cmd/w6c/main.ww", {0}, 0 },
{ "w6a", "selfhost/cmd/w6a", {0}, 0 },
{ "w6l", "selfhost/cmd/w6l", {0}, 0 },
{ "ww", "selfhost/cmd/ww/main.ww", {0}, 0 },
{ "wwdump", "selfhost/cmd/wwdump/main.ww", {0}, 0 },
};
const int n = (int)(sizeof jobs / sizeof jobs[0]);

View File

@@ -1,12 +0,0 @@
// crossmod — sibling module whose probe() takes a param named like the
// module `shadowmod` that paramshadowmod (NOT crossmod) imports. The
// shadow rule is filtered by the BINDING's own module (src_imports
// cur_mod filter): crossmod carries no `import shadowmod`, so this param
// must NOT trip even though a sibling module in the same bundle imports
// that leaf. Legit-form survivor of the abolished self-import tolerance.
package crossmod;
export fn probe(shadowmod: str) i32 = {
return shadowmod.len;
};

View File

@@ -0,0 +1,11 @@
// crossmod — directory package whose probe() takes a param named like the
// module `shadowmod` that paramshadowmod (NOT crossmod) imports. The
// shadow rule is filtered by the binding's own module (src_imports
// cur_mod filter): crossmod carries no `import shadowmod`, so this param
// must NOT trip even though a sibling package imports that leaf.
package crossmod;
export fn probe(shadowmod: str) i32 = {
return shadowmod.len;
};