What programs mean (the languages, translators, Mojo checker and
interpreter, prover, fuzzer, machine model, catalog problems and the Mojo
corpus with godbolt's stored answers) was mixed into the site's tree, so a
change to the prover and a change to a button went through the same gate
and the same docs. This moves all of it under core/, laid out as its own
repository, ready to be extracted with its history and pinned here as a
git submodule.
- core/: src/{engines,services,sync,mojo,exercises,curriculum,common},
mojo/, syntax/mojo.xml, its tests (with Workspace and workForProblem in
place of the site's Session), scripts (corpus pipeline, play, the
exercise and probe starters, engines export/diff), and its docs
(engines, trust, mojo-corpus, exercises, coverage). Its own pixi.toml,
package.json, README, AGENTS.md and CI workflow.
- core/tests/boundary.test.mjs: library modules use no DOM, import no
page widget, and import nothing outside src/.
- core/scripts/cli.mjs: pixi run cli check|run|prove|fuzz|translate.
- core/scripts/dafny.py: Dafny 4.11.0 pinned by version and SHA-256 per
platform, fetched into .tools/ (pixi run dafny-fetch, pixi run dafny).
- The site imports core only as #core/<path>.js: an import map in
index.html, "imports" in package.json for node, core's declarations for
tsc. The site's TypeScript builds core first (npm run build).
- assemble.sh, the Quarto engine copy, the render cache key, check-pages,
quarto-export and quarto-css read core/dist and core/mojo; quarto-css
copies core's syntax/mojo.xml into the extension.
- Site tests that covered engines moved to core; the rest keep Session.
- README, AGENTS.md, docs/app.md, docs/deploy.md and the CI workflow
describe the split (checkout with submodules; core's tests and corpus
status run against the pinned commit).
Gate: site 110 pass; core 307 pass; corpus status --strict passes.
Manual check: the assembled site opens Bridge (count-base-proved),
Developer and Hardware (count-base) with the editor, the stepper and the
board, and no module errors.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FgvbRdoEheAHqsRmr2WuKZ
113 lines
4.2 KiB
Python
113 lines
4.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Dafny, pinned: fetch the release this project uses, check it, and run it.
|
|
|
|
pixi run dafny-fetch download Dafny into .tools/ once (network), checked by SHA-256
|
|
pixi run dafny verify file.dfy run the pinned Dafny (fetches first if it is missing)
|
|
pixi run dafny --version
|
|
|
|
Dafny is not on conda-forge, so pixi cannot install it directly; this script is the pin instead. It downloads the
|
|
official release zip for this machine from GitHub, refuses it unless its SHA-256 is the one written below, and unpacks
|
|
it into .tools/dafny-<version>/ (ignored by git). The zip is self-contained: it carries its own .NET runtime and the Z3
|
|
builds Dafny was tested with, so the solver is pinned too. To move to another Dafny, change VERSION and every hash in
|
|
RELEASES in one commit, and expect every stored proof answer to be asked again.
|
|
|
|
Standard library only, like the corpus pipeline.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import os
|
|
import platform
|
|
import shutil
|
|
import stat
|
|
import subprocess
|
|
import sys
|
|
import urllib.request
|
|
import zipfile
|
|
from pathlib import Path
|
|
|
|
VERSION = "4.11.0"
|
|
# platform -> (release asset, SHA-256 of the zip)
|
|
RELEASES = {
|
|
("Linux", "x86_64"): ("dafny-4.11.0-x64-ubuntu-22.04.zip", "a46a9ff7cdd720f7955854c78e95df13f4cfe6b80691b05f8654fe19e8267179"),
|
|
("Darwin", "arm64"): ("dafny-4.11.0-arm64-macos-13.zip", "c90c75e7d5db9c6ccbb7127840dfe43f0ac938b039a7ebed146d8ead383a572f"),
|
|
}
|
|
URL = "https://github.com/dafny-lang/dafny/releases/download/v{version}/{asset}"
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
TOOLS = ROOT / ".tools"
|
|
HOME = TOOLS / f"dafny-{VERSION}"
|
|
EXE = HOME / "dafny" / "dafny"
|
|
|
|
|
|
def release(system: str | None = None, machine: str | None = None) -> tuple[str, str]:
|
|
key = (system or platform.system(), machine or platform.machine())
|
|
if key not in RELEASES:
|
|
raise SystemExit(f"dafny: no pinned Dafny {VERSION} for {key[0]} {key[1]}; the pinned platforms are "
|
|
+ ", ".join(f"{s} {m}" for s, m in RELEASES))
|
|
return RELEASES[key]
|
|
|
|
|
|
def sha256(path: Path) -> str:
|
|
h = hashlib.sha256()
|
|
with path.open("rb") as f:
|
|
for block in iter(lambda: f.read(1 << 20), b""):
|
|
h.update(block)
|
|
return h.hexdigest()
|
|
|
|
|
|
def unpack(zip_path: Path, into: Path) -> None:
|
|
"""Unzip, keeping each file's Unix permission bits (zipfile drops them), so dafny and z3 stay executable."""
|
|
with zipfile.ZipFile(zip_path) as z:
|
|
for info in z.infolist():
|
|
target = into / info.filename
|
|
z.extract(info, into)
|
|
mode = (info.external_attr >> 16) & 0o777
|
|
if mode and not info.is_dir():
|
|
os.chmod(target, mode | stat.S_IRUSR)
|
|
|
|
|
|
def fetch(quiet: bool = False) -> Path:
|
|
"""Make sure the pinned Dafny is in .tools/, and return its executable."""
|
|
if EXE.exists():
|
|
return EXE
|
|
asset, want = release()
|
|
TOOLS.mkdir(exist_ok=True)
|
|
zip_path = TOOLS / asset
|
|
if not zip_path.exists() or sha256(zip_path) != want:
|
|
url = URL.format(version=VERSION, asset=asset)
|
|
if not quiet:
|
|
print(f"dafny: downloading {url}", file=sys.stderr)
|
|
part = zip_path.with_suffix(".part")
|
|
with urllib.request.urlopen(url) as r, part.open("wb") as f:
|
|
shutil.copyfileobj(r, f)
|
|
part.replace(zip_path)
|
|
got = sha256(zip_path)
|
|
if got != want:
|
|
zip_path.unlink()
|
|
raise SystemExit(f"dafny: {asset} has SHA-256 {got}, not the pinned {want}; refusing it")
|
|
staging = TOOLS / f".dafny-{VERSION}.unpacking"
|
|
shutil.rmtree(staging, ignore_errors=True)
|
|
unpack(zip_path, staging)
|
|
staging.replace(HOME)
|
|
zip_path.unlink()
|
|
if not quiet:
|
|
print(f"dafny: Dafny {VERSION} is in {HOME.relative_to(ROOT)}", file=sys.stderr)
|
|
return EXE
|
|
|
|
|
|
def main(argv: list[str]) -> int:
|
|
if argv[:1] == ["fetch"]:
|
|
fetch()
|
|
print(subprocess.run([str(EXE), "--version"], capture_output=True, text=True).stdout.strip())
|
|
return 0
|
|
if argv[:1] == ["path"]:
|
|
print(fetch(quiet=True))
|
|
return 0
|
|
exe = fetch()
|
|
return subprocess.run([str(exe), *argv]).returncode
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main(sys.argv[1:]))
|