Skip to content

Commit d2c600d

Browse files
committed
add fenix.{fromManifest,fromManifestFile,toolchainOf}
rewrite stable and beta toolchains close #16
1 parent 9de3368 commit d2c600d

File tree

8 files changed

+44333
-57
lines changed

8 files changed

+44333
-57
lines changed

.github/workflows/update.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@ jobs:
2525
git config --local user.email "[email protected]"
2626
2727
nix-shell --run ./update -p "python3.withPackages (ps: [ ps.toml ])"
28-
if [ -n "$(git diff)" ]; then
29-
git commit -am "update toolchains"
30-
fi
3128
32-
nix flake update --commit-lock-file
29+
nix flake update
30+
31+
curl -fLSso data/stable.toml https://static.rust-lang.org/dist/channel-rust-stable.toml
32+
curl -fLSso data/beta.toml https://static.rust-lang.org/dist/channel-rust-beta.toml
3333
3434
curl -fLSso data/rust-analyzer-vsix.zip \
3535
https://github.com/rust-analyzer/rust-analyzer/releases/download/nightly/rust-analyzer.vsix || true
36-
if [ -n "$(git diff)" ]; then
37-
git commit -am "update rust analyzer vscode extension"
38-
fi
36+
37+
git commit -am "update rust analyzer vscode extension"
3938
4039
- name: Push changes
4140
uses: ad-m/github-push-action@master

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ As a flake (recommended)
3535
# fenix.packages.x86_64-linux.minimal.toolchain
3636
# fenix.packages.x86_64-linux.stable.defaultToolchain
3737
# fenix.packages.x86_64-linux.beta.completeToolchain
38+
# fenix.packages.x86_64-linux.fromManifest (import ./channel-rust-nightly.nix)
39+
# fenix.packages.x86_64-apple-darwin.fromManifestFile ./channel-rust-stable.toml
40+
# fenix.packages.aarch64-linux.toolchainOf { date = "2021-07-01"; sha256 = ""; }
41+
# fenix.packages.x86_64-linux.toolchainOf { channel = "stable"; date = "2021-06-17"; sha256 = ""; }
3842
# fenix.packages.x86_64-linux.targets.aarch64-unknown-linux-gnu.latest.rust-std
3943
# fenix.packages.x86_64-linux.targets.wasm32-unknown-unknown.stable.rust-std
4044
# fenix.packages.x86_64-linux.rust-analyzer

data/beta.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/beta.toml

Lines changed: 22253 additions & 0 deletions
Large diffs are not rendered by default.

data/stable.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

data/stable.toml

Lines changed: 22020 additions & 0 deletions
Large diffs are not rendered by default.

