Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::core::build_steps::gcc::GccTargetPair;
use crate::core::build_steps::tool::{
self, RustcPrivateCompilers, ToolTargetBuildMode, get_tool_target_compiler,
};
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor};
use crate::core::build_steps::vendor::Vendor;
use crate::core::build_steps::{compile, llvm};
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata};
use crate::core::config::{GccCiMode, TargetSelection};
Expand Down Expand Up @@ -1211,6 +1211,19 @@ impl Step for Src {
&dst_src,
);

// Vendor all Cargo dependencies
let vendor = builder.ensure(Vendor {
sync_args: vec![],
versioned_dirs: true,
root_dir: dst_src.clone(),
output_dir: None,
only_library_workspace: true,
});

let library_cargo_config_dir = dst_src.join("library").join(".cargo");
builder.create_dir(&library_cargo_config_dir);
builder.create(&library_cargo_config_dir.join("config.toml"), &vendor.config_library);

Comment on lines +1214 to +1226
Copy link
Copy Markdown
Contributor

@lambdageek lambdageek May 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm late to the party. Would it be reasonable to wrap this in something like if builder.config.dist_vendor { ... } so that it respects the --set dist.vendor=false bootstrap option similar to what's done for PlainSourceTarball

if builder.config.dist_vendor {

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dist.vendor currently does not affect any components that would be shipped to the end user as opposed to only be used for building rustc yourself. If the rust-src component also looked at dist.vendor, then a distro setting dist.vendor=false to avoid having to keep all non-Linux deps in the source tarball from which they build rustc would break offline rust-analyzer (and in the future offline -Zbuild-std) for their users.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks

tarball.generate()
}

Expand Down Expand Up @@ -1376,12 +1389,17 @@ fn prepare_source_tarball<'a>(
sync_args: pkgs_for_pgo_training.collect(),
versioned_dirs: true,
root_dir: plain_dst_src.into(),
output_dir: VENDOR_DIR.into(),
output_dir: None,
only_library_workspace: false,
});

let cargo_config_dir = plain_dst_src.join(".cargo");
builder.create_dir(&cargo_config_dir);
builder.create(&cargo_config_dir.join("config.toml"), &vendor.config);

let library_cargo_config_dir = plain_dst_src.join("library").join(".cargo");
builder.create_dir(&library_cargo_config_dir);
builder.create(&library_cargo_config_dir.join("config.toml"), &vendor.config_library);
}

// Delete extraneous directories
Expand Down
7 changes: 4 additions & 3 deletions src/bootstrap/src/core/build_steps/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use clap_complete::{Generator, shells};
use crate::core::build_steps::dist::distdir;
use crate::core::build_steps::test;
use crate::core::build_steps::tool::{self, RustcPrivateCompilers, SourceType, Tool};
use crate::core::build_steps::vendor::{Vendor, default_paths_to_vendor};
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor, default_paths_to_vendor};
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata};
use crate::core::config::TargetSelection;
use crate::core::config::flags::{get_completion, top_level_help};
Expand Down Expand Up @@ -275,9 +275,10 @@ impl Step for GenerateCopyright {
sync_args: Vec::new(),
versioned_dirs: true,
root_dir: builder.src.clone(),
output_dir: cache_dir.clone(),
output_dir: Some(cache_dir.clone()),
only_library_workspace: false,
});
cache_dir
cache_dir.join(VENDOR_DIR)
};

let _guard = builder.group("generate-copyright");
Expand Down
85 changes: 61 additions & 24 deletions src/bootstrap/src/core/build_steps/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ pub(crate) struct Vendor {
/// Determines whether vendored dependencies use versioned directories.
pub(crate) versioned_dirs: bool,
/// The root directory of the source code.
///
/// Vendored dependencies will be stored in <root_dir>/vendor and
/// <root_dir>/library/vendor unless overridden by `output_dir`.
pub(crate) root_dir: PathBuf,
/// The target directory for storing vendored dependencies.
pub(crate) output_dir: PathBuf,
/// The root directory for storing vendored dependencies in <output_dir>/vendor
/// and <output_dir>/library/vendor.
pub(crate) output_dir: Option<PathBuf>,
/// Only vendor crates necessary by the library workspace.
pub(crate) only_library_workspace: bool,
}

