Skip to content

Commit

Permalink
Implement AsRef<Path> for TargetSelection
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Aug 11, 2024
1 parent 2f5d9ff commit e1613ea
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 61 deletions.
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn clean(build: &Build, all: bool, stage: Option<u32>) {

fn clean_specific_stage(build: &Build, stage: u32) {
for host in &build.hosts {
let entries = match build.out.join(host.triple).read_dir() {
let entries = match build.out.join(host).read_dir() {
Ok(iter) => iter,
Err(_) => continue,
};
Expand All @@ -148,7 +148,7 @@ fn clean_default(build: &Build) {
rm_rf(&build.out.join("bootstrap-shims-dump"));
rm_rf(&build.out.join("rustfmt.stamp"));

let mut hosts: Vec<_> = build.hosts.iter().map(|t| build.out.join(t.triple)).collect();
let mut hosts: Vec<_> = build.hosts.iter().map(|t| build.out.join(t)).collect();
// After cross-compilation, artifacts of the host architecture (which may differ from build.host)
// might not get removed.
// Adding its path (linked one for easier accessibility) will solve this problem.
Expand Down
14 changes: 7 additions & 7 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl Step for Std {
.rustc_snapshot_sysroot()
.join("lib")
.join("rustlib")
.join(compiler.host.triple)
.join(compiler.host)
.join("bin");
if src_sysroot_bin.exists() {
let target_sysroot_bin =
Expand Down Expand Up @@ -651,8 +651,8 @@ impl Step for StdLink {
compiler: self.compiler,
force_recompile: self.force_recompile,
});
let libdir = sysroot.join(lib).join("rustlib").join(target.triple).join("lib");
let hostdir = sysroot.join(lib).join("rustlib").join(compiler.host.triple).join("lib");
let libdir = sysroot.join(lib).join("rustlib").join(target).join("lib");
let hostdir = sysroot.join(lib).join("rustlib").join(compiler.host).join("lib");
(libdir, hostdir)
} else {
let libdir = builder.sysroot_libdir(target_compiler, target);
Expand All @@ -670,12 +670,12 @@ impl Step for StdLink {
.build
.config
.initial_rustc
.starts_with(builder.out.join(compiler.host.triple).join("stage0/bin"))
.starts_with(builder.out.join(compiler.host).join("stage0/bin"))
{
// Copy bin files from stage0/bin to stage0-sysroot/bin
let sysroot = builder.out.join(compiler.host.triple).join("stage0-sysroot");
let sysroot = builder.out.join(compiler.host).join("stage0-sysroot");

let host = compiler.host.triple;
let host = compiler.host;
let stage0_bin_dir = builder.out.join(host).join("stage0/bin");
let sysroot_bin_dir = sysroot.join("bin");
t!(fs::create_dir_all(&sysroot_bin_dir));
Expand Down Expand Up @@ -1554,7 +1554,7 @@ impl Step for Sysroot {
/// For all other stages, it's the same stage directory that the compiler lives in.
fn run(self, builder: &Builder<'_>) -> PathBuf {
let compiler = self.compiler;
let host_dir = builder.out.join(compiler.host.triple);
let host_dir = builder.out.join(compiler.host);

let sysroot_dir = |stage| {
if stage == 0 {
Expand Down
24 changes: 8 additions & 16 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,8 @@ fn make_win_dist(
}

//Copy platform tools to platform-specific bin directory
let target_bin_dir = plat_root
.join("lib")
.join("rustlib")
.join(target.triple)
.join("bin")
.join("self-contained");
let target_bin_dir =
plat_root.join("lib").join("rustlib").join(target).join("bin").join("self-contained");
fs::create_dir_all(&target_bin_dir).expect("creating target_bin_dir failed");
for src in target_tools {
builder.copy_link_to_folder(&src, &target_bin_dir);
Expand All @@ -295,12 +291,8 @@ fn make_win_dist(
);

//Copy platform libs to platform-specific lib directory
let target_lib_dir = plat_root
.join("lib")
.join("rustlib")
.join(target.triple)
.join("lib")
.join("self-contained");
let target_lib_dir =
plat_root.join("lib").join("rustlib").join(target).join("lib").join("self-contained");
fs::create_dir_all(&target_lib_dir).expect("creating target_lib_dir failed");
for src in target_libs {
builder.copy_link_to_folder(&src, &target_lib_dir);
Expand Down Expand Up @@ -450,7 +442,7 @@ impl Step for Rustc {
// component for now.
maybe_install_llvm_runtime(builder, host, image);

let dst_dir = image.join("lib/rustlib").join(&*host.triple).join("bin");
let dst_dir = image.join("lib/rustlib").join(host).join("bin");
t!(fs::create_dir_all(&dst_dir));

// Copy over lld if it's there
Expand Down Expand Up @@ -607,7 +599,7 @@ fn verify_uefi_rlib_format(builder: &Builder<'_>, target: TargetSelection, stamp

/// Copy stamped files into an image's `target/lib` directory.
fn copy_target_libs(builder: &Builder<'_>, target: TargetSelection, image: &Path, stamp: &Path) {
let dst = image.join("lib/rustlib").join(target.triple).join("lib");
let dst = image.join("lib/rustlib").join(target).join("lib");
let self_contained_dst = dst.join("self-contained");
t!(fs::create_dir_all(&dst));
t!(fs::create_dir_all(&self_contained_dst));
Expand Down Expand Up @@ -769,7 +761,7 @@ impl Step for Analysis {

let src = builder
.stage_out(compiler, Mode::Std)
.join(target.triple)
.join(target)
.join(builder.cargo_dir())
.join("deps")
.join("save-analysis");
Expand Down Expand Up @@ -2087,7 +2079,7 @@ fn maybe_install_llvm(

/// Maybe add libLLVM.so to the target lib-dir for linking.
pub fn maybe_install_llvm_target(builder: &Builder<'_>, target: TargetSelection, sysroot: &Path) {
let dst_libdir = sysroot.join("lib/rustlib").join(&*target.triple).join("lib");
let dst_libdir = sysroot.join("lib/rustlib").join(target).join("lib");
// We do not need to copy LLVM files into the sysroot if it is not
// dynamically linked; it is already included into librustc_llvm
// statically.
Expand Down
9 changes: 4 additions & 5 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,12 @@ fn doc_std(
let compiler = builder.compiler(stage, builder.config.build);

let target_doc_dir_name = if format == DocumentationFormat::Json { "json-doc" } else { "doc" };
let target_dir =
builder.stage_out(compiler, Mode::Std).join(target.triple).join(target_doc_dir_name);
let target_dir = builder.stage_out(compiler, Mode::Std).join(target).join(target_doc_dir_name);

// This is directory where the compiler will place the output of the command.
// We will then copy the files from this directory into the final `out` directory, the specified
// as a function parameter.
let out_dir = target_dir.join(target.triple).join("doc");
let out_dir = target_dir.join(target).join("doc");

let mut cargo =
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, Kind::Doc);
Expand Down Expand Up @@ -846,7 +845,7 @@ impl Step for Rustc {

let mut to_open = None;

let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target.triple).join("doc");
let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc");
for krate in &*self.crates {
// Create all crate output directories first to make sure rustdoc uses
// relative links.
Expand Down Expand Up @@ -992,7 +991,7 @@ macro_rules! tool_doc {
// see https://github.com/rust-lang/rust/pull/122066#issuecomment-1983049222
// cargo.rustdocflag("--generate-link-to-definition");

let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc");
let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target).join("doc");
$(for krate in $crates {
let dir_name = krate.replace("-", "_");
t!(fs::create_dir_all(out_dir.join(&*dir_name)));
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ You can skip linkcheck with --skip src/tools/linkchecker"
let _guard =
builder.msg(Kind::Test, compiler.stage, "Linkcheck", bootstrap_host, bootstrap_host);
let _time = helpers::timeit(builder);
linkchecker.delay_failure().arg(builder.out.join(host.triple).join("doc")).run(builder);
linkchecker.delay_failure().arg(builder.out.join(host).join("doc")).run(builder);
}

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
Expand Down Expand Up @@ -435,7 +435,7 @@ impl Miri {
compiler: Compiler,
target: TargetSelection,
) -> String {
let miri_sysroot = builder.out.join(compiler.host.triple).join("miri-sysroot");
let miri_sysroot = builder.out.join(compiler.host).join("miri-sysroot");
let mut cargo = builder::Cargo::new(
builder,
compiler,
Expand Down Expand Up @@ -1113,7 +1113,7 @@ HELP: to skip test's attempt to check tidiness, pass `--skip src/tools/tidy` to
}

fn testdir(builder: &Builder<'_>, host: TargetSelection) -> PathBuf {
builder.out.join(host.triple).join("test")
builder.out.join(host).join("test")
}

macro_rules! default_test {
Expand Down Expand Up @@ -2683,7 +2683,7 @@ impl Step for Crate {
if builder.download_rustc() && compiler.stage > 0 {
let sysroot = builder
.out
.join(compiler.host.triple)
.join(compiler.host)
.join(format!("stage{}-test-sysroot", compiler.stage));
cargo.env("RUSTC_SYSROOT", sysroot);
}
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ impl<'a> Builder<'a> {
.sysroot(self.compiler)
.join(lib)
.join("rustlib")
.join(self.target.triple)
.join(self.target)
.join("lib");
// Avoid deleting the rustlib/ directory we just copied
// (in `impl Step for Sysroot`).
Expand Down Expand Up @@ -1248,7 +1248,7 @@ impl<'a> Builder<'a> {

// Ensure that the downloaded LLVM libraries can be found.
if self.config.llvm_from_ci {
let ci_llvm_lib = self.out.join(&*compiler.host.triple).join("ci-llvm").join("lib");
let ci_llvm_lib = self.out.join(compiler.host).join("ci-llvm").join("lib");
dylib_dirs.push(ci_llvm_lib);
}

Expand Down Expand Up @@ -1498,9 +1498,9 @@ impl<'a> Builder<'a> {
Mode::Rustc | Mode::ToolRustc => self.compiler_doc_out(target),
Mode::Std => {
if self.config.cmd.json() {
out_dir.join(target.triple).join("json-doc")
out_dir.join(target).join("json-doc")
} else {
out_dir.join(target.triple).join("doc")
out_dir.join(target).join("doc")
}
}
_ => panic!("doc mode {mode:?} not expected"),
Expand Down
16 changes: 12 additions & 4 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,14 @@ impl PartialEq<&str> for TargetSelection {
}
}

// Targets are often used as directory names throughout bootstrap.
// This impl makes it more ergonomics to use them as such.
impl AsRef<Path> for TargetSelection {
fn as_ref(&self) -> &Path {
self.triple.as_ref()
}
}

/// Per-target configuration stored in the global configuration structure.
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct Target {
Expand Down Expand Up @@ -1474,7 +1482,7 @@ impl Config {
config.download_beta_toolchain();
config
.out
.join(config.build.triple)
.join(config.build)
.join("stage0")
.join("bin")
.join(exe("rustc", config.build))
Expand All @@ -1489,7 +1497,7 @@ impl Config {
config.download_beta_toolchain();
config
.out
.join(config.build.triple)
.join(config.build)
.join("stage0")
.join("bin")
.join(exe("cargo", config.build))
Expand Down Expand Up @@ -2282,13 +2290,13 @@ impl Config {
/// The absolute path to the downloaded LLVM artifacts.
pub(crate) fn ci_llvm_root(&self) -> PathBuf {
assert!(self.llvm_from_ci);
self.out.join(&*self.build.triple).join("ci-llvm")
self.out.join(self.build).join("ci-llvm")
}

/// Directory where the extracted `rustc-dev` component is stored.
pub(crate) fn ci_rustc_dir(&self) -> PathBuf {
assert!(self.download_rustc());
self.out.join(self.build.triple).join("ci-rustc")
self.out.join(self.build).join("ci-rustc")
}

/// Determine whether llvm should be linked dynamically.
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl Config {
let version = &self.stage0_metadata.compiler.version;
let host = self.build;

let bin_root = self.out.join(host.triple).join("stage0");
let bin_root = self.out.join(host).join("stage0");
let clippy_stamp = bin_root.join(".clippy-stamp");
let cargo_clippy = bin_root.join("bin").join(exe("cargo-clippy", host));
if cargo_clippy.exists() && !program_out_of_date(&clippy_stamp, date) {
Expand Down Expand Up @@ -412,7 +412,7 @@ impl Config {
let channel = format!("{version}-{date}");

let host = self.build;
let bin_root = self.out.join(host.triple).join("rustfmt");
let bin_root = self.out.join(host).join("rustfmt");
let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host));
let rustfmt_stamp = bin_root.join(".rustfmt-stamp");
if rustfmt_path.exists() && !program_out_of_date(&rustfmt_stamp, &channel) {
Expand Down Expand Up @@ -519,7 +519,7 @@ impl Config {
extra_components: &[&str],
download_component: fn(&Config, String, &str, &str),
) {
let host = self.build.triple;
let host = self.build;
let bin_root = self.out.join(host).join(sysroot);
let rustc_stamp = bin_root.join(".rustc-stamp");

Expand Down Expand Up @@ -592,7 +592,7 @@ impl Config {
t!(fs::create_dir_all(&cache_dir));
}

let bin_root = self.out.join(self.build.triple).join(destination);
let bin_root = self.out.join(self.build).join(destination);
let tarball = cache_dir.join(&filename);
let (base_url, url, should_verify) = match mode {
DownloadSource::CI => {
Expand Down
Loading

0 comments on commit e1613ea

Please sign in to comment.