From 8c2796d37866c7e53250e6824bf4c11171d9b184 Mon Sep 17 00:00:00 2001 From: oxalica Date: Sun, 4 Apr 2021 01:17:15 +0800 Subject: [PATCH] Store profiles in manifests --- manifest.nix | 32 ++++++++++++++++++++++++++------ manifests/profiles.nix | 3 +++ scripts/fetch.py | 23 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 manifests/profiles.nix diff --git a/manifest.nix b/manifest.nix index 51bb86b5e2c..f69d565e809 100644 --- a/manifest.nix +++ b/manifest.nix @@ -4,6 +4,7 @@ with builtins; let targets = import ./manifests/targets.nix // { _ = "*"; }; renamesList = import ./manifests/renames.nix; + profilesList = import ./manifests/profiles.nix; inherit (final.rust-bin) distRoot; @@ -43,15 +44,23 @@ let # Uncompress the compressed manifest to the original one # (not complete but has enough information to make up the toolchain). uncompressManifest = channel: version: { - v, # rustc version - d, # date - r, # rename index + v, # Rustc version + d, # Date + r, # Renames index + p ? null, # Profiles index ... }@manifest: rec { + + # Version used for derivation. + version = if builtins.match ".*(nightly|beta).*" v != null + then "${v}-${d}" # 1.51.0-nightly-2021-01-01, 1.52.0-beta.2-2021-03-27 + else v; # 1.51.0 + date = d; renames = mapAttrs (from: to: { inherit to; }) (elemAt renamesList r); + pkg = - mapAttrs (pkgName: { u ? null /* url version */, ... }@hashes: { + mapAttrs (pkgName: { u ? null /* Version appears in URL */, ... }@hashes: { # We use rustc version for all components to reduce manifest size. # This version is just used for component derivation name. version = "${v} (000000000 ${d})"; # " ( yyyy-mm-dd)" @@ -61,7 +70,7 @@ let pkgNameStripped = removeSuffix "-preview" pkgName; targetTail = if targetIdx == "_" then "" else "-" + target; urlVersion = - if u != null then u # Use specified url version if exists. + if u != null then u # Use specified version for URL if exists. else if channel == "stable" then v # For stable channel, default to be rustc version. else channel; # Otherwise, for beta/nightly channel, default to be "beta"/"nightly". in { @@ -71,7 +80,18 @@ let xz_hash = hash; } // (if pkgName == "rust" then rustPkgExtra pkg target else {}); }) (removeAttrs hashes ["u"]); - }) (removeAttrs manifest ["v" "d" "r"]); + }) (removeAttrs manifest ["v" "d" "r" "p"]); + + profiles = if p == null + then {} + # `rust-mingw` is in each profile but doesn't support platforms other than Windows. + else mapAttrs (name: remove "rust-mingw") (elemAt profilesList p); + + targetComponentsList = [ + "rust-std" + "rustc-dev" + "rustc-docs" + ]; }; uncompressManifestSet = channel: set: let diff --git a/manifests/profiles.nix b/manifests/profiles.nix new file mode 100644 index 00000000000..583b8b45e3c --- /dev/null +++ b/manifests/profiles.nix @@ -0,0 +1,3 @@ +[ + { complete = [ "rustc" "cargo" "rust-std" "rust-mingw" "rust-docs" "rustfmt-preview" "clippy-preview" "rls-preview" "rust-analyzer-preview" "rust-src" "llvm-tools-preview" "rust-analysis" "miri-preview" ]; default = [ "rustc" "cargo" "rust-std" "rust-mingw" "rust-docs" "rustfmt-preview" "clippy-preview" ]; minimal = [ "rustc" "cargo" "rust-std" "rust-mingw" ]; } +] diff --git a/scripts/fetch.py b/scripts/fetch.py index 071cab7ddb2..ae27d40fb67 100755 --- a/scripts/fetch.py +++ b/scripts/fetch.py @@ -24,6 +24,7 @@ NIX_KEYWORDS = {'', 'if', 'then', 'else', 'assert', 'with', 'let', 'in', 'rec', MANIFEST_TMP_PATH = Path('manifest.tmp') TARGETS_PATH = Path('manifests/targets.nix') RENAMES_PATH = Path('manifests/renames.nix') +PROFILES_PATH = Path('manifests/profiles.nix') RE_STABLE_VERSION = re.compile(r'^\d+\.\d+\.\d+$') @@ -86,6 +87,25 @@ def compress_renames(renames: dict) -> int: f.write(']\n') return idx +profiles_map = dict((line.strip(), i) for i, line in enumerate(PROFILES_PATH.read_text().strip().split('\n')[1:-1])) +def compress_profiles(profiles: dict) -> int: + serialized = '{ ' + ''.join( + escape_nix_key(k) + ' = [ ' + ''.join(escape_nix_string(comp) + ' ' for comp in v) + ']; ' + for k, v in sorted(profiles.items()) + ) + '}' + + if serialized in profiles_map: + return profiles_map[serialized] + idx = len(profiles_map) + profiles_map[serialized] = idx + + with open(str(PROFILES_PATH), 'w') as f: + f.write('[\n') + for _, ser in sorted((idx, ser) for ser, idx in profiles_map.items()): + f.write(' ' + ser + '\n') + f.write(']\n') + return idx + def fetch_url(url: str, params=None, allow_not_found=False): i = 0 while True: @@ -116,6 +136,9 @@ def translate_dump_manifest(channel: str, manifest: str, f): f.write(f'v={escape_nix_string(rustc_version)};') f.write(f'd={escape_nix_string(date)};') f.write(f'r={renames_idx};') + if 'profiles' in manifest: + f.write(f'p={compress_profiles(manifest["profiles"])};') + for pkg_name in sorted(manifest['pkg'].keys()): pkg = manifest['pkg'][pkg_name] pkg_name_stripped = pkg_name[:-len(strip_tail)] if pkg_name.endswith(strip_tail) else pkg_name