Skip to content

Commit

Permalink
Unrolled build for rust-lang#128983
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#128983 - Kobzol:bootstrap-target, r=onur-ozkan

Slightly refactor `TargetSelection` in bootstrap

Mostly a drive-by refactoring of `TargetSelection` to reduce some manual "windows-gnu" detection and also accesses to the `triple` field.

r? `@onur-ozkan`
  • Loading branch information
rust-timer committed Aug 13, 2024
2 parents a2e1d15 + 1c0c2c3 commit 6ff854b
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 70 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
18 changes: 9 additions & 9 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 @@ -432,7 +432,7 @@ fn copy_self_contained_objects(
DependencyType::TargetSelfContained,
);
}
} else if target.ends_with("windows-gnu") {
} else if target.is_windows_gnu() {
for obj in ["crt2.o", "dllcrt2.o"].iter() {
let src = compiler_file(builder, &builder.cc(target), target, CLang::C, obj);
let target = libdir_self_contained.join(obj);
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 @@ -793,7 +793,7 @@ impl Step for StartupObjects {
fn run(self, builder: &Builder<'_>) -> Vec<(PathBuf, DependencyType)> {
let for_compiler = self.compiler;
let target = self.target;
if !target.ends_with("windows-gnu") {
if !target.is_windows_gnu() {
return vec![];
}

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
38 changes: 15 additions & 23 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 @@ -1509,7 +1501,7 @@ impl Step for Extended {
tarballs.push(builder.ensure(Rustc { compiler: builder.compiler(stage, target) }));
tarballs.push(builder.ensure(Std { compiler, target }).expect("missing std"));

if target.ends_with("windows-gnu") {
if target.is_windows_gnu() {
tarballs.push(builder.ensure(Mingw { host: target }).expect("missing mingw"));
}

Expand Down Expand Up @@ -1683,7 +1675,7 @@ impl Step for Extended {
prepare(tool);
}
}
if target.ends_with("windows-gnu") {
if target.is_windows_gnu() {
prepare("rust-mingw");
}

Expand Down Expand Up @@ -1830,7 +1822,7 @@ impl Step for Extended {
.arg("-t")
.arg(etc.join("msi/remove-duplicates.xsl"))
.run(builder);
if target.ends_with("windows-gnu") {
if target.is_windows_gnu() {
command(&heat)
.current_dir(&exe)
.arg("dir")
Expand Down Expand Up @@ -1876,7 +1868,7 @@ impl Step for Extended {
if built_tools.contains("miri") {
cmd.arg("-dMiriDir=miri");
}
if target.ends_with("windows-gnu") {
if target.is_windows_gnu() {
cmd.arg("-dGccDir=rust-mingw");
}
cmd.run(builder);
Expand All @@ -1901,7 +1893,7 @@ impl Step for Extended {
}
candle("AnalysisGroup.wxs".as_ref());

if target.ends_with("windows-gnu") {
if target.is_windows_gnu() {
candle("GccGroup.wxs".as_ref());
}

Expand Down Expand Up @@ -1941,7 +1933,7 @@ impl Step for Extended {
cmd.arg("DocsGroup.wixobj");
}

if target.ends_with("windows-gnu") {
if target.is_windows_gnu() {
cmd.arg("GccGroup.wixobj");
}
// ICE57 wrongly complains about the shortcuts
Expand Down Expand Up @@ -1973,7 +1965,7 @@ fn add_env(builder: &Builder<'_>, cmd: &mut BootstrapCommand, target: TargetSele

if target.contains("windows-gnullvm") {
cmd.env("CFG_MINGW", "1").env("CFG_ABI", "LLVM");
} else if target.contains("windows-gnu") {
} else if target.is_windows_gnu() {
cmd.env("CFG_MINGW", "1").env("CFG_ABI", "GNU");
} else {
cmd.env("CFG_MINGW", "0").env("CFG_ABI", "MSVC");
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,
) -> PathBuf {
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 @@ -1115,7 +1115,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 @@ -2685,7 +2685,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 @@ -1171,7 +1171,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 @@ -1254,7 +1254,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 @@ -1504,9 +1504,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
20 changes: 16 additions & 4 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,10 @@ impl TargetSelection {
self.contains("windows")
}

pub fn is_windows_gnu(&self) -> bool {
self.ends_with("windows-gnu")
}

/// Path to the file defining the custom target, if any.
pub fn filepath(&self) -> Option<&Path> {
self.file.as_ref().map(Path::new)
Expand Down Expand Up @@ -542,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 @@ -1469,7 +1481,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 @@ -1484,7 +1496,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 @@ -2277,13 +2289,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
Loading

0 comments on commit 6ff854b

Please sign in to comment.