Skip to content

Write .cargo/config.toml in x vendor #144124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 3 additions & 7 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use tracing::instrument;

use crate::core::build_steps::doc::DocumentationFormat;
use crate::core::build_steps::tool::{self, Tool};
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::TargetSelection;
Expand Down Expand Up @@ -1138,16 +1138,12 @@ impl Step for PlainSourceTarball {
});

// Vendor all Cargo dependencies
let vendor = builder.ensure(Vendor {
builder.ensure(Vendor {
sync_args: pkgs_for_pgo_training.collect(),
versioned_dirs: true,
root_dir: plain_dst_src.into(),
output_dir: VENDOR_DIR.into(),
output_dir: None,
});

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);
}

// Delete extraneous directories
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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, 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};
use crate::core::config::TargetSelection;
use crate::core::config::flags::get_completion;
Expand Down Expand Up @@ -242,9 +242,9 @@ 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()),
});
cache_dir
cache_dir.join(VENDOR_DIR)
};

let mut cmd = builder.tool_cmd(Tool::GenerateCopyright);
Expand Down
30 changes: 17 additions & 13 deletions src/bootstrap/src/core/build_steps/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ pub(crate) struct Vendor {
pub(crate) versioned_dirs: bool,
/// The root directory of the source code.
pub(crate) root_dir: PathBuf,
/// The target directory for storing vendored dependencies.
pub(crate) output_dir: PathBuf,
/// The target directory for storing vendored dependencies if different from root_dir.
pub(crate) output_dir: Option<PathBuf>,
}

impl Step for Vendor {
type Output = VendorOutput;
type Output = ();
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this? GenerateCopyright can still make use of the final path, instead of having to know about VENDOR_DIR, which is an implementation detail of the vendor step.

Copy link
Member Author

Choose a reason for hiding this comment

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

VendorOutput only ever contained the data that should be written to .cargo/config.toml.

Copy link
Member

Choose a reason for hiding this comment

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

I don't like overwriting the config.toml file on disk (as per my other comment), but if we did that, we can at least return the path to the vendor directory from the step, to avoid other steps reaching for VENDOR_DIR.

const DEFAULT: bool = true;
const ONLY_HOSTS: bool = true;

Expand All @@ -64,15 +64,15 @@ 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,
});
}

/// Executes the vendoring process.
///
/// This function runs `cargo vendor` and ensures all required submodules
/// are initialized before vendoring begins.
fn run(self, builder: &Builder<'_>) -> Self::Output {
fn run(self, builder: &Builder<'_>) {
builder.info(&format!("Vendoring sources to {:?}", self.root_dir));

let mut cmd = command(&builder.initial_cargo);
Expand Down Expand Up @@ -105,15 +105,19 @@ impl Step for Vendor {
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).arg(if let Some(output_dir) = &self.output_dir {
output_dir.join(VENDOR_DIR)
} else {
// Make sure to use a relative path here to ensure dist tarballs
// can be unpacked to a different drectory.
VENDOR_DIR.into()
});

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

/// Stores the result of the vendoring step.
#[derive(Debug, Clone)]
pub(crate) struct VendorOutput {
pub(crate) config: String,
// Write .cargo/config.toml
let cargo_config_dir = self.output_dir.unwrap_or(self.root_dir).join(".cargo");
builder.create_dir(&cargo_config_dir);
builder.create(&cargo_config_dir.join("config.toml"), &config.stdout());
}
}
Loading