Skip to content

Commit 4f1ae3c

Browse files
committed
Write .cargo/config.toml in x vendor
1 parent ab1d244 commit 4f1ae3c

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
@@ -24,7 +24,7 @@ use crate::core::build_steps::doc::DocumentationFormat;
2424
use crate::core::build_steps::tool::{
2525
self, RustcPrivateCompilers, Tool, ToolTargetBuildMode, get_tool_target_compiler,
2626
};
27-
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor};
27+
use crate::core::build_steps::vendor::Vendor;
2828
use crate::core::build_steps::{compile, llvm};
2929
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata};
3030
use crate::core::config::TargetSelection;
@@ -1271,16 +1271,12 @@ impl Step for PlainSourceTarball {
12711271
});
12721272

12731273
// Vendor all Cargo dependencies
1274-
let vendor = builder.ensure(Vendor {
1274+
builder.ensure(Vendor {
12751275
sync_args: pkgs_for_pgo_training.collect(),
12761276
versioned_dirs: true,
12771277
root_dir: plain_dst_src.into(),
1278-
output_dir: VENDOR_DIR.into(),
1278+
output_dir: None,
12791279
});
1280-
1281-
let cargo_config_dir = plain_dst_src.join(".cargo");
1282-
builder.create_dir(&cargo_config_dir);
1283-
builder.create(&cargo_config_dir.join("config.toml"), &vendor.config);
12841280
}
12851281

12861282
// 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
@@ -12,7 +12,7 @@ use clap_complete::{Generator, shells};
1212
use crate::core::build_steps::dist::distdir;
1313
use crate::core::build_steps::test;
1414
use crate::core::build_steps::tool::{self, RustcPrivateCompilers, SourceType, Tool};
15-
use crate::core::build_steps::vendor::{Vendor, default_paths_to_vendor};
15+
use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor, default_paths_to_vendor};
1616
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata};
1717
use crate::core::config::TargetSelection;
1818
use crate::core::config::flags::{get_completion, top_level_help};
@@ -269,9 +269,9 @@ impl Step for GenerateCopyright {
269269
sync_args: Vec::new(),
270270
versioned_dirs: true,
271271
root_dir: builder.src.clone(),
272-
output_dir: cache_dir.clone(),
272+
output_dir: Some(cache_dir.clone()),
273273
});
274-
cache_dir
274+
cache_dir.join(VENDOR_DIR)
275275
};
276276

277277
let _guard = builder.group("generate-copyright");

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

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

5454
impl Step for Vendor {
55-
type Output = VendorOutput;
55+
type Output = ();
5656
const DEFAULT: bool = true;
5757
const IS_HOST: bool = true;
5858

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

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

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

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

111117
let config = cmd.run_capture_stdout(builder);
112-
VendorOutput { config: config.stdout() }
113-
}
114-
}
115118

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

0 commit comments

Comments
 (0)