flake.nix

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,69 @@
2121
mapAttrs (k: v:
2222
let
2323
pkgs = nixpkgs.legacyPackages.${k};
24+
2425
mkToolchain = pkgs.callPackage ./lib/mk-toolchain.nix { };
26+
2527
nightlyToolchains = mapAttrs
2628
(_: mapAttrs (profile: mkToolchain "rust-nightly-${profile}"))
2729
(fromJSON (readFile ./data/nightly.json));
30+
31+
fromManifest' = target: name: manifest:
32+
let
33+
toolchain = mkToolchain name {
34+
inherit (manifest) date;
35+
components = mapAttrs (_: src: {
36+
inherit (src) url;
37+
sha256 = src.hash;
38+
}) (filterAttrs (_: src: src ? available && src.available)
39+
(mapAttrs (component: pkg:
40+
if pkg.target ? "*" then
41+
pkg.target."*"
42+
else if pkg.target ? ${target} then
43+
pkg.target.${target}
44+
else
45+
null) manifest.pkg));
46+
};
47+
in toolchain // mapAttrs' (k: v:
48+
nameValuePair "${k}Toolchain" (toolchain.withComponents
49+
(filter (component: toolchain ? ${component}) v)))
50+
manifest.profiles;
51+
52+
fromManifestFile' = target: name: file:
53+
fromManifest' target name (fromTOML (readFile file));
54+
55+
toolchainOf' = target:
56+
{ root ? "https://static.rust-lang.org/dist", channel ? "nightly"
57+
, date, sha256 }:
58+
fromManifestFile' target "rust-${channel}" (fetchurl {
59+
inherit sha256;
60+
url = "${root}/${date}/channel-rust-${channel}.toml";
61+
});
62+
2863
mkToolchains = channel:
29-
let manifest = fromJSON (readFile (./data + "/${channel}.json"));
30-
in mapAttrs (_: components:
31-
let
32-
toolchain = mkToolchain "rust-${channel}" {
33-
inherit (manifest) date;
34-
inherit components;
35-
};
36-
in toolchain // mapAttrs' (k: v:
37-
nameValuePair "${k}Toolchain" (toolchain.withComponents
38-
(filter (component: hasAttr component toolchain) v)))
39-
manifest.profiles) manifest.targets;
40-
stableToolchains = mkToolchains "stable";
41-
betaToolchains = mkToolchains "beta";
64+
let manifest = fromTOML (readFile (./data + "/${channel}.toml"));
65+
in mapAttrs (target: _: {
66+
${channel} = fromManifest' target "rust-${channel}" manifest;
67+
}) manifest.pkg.rust-std.target;
68+
4269
rust-analyzer-rev = substring 0 7 (fromJSON
4370
(readFile ./flake.lock)).nodes.rust-analyzer-src.locked.rev;
4471
in nightlyToolchains.${v} // rec {
4572
combine = pkgs.callPackage ./lib/combine.nix { } "rust-mixed";
4673

47-
stable = stableToolchains.${v};
74+
fromManifest = fromManifest' v "rust";
75+
76+
fromManifestFile = fromManifestFile' v "rust";
77+
78+
toolchainOf = toolchainOf' v;
79+
80+
stable = fromManifestFile' v "rust-stable" ./data/stable.toml;
4881

49-
beta = betaToolchains.${v};
82+
beta = fromManifestFile' v "rust-beta" ./data/beta.toml;
5083

5184
targets = zipAttrsWith (_: foldl (x: y: x // y) { }) [
52-
(mapAttrs (_: toolchain: { stable = toolchain; }) stableToolchains)
53-
(mapAttrs (_: toolchain: { beta = toolchain; }) betaToolchains)
85+
(mkToolchains "stable")
86+
(mkToolchains "beta")
5487
nightlyToolchains
5588
];
5689

update

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -153,34 +153,3 @@ def fetch_nightly(d = None):
153153

154154
fetch_nightly()
155155
json.dump(nightly, open("data/nightly.json", "w"))
156-
157-
for channel in ["stable", "beta"]:
158-
resp = urlopen(f"{dist_root}/channel-rust-{channel}.toml")
159-
manifest = toml.loads(resp.read().decode("utf-8"))
160-
results = {
161-
"date": manifest["date"],
162-
"targets": { target: {} for target in targets },
163-
"profiles": { profile: manifest["profiles"][profile] for profile in profiles },
164-
}
165-
pkgs = manifest["pkg"]
166-
167-
for component, pkg in pkgs.items():
168-
pkg = pkg["target"]
169-
for target in targets:
170-
src = pkg.get("*") or pkg.get(target)
171-
if src and src["available"]:
172-
results["targets"][target][component] = {
173-
"url": src["url"],
174-
"sha256": src["hash"],
175-
}
176-
177-
for target, src in pkgs["rust-std"]["target"].items():
178-
if src["available"] and not target in targets:
179-
results["targets"][target] = {
180-
"rust-std": {
181-
"url": src["url"],
182-
"sha256": src["hash"],
183-
},
184-
}
185-
186-
json.dump(results, open(f"data/{channel}.json", "w"))

0 commit comments

Comments
 (0)