Poincaré conjecture: the Lean proof, cleaned up together
The 2026 Lean proof of the Poincaré conjecture after Morgan and Tian, 3 million lines, cleaned up together: smaller, faster to build, more readable, the theorems unchanged

| 1 | |
| 2 | # Builds the Lean image of poincare-conjecture in three steps, so the hours-long compile is never a Dockerfile |
| 3 | # layer that a failure throws away: |
| 4 | # |
| 5 | # sh docker/build.sh base the image shoal-poincare-lean:62db01af-base (lean.Dockerfile: minutes) |
| 6 | # sh docker/build.sh start the long step, detached, in the container $NAME on top of the base (hours) |
| 7 | # sh docker/build.sh commit once the container has exited 0: the image shoal-poincare-lean:62db01af |
| 8 | # |
| 9 | # Watch the long step with `docker logs --tail 3 $NAME`. If it stops (a kill, a reboot, a full disk), `docker start |
| 10 | # $NAME` goes on from the modules already compiled. Settings, all optional: CPUSET (the cores to use, as docker's |
| 11 | # --cpuset-cpus, e.g. 64-95), MEMORY (default 256g), NAME (default poincare-lean-build). |
| 12 | set -eu |
| 13 | TAG=shoal-poincare-lean:62db01af |
| 14 | NAME=${NAME:-poincare-lean-build} |
| 15 | CPUSET=${CPUSET:-} |
| 16 | MEMORY=${MEMORY:-256g} |
| 17 | here=$(cd "$(dirname "$0")" && pwd) |
| 18 | |
| 19 | # What the long step runs. The default targets (PoincareConjecture, PoincareLib), then the Comparator modules and |
| 20 | # the two tools as the project's Comparator/README.md says; the tools go on PATH; all of /opt is opened to `nobody`, |
| 21 | # the user the check runs a commit's Lean as, and the project's own build is given to `nobody`: the check compiles a |
| 22 | # commit on top of it, inside the job's container, and writes only what the commit changed (scripts/lean-ci/README.md; |
| 23 | # the dependencies' builds under .lake/packages stay root's). Lake writes a setup.json before it compiles a module |
| 24 | # (every transitive import's path, 1.5 MB here) and never reads it again: 35 GB of a 51 GB build, deleted. It needs no |
| 25 | # network: the base fetched everything. |
| 26 | LONG='set -eu |
| 27 | cd /opt/proof |
| 28 | lake build |
| 29 | lake build Challenge Solution @Comparator/comparator @lean4export/lean4export |
| 30 | ln -sf /opt/proof/.lake/packages/Comparator/.lake/build/bin/comparator /usr/local/bin/comparator |
| 31 | ln -sf /opt/proof/.lake/packages/lean4export/.lake/build/bin/lean4export /usr/local/bin/lean4export |
| 32 | for t in lean4export comparator landrun nanoda_bin lake lean; do command -v "$t" >/dev/null || { echo "missing: $t"; exit 1; }; done |
| 33 | find /opt/proof/.lake/build -name "*.setup.json" -delete |
| 34 | chmod -R a+rX /opt |
| 35 | chown -R nobody:nogroup /opt/proof/.lake/build |
| 36 | echo "long step done"' |
| 37 | |
| 38 | case "${1:-}" in |
| 39 | base) |
| 40 | DOCKER_BUILDKIT=0 docker build --network host ${CPUSET:+--cpuset-cpus "$CPUSET"} \ |
| 41 | -f "$here/lean.Dockerfile" -t "$TAG-base" "$here" |
| 42 | ;; |
| 43 | start) |
| 44 | docker run -d --name "$NAME" --network none ${CPUSET:+--cpuset-cpus "$CPUSET"} --memory "$MEMORY" \ |
| 45 | "$TAG-base" sh -c "$LONG" |
| 46 | ;; |
| 47 | commit) |
| 48 | test "$(docker inspect -f '{{.State.Status}} {{.State.ExitCode}}' "$NAME")" = "exited 0" \ |
| 49 | || { echo "$NAME has not finished cleanly; see docker logs --tail 20 $NAME, then docker start $NAME"; exit 1; } |
| 50 | docker commit --change 'ENV PROOF_BASE=/opt/proof' --change 'WORKDIR /opt/proof' --change 'CMD ["/bin/bash"]' \ |
| 51 | "$NAME" "$TAG" |
| 52 | docker rm "$NAME" |
| 53 | ;; |
| 54 | *) |
| 55 | echo "usage: sh docker/build.sh base|start|commit"; exit 2 |
| 56 | ;; |
| 57 | esac |