nandi/jolt-nativepublic Fork 0
8cf1b3347ef6fa83297b6866dfd47d2728d4e339
Commits
Clone
git clone https://git.rickub.com/nandi/jolt-native.git
git clone ssh://git@rickub.com/nandi/jolt-native.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

dotslash-to-buck · 76 lines · 2.7 KBGDScript3 Blame HistoryRaw
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago1#!/usr/bin/env python3
2"""Generate buck2 http_archive data from the DotSlash files beside this script.
3
4DotSlash is where a tool's version, URL and digest are written down. buck needs
5the same three facts to fetch that tool itself — it cannot use the shim, which
6resolves on the machine at run time and so is neither an action input nor
7anything a remote worker could be given. Rather than write them twice and let
8them drift, this reads the manifests and emits the table buck reads.
9
10 just sync-dist # after editing any scripts/*.dotslash
11
12The DotSlash format is JSON with a `//` shebang line on top: one entry per
13platform, each with a url, a size, a digest and the path of the binary inside
14the archive. Only the archive itself is wanted here; the path inside it is the
15shim's business, and the toolchain rules name what they need.
16"""
17
18import json
19import pathlib
20import sys
21
22HERE = pathlib.Path(__file__).resolve().parent
23OUT = HERE.parent / "toolchains" / "dist" / "generated.bzl"
24
25# The tools buck fetches for itself. buck2 is not among them: it is the thing
26# doing the fetching, and dotslash is how a human gets it.
27TOOLS = {"zig": "zig", "rustc": "rust"}
28
29
30def load(path):
31 text = path.read_text()
32 return json.loads(text[text.index("{") :])
33
34
35def main():
36 entries = {}
37 for stem, name in sorted(TOOLS.items()):
38 for candidate in (HERE / f"{stem}.dotslash", HERE / stem):
39 if candidate.exists():
40 manifest = load(candidate)
41 break
42 else:
43 sys.exit(f"no DotSlash manifest for {stem}")
44
45 platforms = {}
46 for platform, entry in sorted(manifest["platforms"].items()):
47 if entry["hash"] != "sha256":
48 # http_archive takes sha256 and nothing else.
49 continue
50 url = entry["providers"][0]["url"]
51 # The path of the binary inside the archive starts with the
52 # directory the tarball unpacks into, which is what to strip.
53 platforms[platform] = {
54 "url": url,
55 "sha256": entry["digest"],
56 "strip_prefix": entry["path"].split("/")[0],
57 "type": entry["format"],
58 }
59 entries[name] = platforms
60
61 lines = [
62 "# @generated by scripts/dotslash-to-buck — do not edit.",
63 "#",
64 "# The same archives scripts/*.dotslash pins, as facts buck can act on.",
65 "# Bump the DotSlash file and run `just sync-dist`.",
66 "",
67 "DIST = " + json.dumps(entries, indent=4).replace(": true", ": True"),
68 "",
69 ]
70 OUT.parent.mkdir(parents=True, exist_ok=True)
71 OUT.write_text("\n".join(lines))
72 print(f"wrote {OUT.relative_to(HERE.parent)}")
73
74
75if __name__ == "__main__":
76 main()