Skip to content

Commit 0aaad9e

Browse files
committed
Auto merge of rust-lang#102565 - jyn514:refactor-build-manifest, r=Mark-Simulacrum
Refactor build-manifest to minimize the number of changes needed to add a new component - Add all components to `PkgType` - Automate functionality wherever possible, so functions often don't have to be manually edited - Where that's not possible, use exhaustive matches on `PkgType` instead of adding individual strings. - Add documentation for how to add a component. Improve the existing documentation for how to test changes. I tested locally that this generates an identical manifest before and after my change, as follows: ```sh git checkout d44e142 cargo +nightly run --manifest-path src/tools/build-manifest/Cargo.toml build/dist build/manifest-before 1970-01-01 http://example.com nightly git checkout refactor-build-manifest cargo +nightly run --manifest-path src/tools/build-manifest/Cargo.toml build/dist build/manifest-before 1970-01-01 http://example.com nightly sort -u build/manifest-before/channel-rust-nightly.toml | diff - <(sort -u build/manifest-after/channel-rust-nightly.toml) ``` I then verified by hand that the differences before sorting are inconsequential (mostly targets being slightly reordered). The only change in behavior is that `llvm-tools` is now properly renamed to `llvm-tools-preview`: ``` ; sort -u build/manifest-before/channel-rust-nightly.toml | diff - <(sort -u build/manifest-after/channel-rust-nightly.toml) 784a785 > [renames.llvm-tools] 894a896 > to = "llvm-tools-preview" ``` This is based on rust-lang#102241 and should not be merged before.
2 parents d22c433 + 8810174 commit 0aaad9e

File tree

4 files changed

+208
-181
lines changed

4 files changed

+208
-181
lines changed

src/tools/build-manifest/README.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
# build-manifest
22

3-
This tool generates the manifests uploaded to static.rust-lang.org and used by
4-
rustup. The tool is invoked by the bootstrap tool.
3+
This tool generates the manifests uploaded to static.rust-lang.org and used by rustup.
4+
You can see a full list of all manifests at <https://static.rust-lang.org/manifests.txt>.
5+
This listing is updated by <https://github.com/rust-lang/generate-manifest-list> every 7 days.
6+
7+
This gets called by `promote-release` <https://github.com/rust-lang/promote-release> via `x.py dist hash-and-sign`.
8+
9+
## Adding a new component
10+
11+
1. Add a new `Step` to `dist.rs`. This should usually be named after the filename of the uploaded tarball. See https://github.com/rust-lang/rust/pull/101799/files#diff-2c56335faa24486df09ba392d8900c57e2fac4633e1f7038469bcf9ed3feb871 for an example.
12+
a. If appropriate, call `tarball.is_preview(true)` for the component.
13+
2. Add a new `PkgType` to build-manifest. Fix all the compile errors as appropriate.
514

615
## Testing changes locally
716

817
In order to test the changes locally you need to have a valid dist directory
918
available locally. If you don't want to build all the compiler, you can easily
1019
create one from the nightly artifacts with:
1120

12-
```
13-
#!/bin/bash
14-
for cmpn in rust rustc rust-std rust-docs cargo; do
15-
wget https://static.rust-lang.org/dist/${cmpn}-nightly-x86_64-unknown-linux-gnu.tar.gz
21+
```sh
22+
for component in rust rustc rust-std rust-docs cargo; do
23+
wget -P build/dist https://static.rust-lang.org/dist/${component}-nightly-x86_64-unknown-linux-gnu.tar.gz
1624
done
1725
```
1826

19-
Then, you can generate the manifest and all the packages from `path/to/dist` to
20-
`path/to/output` with:
27+
Then, you can generate the manifest and all the packages from `build/dist` to
28+
`build/manifest` with:
2129

30+
```sh
31+
mkdir -p build/manifest
32+
cargo +nightly run --release -p build-manifest build/dist build/manifest 1970-01-01 http://example.com nightly
2233
```
23-
$ cargo +nightly run path/to/dist path/to/output 1970-01-01 http://example.com CHANNEL
24-
```
25-
26-
Remember to replace `CHANNEL` with the channel you produced dist artifacts of
27-
and `VERSION` with the current Rust version.

src/tools/build-manifest/src/main.rs

