Rollup merge of #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`
This commit is contained in:
Matthias Krüger 2024-08-13 12:12:24 +02:00 committed by GitHub
commit 9d9c9acc6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 70 additions and 70 deletions

View File

@ -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,
};
@ -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.

View File

@ -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 =
@ -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);
@ -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);
@ -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));
@ -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![];
}
@ -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 {

View File

@ -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);
@ -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);
@ -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
@ -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));
@ -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");
@ -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"));
}
@ -1683,7 +1675,7 @@ impl Step for Extended {
prepare(tool);
}
}
if target.ends_with("windows-gnu") {
if target.is_windows_gnu() {
prepare("rust-mingw");
}
@ -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")
@ -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);
@ -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());
}
@ -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
@ -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");
@ -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.

View File

@ -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);
@ -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.
@ -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)));

View File

@ -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<'_> {
@ -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,
@ -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 {
@ -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);
}

View File

@ -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`).
@ -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);
}
@ -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"),

View File

@ -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)
@ -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 {
@ -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))
@ -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))
@ -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.

View File

@ -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) {
@ -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) {
@ -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");
@ -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 => {

View File

@ -452,7 +452,7 @@ impl Build {
}
// Make a symbolic link so we can use a consistent directory in the documentation.
let build_triple = build.out.join(build.build.triple);
let build_triple = build.out.join(build.build);
t!(fs::create_dir_all(&build_triple));
let host = build.out.join("host");
if host.is_symlink() {
@ -807,10 +807,7 @@ impl Build {
}
fn tools_dir(&self, compiler: Compiler) -> PathBuf {
let out = self
.out
.join(&*compiler.host.triple)
.join(format!("stage{}-tools-bin", compiler.stage));
let out = self.out.join(compiler.host).join(format!("stage{}-tools-bin", compiler.stage));
t!(fs::create_dir_all(&out));
out
}
@ -827,14 +824,14 @@ impl Build {
Mode::ToolBootstrap => "-bootstrap-tools",
Mode::ToolStd | Mode::ToolRustc => "-tools",
};
self.out.join(&*compiler.host.triple).join(format!("stage{}{}", compiler.stage, suffix))
self.out.join(compiler.host).join(format!("stage{}{}", compiler.stage, suffix))
}
/// Returns the root output directory for all Cargo output in a given stage,
/// running a particular compiler, whether or not we're building the
/// standard library, and targeting the specified architecture.
fn cargo_out(&self, compiler: Compiler, mode: Mode, target: TargetSelection) -> PathBuf {
self.stage_out(compiler, mode).join(&*target.triple).join(self.cargo_dir())
self.stage_out(compiler, mode).join(target).join(self.cargo_dir())
}
/// Root output directory of LLVM for `target`
@ -845,36 +842,36 @@ impl Build {
if self.config.llvm_from_ci && self.config.build == target {
self.config.ci_llvm_root()
} else {
self.out.join(&*target.triple).join("llvm")
self.out.join(target).join("llvm")
}
}
fn lld_out(&self, target: TargetSelection) -> PathBuf {
self.out.join(&*target.triple).join("lld")
self.out.join(target).join("lld")
}
/// Output directory for all documentation for a target
fn doc_out(&self, target: TargetSelection) -> PathBuf {
self.out.join(&*target.triple).join("doc")
self.out.join(target).join("doc")
}
/// Output directory for all JSON-formatted documentation for a target
fn json_doc_out(&self, target: TargetSelection) -> PathBuf {
self.out.join(&*target.triple).join("json-doc")
self.out.join(target).join("json-doc")
}
fn test_out(&self, target: TargetSelection) -> PathBuf {
self.out.join(&*target.triple).join("test")
self.out.join(target).join("test")
}
/// Output directory for all documentation for a target
fn compiler_doc_out(&self, target: TargetSelection) -> PathBuf {
self.out.join(&*target.triple).join("compiler-doc")
self.out.join(target).join("compiler-doc")
}
/// Output directory for some generated md crate documentation for a target (temporary)
fn md_doc_out(&self, target: TargetSelection) -> PathBuf {
self.out.join(&*target.triple).join("md-doc")
self.out.join(target).join("md-doc")
}
/// Returns `true` if this is an external version of LLVM not managed by bootstrap.
@ -954,7 +951,7 @@ impl Build {
/// Directory for libraries built from C/C++ code and shared between stages.
fn native_dir(&self, target: TargetSelection) -> PathBuf {
self.out.join(&*target.triple).join("native")
self.out.join(target).join("native")
}
/// Root output directory for rust_test_helpers library compiled for