Skip to content

Commit 358aa51

Browse files
committed
Write .cargo/config.toml in x vendor
1 parent 6c0a912 commit 358aa51

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use tracing::instrument;
2121

2222
use crate::core::build_steps::doc::DocumentationFormat;
2323
use crate::core::build_steps::tool::{self, Tool};
24-
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor};
24+
use crate::core::build_steps::vendor::Vendor;
2525
use crate::core::build_steps::{compile, llvm};
2626
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata};
2727
use crate::core::config::TargetSelection;
@@ -1138,16 +1138,12 @@ impl Step for PlainSourceTarball {
11381138
});
11391139

11401140
// Vendor all Cargo dependencies
1141-
let vendor = builder.ensure(Vendor {
1141+
builder.ensure(Vendor {
11421142
sync_args: pkgs_for_pgo_training.collect(),
11431143
versioned_dirs: true,
11441144
root_dir: plain_dst_src.into(),
1145-
output_dir: VENDOR_DIR.into(),
1145+
output_dir: None,
11461146
});
1147-
1148-
let cargo_config_dir = plain_dst_src.join(".cargo");
1149-
builder.create_dir(&cargo_config_dir);
1150-
builder.create(&cargo_config_dir.join("config.toml"), &vendor.config);
11511147
}
11521148

11531149
// Delete extraneous directories

src/bootstrap/src/core/build_steps/run.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use clap_complete::{Generator, shells};
1010
use crate::core::build_steps::dist::distdir;
1111
use crate::core::build_steps::test;
1212
use crate::core::build_steps::tool::{self, SourceType, Tool};
13-
use crate::core::build_steps::vendor::{Vendor, default_paths_to_vendor};
13+
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor, default_paths_to_vendor};
1414
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
1515
use crate::core::config::TargetSelection;
1616
use crate::core::config::flags::get_completion;
@@ -242,9 +242,9 @@ impl Step for GenerateCopyright {
242242
sync_args: Vec::new(),
243243
versioned_dirs: true,
244244
root_dir: builder.src.clone(),
245-
output_dir: cache_dir.clone(),
245+
output_dir: Some(cache_dir.clone()),
246246
});
247-
cache_dir
247+
cache_dir.join(VENDOR_DIR)
248248
};
249249

250250
let mut cmd = builder.tool_cmd(Tool::GenerateCopyright);

src/bootstrap/src/core/build_steps/vendor.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ pub(crate) struct Vendor {
4646
pub(crate) versioned_dirs: bool,
4747
/// The root directory of the source code.
4848
pub(crate) root_dir: PathBuf,
49-
/// The target directory for storing vendored dependencies.
50-
pub(crate) output_dir: PathBuf,
49+
/// The target directory for storing vendored dependencies if different from root_dir.
50+
pub(crate) output_dir: Option<PathBuf>,
5151
}
5252

5353
impl Step for Vendor {
54-
type Output = VendorOutput;
54+
type Output = ();
5555
const DEFAULT: bool = true;
5656
const ONLY_HOSTS: bool = true;
5757

@@ -64,15 +64,15 @@ impl Step for Vendor {
6464
sync_args: run.builder.config.cmd.vendor_sync_args(),
6565
versioned_dirs: run.builder.config.cmd.vendor_versioned_dirs(),
6666
root_dir: run.builder.src.clone(),
67-
output_dir: run.builder.src.join(VENDOR_DIR),
67+
output_dir: None,
6868
});
6969
}
7070

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

7878
let mut cmd = command(&builder.initial_cargo);
@@ -105,15 +105,19 @@ impl Step for Vendor {
105105
cmd.env("RUSTC_BOOTSTRAP", "1");
106106
cmd.env("RUSTC", &builder.initial_rustc);
107107

108-
cmd.current_dir(self.root_dir).arg(&self.output_dir);
108+
cmd.current_dir(&self.root_dir).arg(if let Some(output_dir) = &self.output_dir {
109+
output_dir.join(VENDOR_DIR)
110+
} else {
111+
// Make sure to use a relative path here to ensure dist tarballs
112+
// can be unpacked to a different drectory.
113+
VENDOR_DIR.into()
114+
});
109115

110116
let config = cmd.run_capture_stdout(builder);
111-
VendorOutput { config: config.stdout() }
112-
}
113-
}
114117

115-
/// Stores the result of the vendoring step.
116-
#[derive(Debug, Clone)]
117-
pub(crate) struct VendorOutput {
118-
pub(crate) config: String,
118+
// Write .cargo/config.toml
119+
let cargo_config_dir = self.output_dir.unwrap_or(self.root_dir).join(".cargo");
120+
builder.create_dir(&cargo_config_dir);
121+
builder.create(&cargo_config_dir.join("config.toml"), &config.stdout());
122+
}
119123
}

0 commit comments

Comments
 (0)