From a554887abc0ea3fd785d09be82b6fd6bf0e58eb2 Mon Sep 17 00:00:00 2001 From: Charles Vestal Date: Wed, 7 Oct 2026 20:36:35 +0200 Subject: [PATCH] Build: one long-lived toolchain container (docker exec) instead of one per tool call; publish: ask GitHub Pages to build The container per tool call was most of the build on a Mac (podman): X0X 38 s -> 26 s, FoMni 25 s -> 12 s, same package bytes. publish_pages.sh POSTs a Pages build: a push alone left a first deploy stuck. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01SatahBsL1rTVi7DoecS2hK --- tools/build.py | 35 +++++++++++++++++++++++++++++++++-- tools/publish_pages.sh | 3 +++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/tools/build.py b/tools/build.py index ed8f4dc..589d8ca 100755 --- a/tools/build.py +++ b/tools/build.py @@ -69,14 +69,45 @@ def use_docker(): return os.environ.get("JIELI_DOCKER", "0" if native else "1") == "1" +_BUILDER = None +_BUILDER_LOCK = __import__("threading").Lock() + + +def builder(): + """one long-lived toolchain container per source tree (starting a container per tool call cost + most of the build); it stops by itself after an hour without a build""" + global _BUILDER + with _BUILDER_LOCK: # the loader and the app build in parallel: start it once + return _builder_start() + + +def _builder_start(): + global _BUILDER + if _BUILDER: + return _BUILDER + name = "jieli-" + hashlib.sha1(str(SRC).encode()).hexdigest()[:10] + st = subprocess.run(["docker", "inspect", "-f", "{{.State.Running}}", name], capture_output=True, text=True) + if st.stdout.strip() != "true": + subprocess.run(["docker", "rm", "-f", name], capture_output=True) + r = subprocess.run(["docker", "run", "-d", "--rm", "--name", name, "--platform", "linux/amd64", + "-v", f"{SRC}:/work", "-v", f"{toolchain()}:/opt/jieli:ro", "-w", "/work", + DOCKER_IMAGE, "sh", "-c", "sleep 3600"], capture_output=True, text=True) + if r.returncode: + sys.stderr.write(r.stderr) + raise SystemExit("build: cannot start the toolchain container") + else: # an hour from now again + subprocess.run(["docker", "exec", "-d", name, "sh", "-c", "sleep 3600 && kill 1"], capture_output=True) + _BUILDER = name + return name + + def tc(tool, *args): """run a toolchain binary (pi32v2/bin/..., common/bin/...) with cwd SRC; paths relative to SRC""" rel = [str(Path(a).resolve().relative_to(SRC)) if isinstance(a, Path) else a for a in args] if tool == "cc": # the toolchain's cc wrapper needs python3; call clang directly tool, rel = "pi32v2/bin/clang", ["-target", "pi32v2", *rel] if use_docker(): - cmd = ["docker", "run", "--rm", "--platform", "linux/amd64", "-v", f"{SRC}:/work", - "-v", f"{toolchain()}:/opt/jieli:ro", "-w", "/work", DOCKER_IMAGE, f"/opt/jieli/{tool}", *rel] + cmd = ["docker", "exec", "-w", "/work", builder(), f"/opt/jieli/{tool}", *rel] else: cmd = [str(toolchain() / tool), *rel] r = subprocess.run(cmd, cwd=SRC, capture_output=True, text=True) diff --git a/tools/publish_pages.sh b/tools/publish_pages.sh index 1e5234e..7e2f188 100755 --- a/tools/publish_pages.sh +++ b/tools/publish_pages.sh @@ -19,4 +19,7 @@ git add -A git commit -q -m "Site for X0X $V (from $SHA)" git push -q -f "$REMOTE" gh-pages rm -rf .git +# ask GitHub Pages to build it now: a push alone has left the first deploy stuck on "building" +REPO="$(printf %s "$REMOTE" | sed -E 's#(git@github.com:|https://github.com/)##; s#\.git$##')" +gh api -X POST "repos/$REPO/pages/builds" >/dev/null 2>&1 || echo "(could not ask GitHub Pages to build: check the repository's Pages settings)" echo "pushed the site for $V to gh-pages"