nandi/jolt-nativepublic Fork 0
807f68183d34c39f2c251c5ad1ec50bb79005211
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 · 90 lines · 3.3 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.
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago27TOOLS = {
28 "zig": "zig",
29 "rustc": "rust",
30 "android-ndk": "android-ndk",
31 # Target-only: the same archive whatever the host, which is why
32 # every platform in that manifest carries the same digest.
33 "rust-std-android": "rust-std-android",
34 # Fetched so it can do the fetching, on a machine this one cannot upload
35 # three gigabytes to. See the manifest.
36 "dotslash": "dotslash",
37}
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago38
39
40def load(path):
41 text = path.read_text()
42 return json.loads(text[text.index("{") :])
43
44
45def main():
46 entries = {}
47 for stem, name in sorted(TOOLS.items()):
48 for candidate in (HERE / f"{stem}.dotslash", HERE / stem):
49 if candidate.exists():
50 manifest = load(candidate)
51 break
52 else:
53 sys.exit(f"no DotSlash manifest for {stem}")
54
55 platforms = {}
56 for platform, entry in sorted(manifest["platforms"].items()):
57 if entry["hash"] != "sha256":
58 # http_archive takes sha256 and nothing else.
59 continue
60 url = entry["providers"][0]["url"]
61 # The path of the binary inside the archive starts with the
62 # directory the tarball unpacks into, which is what to strip.
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago63 # A flat archive — one binary, no directory around it — has
64 # nothing to strip, and naming the binary would strip the whole
65 # payload.
66 head, _, rest = entry["path"].partition("/")
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago67 platforms[platform] = {
68 "url": url,
69 "sha256": entry["digest"],
Cross-compile for Android, with an NDK nobody has to install 14a30c0 nandi 19d ago70 "strip_prefix": head if rest else "",
Fetch rustc the way buck can ship it, from what DotSlash already pins 8cf1b33 nandi 19d ago71 "type": entry["format"],
72 }
73 entries[name] = platforms
74
75 lines = [
76 "# @generated by scripts/dotslash-to-buck — do not edit.",
77 "#",
78 "# The same archives scripts/*.dotslash pins, as facts buck can act on.",
79 "# Bump the DotSlash file and run `just sync-dist`.",
80 "",
81 "DIST = " + json.dumps(entries, indent=4).replace(": true", ": True"),
82 "",
83 ]
84 OUT.parent.mkdir(parents=True, exist_ok=True)
85 OUT.write_text("\n".join(lines))
86 print(f"wrote {OUT.relative_to(HERE.parent)}")
87
88
89if __name__ == "__main__":
90 main()