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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SatahBsL1rTVi7DoecS2hK
This commit is contained in:
Charles VestalandClaude Opus 5.5 committed 2026-10-07 20:36:35 +02:00
1 parent 620fca0130
commit a554887abc
2 files changed
+36 -2

No files matched your search

+33 -2
View File
@@ -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)
+3
View File
@@ -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"