bootstrap/core/build_steps/
vendor.rs

1use std::path::PathBuf;
2
3use crate::core::build_steps::tool::SUBMODULES_FOR_RUSTBOOK;
4use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
5use crate::utils::exec::command;
6
7/// Returns the cargo workspaces to vendor for `x vendor` and dist tarballs.
8///
9/// Returns a `Vec` of `(path_to_manifest, submodules_required)` where
10/// `path_to_manifest` is the cargo workspace, and `submodules_required` is
11/// the set of submodules that must be available.
12pub fn default_paths_to_vendor(builder: &Builder<'_>) -> Vec<(PathBuf, Vec<&'static str>)> {
13    [
14        ("src/tools/cargo/Cargo.toml", vec!["src/tools/cargo"]),
15        ("src/tools/rust-analyzer/Cargo.toml", vec![]),
16        ("compiler/rustc_codegen_cranelift/Cargo.toml", vec![]),
17        ("compiler/rustc_codegen_gcc/Cargo.toml", vec![]),
18        ("library/Cargo.toml", vec![]),
19        ("src/bootstrap/Cargo.toml", vec![]),
20        ("src/tools/rustbook/Cargo.toml", SUBMODULES_FOR_RUSTBOOK.into()),
21        ("src/tools/rustc-perf/Cargo.toml", vec!["src/tools/rustc-perf"]),
22        ("src/tools/opt-dist/Cargo.toml", vec![]),
23        ("src/doc/book/packages/trpl/Cargo.toml", vec![]),
24    ]
25    .into_iter()
26    .map(|(path, submodules)| (builder.src.join(path), submodules))
27    .collect()
28}
29
30#[derive(Debug, Clone, Hash, PartialEq, Eq)]
31pub(crate) struct Vendor {
32    sync_args: Vec<PathBuf>,
33    versioned_dirs: bool,
34    root_dir: PathBuf,
35}
36
37impl Step for Vendor {
38    type Output = ();
39    const DEFAULT: bool = true;
40    const ONLY_HOSTS: bool = true;
41
42    fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
43        run.alias("placeholder").default_condition(true)
44    }
45
46    fn make_run(run: RunConfig<'_>) {
47        run.builder.ensure(Vendor {
48            sync_args: run.builder.config.cmd.vendor_sync_args(),
49            versioned_dirs: run.builder.config.cmd.vendor_versioned_dirs(),
50            root_dir: run.builder.src.clone(),
51        });
52    }
53
54    fn run(self, builder: &Builder<'_>) -> Self::Output {
55        let mut cmd = command(&builder.initial_cargo);
56        cmd.arg("vendor");
57
58        if self.versioned_dirs {
59            cmd.arg("--versioned-dirs");
60        }
61
62        let to_vendor = default_paths_to_vendor(builder);
63        // These submodules must be present for `x vendor` to work.
64        for (_, submodules) in &to_vendor {
65            for submodule in submodules {
66                builder.build.require_submodule(submodule, None);
67            }
68        }
69
70        // Sync these paths by default.
71        for (p, _) in &to_vendor {
72            cmd.arg("--sync").arg(p);
73        }
74
75        // Also sync explicitly requested paths.
76        for sync_arg in self.sync_args {
77            cmd.arg("--sync").arg(sync_arg);
78        }
79
80        // Will read the libstd Cargo.toml
81        // which uses the unstable `public-dependency` feature.
82        cmd.env("RUSTC_BOOTSTRAP", "1");
83
84        cmd.current_dir(self.root_dir);
85
86        cmd.run(builder);
87    }
88}