impl Step for Vendor {
Expand All @@ -68,7 +74,8 @@ impl Step for Vendor {
sync_args: run.builder.config.cmd.vendor_sync_args(),
versioned_dirs: run.builder.config.cmd.vendor_versioned_dirs(),
root_dir: run.builder.src.clone(),
output_dir: run.builder.src.join(VENDOR_DIR),
output_dir: None,
only_library_workspace: false,
});
}

Expand All @@ -79,45 +86,75 @@ impl Step for Vendor {
fn run(self, builder: &Builder<'_>) -> Self::Output {
let _guard = builder.group(&format!("Vendoring sources to {:?}", self.root_dir));

let mut cmd = command(&builder.initial_cargo);
cmd.arg("vendor");
let config = if self.only_library_workspace {
String::new()
} else {
let mut cmd = command(&builder.initial_cargo);
cmd.arg("vendor");

if self.versioned_dirs {
cmd.arg("--versioned-dirs");
}
if self.versioned_dirs {
cmd.arg("--versioned-dirs");
}

let to_vendor = default_paths_to_vendor(builder);
// These submodules must be present for `x vendor` to work.
for (_, submodules) in &to_vendor {
for submodule in submodules {
builder.build.require_submodule(submodule, None);
let to_vendor = default_paths_to_vendor(builder);
// These submodules must be present for `x vendor` to work.
for (_, submodules) in &to_vendor {
for submodule in submodules {
builder.build.require_submodule(submodule, None);
}
}
}

// Sync these paths by default.
for (p, _) in &to_vendor {
cmd.arg("--sync").arg(p);
}
// Sync these paths by default.
for (p, _) in &to_vendor {
cmd.arg("--sync").arg(p);
}

// Also sync explicitly requested paths.
for sync_arg in self.sync_args {
cmd.arg("--sync").arg(sync_arg);
// Also sync explicitly requested paths.
for sync_arg in self.sync_args {
cmd.arg("--sync").arg(sync_arg);
}

// Will read the libstd Cargo.toml
// which uses the unstable `public-dependency` feature.
cmd.env("RUSTC_BOOTSTRAP", "1");
cmd.env("RUSTC", &builder.initial_rustc);

cmd.current_dir(&self.root_dir);
match &self.output_dir {
None => cmd.arg(VENDOR_DIR),
Some(output_dir) => cmd.arg(output_dir.join(VENDOR_DIR)),
};

cmd.run_capture_stdout(builder).stdout()
};

let mut cmd = command(&builder.initial_cargo);
cmd.arg("vendor");

if self.versioned_dirs {
cmd.arg("--versioned-dirs");
}

// Will read the libstd Cargo.toml
// which uses the unstable `public-dependency` feature.
cmd.env("RUSTC_BOOTSTRAP", "1");
cmd.env("RUSTC", &builder.initial_rustc);

cmd.current_dir(self.root_dir).arg(&self.output_dir);
cmd.current_dir(self.root_dir.join("library"));
match &self.output_dir {
None => cmd.arg(VENDOR_DIR),
Some(output_dir) => cmd.arg(output_dir.join("library").join(VENDOR_DIR)),
};

let config_library = cmd.run_capture_stdout(builder).stdout();

let config = cmd.run_capture_stdout(builder);
VendorOutput { config: config.stdout() }
VendorOutput { config, config_library }
}
}

/// Stores the result of the vendoring step.
#[derive(Debug, Clone)]
pub(crate) struct VendorOutput {
pub(crate) config: String,
pub(crate) config_library: String,
}
Loading