+92-120
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
//! Build a dist manifest, hash and sign everything.
2-
//! This gets called by `promote-release`
3-
//! (https://github.com/rust-lang/rust-central-station/tree/master/promote-release)
4-
//! via `x.py dist hash-and-sign`; the cmdline arguments are set up
5-
//! by rustbuild (in `src/bootstrap/dist.rs`).
1+
#![doc = include_str!("../README.md")]
62

73
mod checksum;
84
mod manifest;
@@ -184,7 +180,7 @@ static PKG_INSTALLERS: &[&str] = &["x86_64-apple-darwin", "aarch64-apple-darwin"
184180

185181
static MINGW: &[&str] = &["i686-pc-windows-gnu", "x86_64-pc-windows-gnu"];
186182

187-
static NIGHTLY_ONLY_COMPONENTS: &[&str] = &["miri-preview", "rust-docs-json-preview"];
183+
static NIGHTLY_ONLY_COMPONENTS: &[PkgType] = &[PkgType::Miri, PkgType::JsonDocs];
188184

189185
macro_rules! t {
190186
($e:expr) => {
@@ -287,28 +283,9 @@ impl Builder {
287283
}
288284

289285
fn add_packages_to(&mut self, manifest: &mut Manifest) {
290-
macro_rules! package {
291-
($name:expr, $targets:expr) => {
292-
self.package($name, &mut manifest.pkg, $targets, &[])
293-
};
286+
for pkg in PkgType::all() {
287+
self.package(pkg, &mut manifest.pkg);
294288
}
295-
package!("rustc", HOSTS);
296-
package!("rustc-dev", HOSTS);
297-
package!("reproducible-artifacts", HOSTS);
298-
package!("rustc-docs", HOSTS);
299-
package!("cargo", HOSTS);
300-
package!("rust-mingw", MINGW);
301-
package!("rust-std", TARGETS);
302-
self.package("rust-docs", &mut manifest.pkg, HOSTS, DOCS_FALLBACK);
303-
self.package("rust-docs-json-preview", &mut manifest.pkg, HOSTS, DOCS_FALLBACK);
304-
package!("rust-src", &["*"]);
305-
package!("rls-preview", HOSTS);
306-
package!("rust-analyzer-preview", HOSTS);
307-
package!("clippy-preview", HOSTS);
308-
package!("miri-preview", HOSTS);
309-
package!("rustfmt-preview", HOSTS);
310-
package!("rust-analysis", TARGETS);
311-
package!("llvm-tools-preview", TARGETS);
312289
}
313290

314291
fn add_artifacts_to(&mut self, manifest: &mut Manifest) {
@@ -333,44 +310,28 @@ impl Builder {
333310
}
334311

335312
fn add_profiles_to(&mut self, manifest: &mut Manifest) {
336-
let mut profile = |name, pkgs| self.profile(name, &mut manifest.profiles, pkgs);
337-
profile("minimal", &["rustc", "cargo", "rust-std", "rust-mingw"]);
338-
profile(
339-
"default",
340-
&[
341-
"rustc",
342-
"cargo",
343-
"rust-std",
344-
"rust-mingw",
345-
"rust-docs",
346-
"rustfmt-preview",
347-
"clippy-preview",
348-
],
349-
);
350-
profile(
351-
"complete",
352-
&[
353-
"rustc",
354-
"cargo",
355-
"rust-std",
356-
"rust-mingw",
357-
"rust-docs",
358-
"rustfmt-preview",
359-
"clippy-preview",
360-
"rls-preview",
361-
"rust-analyzer-preview",
362-
"rust-src",
363-
"llvm-tools-preview",
364-
"rust-analysis",
365-
"miri-preview",
366-
],
367-
);
313+
use PkgType::*;
314+
315+
let mut profile = |name, pkgs: &_| self.profile(name, &mut manifest.profiles, pkgs);
316+
317+
// Use a Vec here to make sure we don't exclude any components in an earlier profile.
318+
let minimal = vec![Rustc, Cargo, RustStd, RustMingw];
319+
profile("minimal", &minimal);
320+
321+
let mut default = minimal;
322+
default.extend([HtmlDocs, Rustfmt, Clippy]);
323+
profile("default", &default);
324+
325+
// NOTE: this profile is effectively deprecated; do not add new components to it.
326+
let mut complete = default;
327+
complete.extend([Rls, RustAnalyzer, RustSrc, LlvmTools, RustAnalysis, Miri]);
328+
profile("complete", &complete);
368329

369330
// The compiler libraries are not stable for end users, and they're also huge, so we only
370331
// `rustc-dev` for nightly users, and only in the "complete" profile. It's still possible
371332
// for users to install the additional component manually, if needed.
372333
if self.versions.channel() == "nightly" {
373-
self.extend_profile("complete", &mut manifest.profiles, &["rustc-dev"]);
334+
self.extend_profile("complete", &mut manifest.profiles, &[RustcDev]);
374335
// Do not include the rustc-docs component for now, as it causes
375336
// conflicts with the rust-docs component when installed. See
376337
// #75833.
@@ -382,12 +343,11 @@ impl Builder {
382343
let mut rename = |from: &str, to: &str| {
383344
manifest.renames.insert(from.to_owned(), Rename { to: to.to_owned() })
384345
};
385-
rename("rls", "rls-preview");
386-
rename("rustfmt", "rustfmt-preview");
387-
rename("clippy", "clippy-preview");
388-
rename("miri", "miri-preview");
389-
rename("rust-docs-json", "rust-docs-json-preview");
390-
rename("rust-analyzer", "rust-analyzer-preview");
346+
for pkg in PkgType::all() {
347+
if pkg.is_preview() {
348+
rename(pkg.tarball_component_name(), &pkg.manifest_component_name());
349+
}
350+
}
391351
}
392352

393353
fn rust_package(&mut self, manifest: &Manifest) -> Package {
@@ -419,42 +379,52 @@ impl Builder {
419379
let mut components = Vec::new();
420380
let mut extensions = Vec::new();
421381

422-
let host_component = |pkg| Component::from_str(pkg, host);
423-
424-
// rustc/rust-std/cargo/docs are all required,
425-
// and so is rust-mingw if it's available for the target.
426-
components.extend(vec![
427-
host_component("rustc"),
428-
host_component("rust-std"),
429-
host_component("cargo"),
430-
host_component("rust-docs"),
431-
]);
432-
if host.contains("pc-windows-gnu") {
433-
components.push(host_component("rust-mingw"));
434-
}
382+
let host_component = |pkg: &_| Component::from_pkg(pkg, host);
435383

436-
// Tools are always present in the manifest,
437-
// but might be marked as unavailable if they weren't built.
438-
extensions.extend(vec![
439-
host_component("clippy-preview"),
440-
host_component("miri-preview"),
441-
host_component("rls-preview"),
442-
host_component("rust-analyzer-preview"),
443-
host_component("rustfmt-preview"),
444-
host_component("llvm-tools-preview"),
445-
host_component("rust-analysis"),
446-
host_component("rust-docs-json-preview"),
447-
]);
448-
449-
extensions.extend(
450-
TARGETS
451-
.iter()
452-
.filter(|&&target| target != host)
453-
.map(|target| Component::from_str("rust-std", target)),
454-
);
455-
extensions.extend(HOSTS.iter().map(|target| Component::from_str("rustc-dev", target)));
456-
extensions.extend(HOSTS.iter().map(|target| Component::from_str("rustc-docs", target)));
457-
extensions.push(Component::from_str("rust-src", "*"));
384+
for pkg in PkgType::all() {
385+
match pkg {
386+
// rustc/rust-std/cargo/docs are all required
387+
PkgType::Rustc | PkgType::Cargo | PkgType::HtmlDocs => {
388+
components.push(host_component(pkg));
389+
}
390+
PkgType::RustStd => {
391+
components.push(host_component(pkg));
392+
extensions.extend(
393+
TARGETS
394+
.iter()
395+
.filter(|&&target| target != host)
396+
.map(|target| Component::from_pkg(pkg, target)),
397+
);
398+
}
399+
// so is rust-mingw if it's available for the target
400+
PkgType::RustMingw => {
401+
if host.contains("pc-windows-gnu") {
402+
components.push(host_component(pkg));
403+
}
404+
}
405+
// Tools are always present in the manifest,
406+
// but might be marked as unavailable if they weren't built.
407+
PkgType::Clippy
408+
| PkgType::Miri
409+
| PkgType::Rls
410+
| PkgType::RustAnalyzer
411+
| PkgType::Rustfmt
412+
| PkgType::LlvmTools
413+
| PkgType::RustAnalysis
414+
| PkgType::JsonDocs => {
415+
extensions.push(host_component(pkg));
416+
}
417+
PkgType::RustcDev | PkgType::RustcDocs => {
418+
extensions.extend(HOSTS.iter().map(|target| Component::from_pkg(pkg, target)));
419+
}
420+
PkgType::RustSrc => {
421+
extensions.push(Component::from_pkg(pkg, "*"));
422+
}
423+
PkgType::Rust => {}
424+
// NOTE: this is intentional, these artifacts aren't intended to be used with rustup
425+
PkgType::ReproducibleArtifacts => {}
426+
}
427+
}
458428

459429
// If the components/extensions don't actually exist for this
460430
// particular host/target combination then nix it entirely from our
@@ -481,43 +451,44 @@ impl Builder {
481451
&mut self,
482452
profile_name: &str,
483453
dst: &mut BTreeMap<String, Vec<String>>,
484-
pkgs: &[&str],
454+
pkgs: &[PkgType],
485455
) {
486-
dst.insert(profile_name.to_owned(), pkgs.iter().map(|s| (*s).to_owned()).collect());
456+
dst.insert(
457+
profile_name.to_owned(),
458+
pkgs.iter().map(|s| s.manifest_component_name()).collect(),
459+
);
487460
}
488461

489462
fn extend_profile(
490463
&mut self,
491464
profile_name: &str,
492465
dst: &mut BTreeMap<String, Vec<String>>,
493-
pkgs: &[&str],
466+
pkgs: &[PkgType],
494467
) {
495468
dst.get_mut(profile_name)
496469
.expect("existing profile")
497-
.extend(pkgs.iter().map(|s| (*s).to_owned()));
470+
.extend(pkgs.iter().map(|s| s.manifest_component_name()));
498471
}
499472

500-
fn package(
501-
&mut self,
502-
pkgname: &str,
503-
dst: &mut BTreeMap<String, Package>,
504-
targets: &[&str],
505-
fallback: &[(&str, &str)],
506-
) {
507-
let version_info = self
508-
.versions
509-
.version(&PkgType::from_component(pkgname))
510-
.expect("failed to load package version");
473+
fn package(&mut self, pkg: &PkgType, dst: &mut BTreeMap<String, Package>) {
474+
if *pkg == PkgType::Rust {
475+
// This is handled specially by `rust_package` later.
476+
// Order is important, so don't call `rust_package` here.
477+
return;
478+
}
479+
480+
let fallback = if pkg.use_docs_fallback() { DOCS_FALLBACK } else { &[] };
481+
let version_info = self.versions.version(&pkg).expect("failed to load package version");
511482
let mut is_present = version_info.present;
512483

513484
// Never ship nightly-only components for other trains.
514-
if self.versions.channel() != "nightly" && NIGHTLY_ONLY_COMPONENTS.contains(&pkgname) {
485+
if self.versions.channel() != "nightly" && NIGHTLY_ONLY_COMPONENTS.contains(&pkg) {
515486
is_present = false; // Pretend the component is entirely missing.
516487
}
517488

518489
macro_rules! tarball_name {
519490
($target_name:expr) => {
520-
self.versions.tarball_name(&PkgType::from_component(pkgname), $target_name).unwrap()
491+
self.versions.tarball_name(pkg, $target_name).unwrap()
521492
};
522493
}
523494
let mut target_from_compressed_tar = |target_name| {
@@ -546,7 +517,8 @@ impl Builder {
546517
Target::unavailable()
547518
};
548519

549-
let targets = targets
520+
let targets = pkg
521+
.targets()
550522
.iter()
551523
.map(|name| {
552524
let target = if is_present {
@@ -561,7 +533,7 @@ impl Builder {
561533
.collect();
562534

563535
dst.insert(
564-
pkgname.to_string(),
536+
pkg.manifest_component_name(),
565537
Package {
566538
version: version_info.version.unwrap_or_default(),
567539
git_commit_hash: version_info.git_commit,

src/tools/build-manifest/src/manifest.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::versions::PkgType;
12
use crate::Builder;
23
use serde::{Serialize, Serializer};
34
use std::collections::BTreeMap;
@@ -116,8 +117,8 @@ pub(crate) struct Component {
116117
}
117118

118119
impl Component {
119-
pub(crate) fn from_str(pkg: &str, target: &str) -> Self {
120-
Self { pkg: pkg.to_string(), target: target.to_string() }
120+
pub(crate) fn from_pkg(pkg: &PkgType, target: &str) -> Self {
121+
Self { pkg: pkg.manifest_component_name(), target: target.to_string() }
121122
}
122123
}
123124

0 commit comments

Comments
 (0)