From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- src/bootstrap/compile.rs | 106 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 33 deletions(-) (limited to 'src/bootstrap/compile.rs') diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 0deed3f99..68d1db016 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -18,6 +18,7 @@ use std::str; use serde::Deserialize; +use crate::builder::crate_description; use crate::builder::Cargo; use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; use crate::cache::{Interned, INTERNER}; @@ -46,17 +47,6 @@ impl Std { } } -/// Return a `-p=x -p=y` string suitable for passing to a cargo invocation. -fn build_crates_in_set(run: &RunConfig<'_>) -> Interned> { - let mut crates = Vec::new(); - for krate in &run.paths { - let path = krate.assert_single_path(); - let crate_name = run.builder.crate_paths[&path.path]; - crates.push(format!("-p={crate_name}")); - } - INTERNER.intern_list(crates) -} - impl Step for Std { type Output = (); const DEFAULT: bool = true; @@ -76,7 +66,7 @@ impl Step for Std { // Build all crates anyway, as if they hadn't passed the other args. let has_library = run.paths.iter().any(|set| set.assert_single_path().path.ends_with("library")); - let crates = if has_library { Default::default() } else { build_crates_in_set(&run) }; + let crates = if has_library { Default::default() } else { run.cargo_crates_in_set() }; run.builder.ensure(Std { compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()), target: run.target, @@ -121,7 +111,10 @@ impl Step for Std { let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target); if compiler_to_use != compiler { builder.ensure(Std::new(compiler_to_use, target)); - builder.info(&format!("Uplifting stage1 std ({} -> {})", compiler_to_use.host, target)); + builder.info(&format!( + "Uplifting stage1 library ({} -> {})", + compiler_to_use.host, target + )); // Even if we're not building std this stage, the new sysroot must // still contain the third party objects needed by various targets. @@ -137,18 +130,25 @@ impl Step for Std { let mut cargo = builder.cargo(compiler, Mode::Std, SourceType::InTree, target, "build"); std_cargo(builder, target, compiler.stage, &mut cargo); + for krate in &*self.crates { + cargo.arg("-p").arg(krate); + } builder.info(&format!( - "Building stage{} std artifacts ({} -> {})", - compiler.stage, &compiler.host, target + "Building{} stage{} library artifacts ({} -> {})", + crate_description(&self.crates), + compiler.stage, + &compiler.host, + target, )); run_cargo( builder, cargo, - self.crates.to_vec(), + vec![], &libstd_stamp(builder, compiler, target), target_deps, false, + false, ); builder.ensure(StdLink::from_std( @@ -321,8 +321,15 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car "" }; + let mut features = String::new(); + + // Cranelift doesn't support `asm`. + if stage != 0 && builder.config.default_codegen_backend().unwrap_or_default() == "cranelift" { + features += " compiler-builtins-no-asm"; + } + if builder.no_std(target) == Some(true) { - let mut features = "compiler-builtins-mem".to_string(); + features += " compiler-builtins-mem"; if !target.starts_with("bpf") { features.push_str(compiler_builtins_c_feature); } @@ -335,7 +342,7 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car .arg("--features") .arg(features); } else { - let mut features = builder.std_features(target); + features += &builder.std_features(target); features.push_str(compiler_builtins_c_feature); cargo @@ -429,7 +436,7 @@ impl Step for StdLink { let target_compiler = self.target_compiler; let target = self.target; builder.info(&format!( - "Copying stage{} std from stage{} ({} -> {} / {})", + "Copying stage{} library from stage{} ({} -> {} / {})", target_compiler.stage, compiler.stage, &compiler.host, target_compiler.host, target )); let libdir = builder.sysroot_libdir(target_compiler, target); @@ -596,7 +603,7 @@ impl Step for Rustc { } fn make_run(run: RunConfig<'_>) { - let crates = build_crates_in_set(&run); + let crates = run.cargo_crates_in_set(); run.builder.ensure(Rustc { compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()), target: run.target, @@ -695,7 +702,8 @@ impl Step for Rustc { )); } - // cfg(bootstrap): remove if condition once the bootstrap compiler supports dylib LTO + // We currently don't support cross-crate LTO in stage0. This also isn't hugely necessary + // and may just be a time sink. if compiler.stage != 0 { match builder.config.rust_lto { RustcLto::Thin | RustcLto::Fat => { @@ -717,17 +725,25 @@ impl Step for Rustc { } } + for krate in &*self.crates { + cargo.arg("-p").arg(krate); + } + builder.info(&format!( - "Building stage{} compiler artifacts ({} -> {})", - compiler.stage, &compiler.host, target + "Building{} stage{} compiler artifacts ({} -> {})", + crate_description(&self.crates), + compiler.stage, + &compiler.host, + target, )); run_cargo( builder, cargo, - self.crates.to_vec(), + vec![], &librustc_stamp(builder, compiler, target), vec![], false, + true, // Only ship rustc_driver.so and .rmeta files, not all intermediate .rlib files. ); builder.ensure(RustcLink::from_rustc( @@ -754,7 +770,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS .env("CFG_RELEASE_CHANNEL", &builder.config.channel) .env("CFG_VERSION", builder.rust_version()); - if let Some(backend) = builder.config.rust_codegen_backends.get(0) { + if let Some(backend) = builder.config.default_codegen_backend() { cargo.env("CFG_DEFAULT_CODEGEN_BACKEND", backend); } @@ -805,7 +821,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS if builder.is_rust_llvm(target) { cargo.env("LLVM_RUSTLLVM", "1"); } - let llvm_config = builder.ensure(native::Llvm { target }); + let native::LlvmResult { llvm_config, .. } = builder.ensure(native::Llvm { target }); cargo.env("LLVM_CONFIG", &llvm_config); if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) { cargo.env("CFG_LLVM_ROOT", s); @@ -984,7 +1000,7 @@ impl Step for CodegenBackend { "Building stage{} codegen backend {} ({} -> {})", compiler.stage, backend, &compiler.host, target )); - let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false); + let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false, false); if builder.config.dry_run() { return; } @@ -1177,7 +1193,7 @@ impl Step for Sysroot { ); if builder.config.rust_remap_debuginfo { eprintln!( - "warning: some `src/test/ui` tests will fail when lacking `{}`", + "warning: some `tests/ui` tests will fail when lacking `{}`", sysroot_lib_rustlib_src_rust.display(), ); } @@ -1341,9 +1357,10 @@ impl Step for Assemble { } if builder.config.rust_codegen_backends.contains(&INTERNER.intern_str("llvm")) { - let llvm_config_bin = builder.ensure(native::Llvm { target: target_compiler.host }); + let native::LlvmResult { llvm_config, .. } = + builder.ensure(native::Llvm { target: target_compiler.host }); if !builder.config.dry_run() { - let llvm_bin_dir = output(Command::new(llvm_config_bin).arg("--bindir")); + let llvm_bin_dir = output(Command::new(llvm_config).arg("--bindir")); let llvm_bin_dir = Path::new(llvm_bin_dir.trim()); // Since we've already built the LLVM tools, install them to the sysroot. @@ -1411,6 +1428,7 @@ pub fn run_cargo( stamp: &Path, additional_target_deps: Vec<(PathBuf, DependencyType)>, is_check: bool, + rlib_only_metadata: bool, ) -> Vec { if builder.config.dry_run() { return Vec::new(); @@ -1444,13 +1462,35 @@ pub fn run_cargo( }; for filename in filenames { // Skip files like executables - if !(filename.ends_with(".rlib") - || filename.ends_with(".lib") + let mut keep = false; + if filename.ends_with(".lib") || filename.ends_with(".a") || is_debug_info(&filename) || is_dylib(&filename) - || (is_check && filename.ends_with(".rmeta"))) { + // Always keep native libraries, rust dylibs and debuginfo + keep = true; + } + if is_check && filename.ends_with(".rmeta") { + // During check builds we need to keep crate metadata + keep = true; + } else if rlib_only_metadata { + if filename.contains("jemalloc_sys") || filename.contains("rustc_smir") { + // jemalloc_sys and rustc_smir are not linked into librustc_driver.so, + // so we need to distribute them as rlib to be able to use them. + keep |= filename.ends_with(".rlib"); + } else { + // Distribute the rest of the rustc crates as rmeta files only to reduce + // the tarball sizes by about 50%. The object files are linked into + // librustc_driver.so, so it is still possible to link against them. + keep |= filename.ends_with(".rmeta"); + } + } else { + // In all other cases keep all rlibs + keep |= filename.ends_with(".rlib"); + } + + if !keep { continue; } -- cgit v1.2.3