From 4a57da563f5da9501b3c7f9213b9cb40f9b6bf1e Mon Sep 17 00:00:00 2001 From: q66 Date: Fri, 30 May 2025 12:33:02 +0200 Subject: [PATCH 02/16] remove a bunch of unused junk --- compiler/rustc_target/src/spec/crt_objects.rs | 22 ---- src/bootstrap/configure.py | 100 ------------------ src/bootstrap/src/core/build_steps/compile.rs | 58 +--------- src/bootstrap/src/core/build_steps/llvm.rs | 3 - src/bootstrap/src/core/config/config.rs | 8 -- .../src/core/config/target_selection.rs | 4 - src/bootstrap/src/core/config/toml/rust.rs | 2 - src/bootstrap/src/core/config/toml/target.rs | 4 - src/bootstrap/src/core/sanity.rs | 16 --- src/bootstrap/src/lib.rs | 29 ----- src/bootstrap/src/utils/cc_detect.rs | 24 ----- 11 files changed, 1 insertion(+), 269 deletions(-) diff --git a/compiler/rustc_target/src/spec/crt_objects.rs b/compiler/rustc_target/src/spec/crt_objects.rs index 2d84e78f2..0e6cb0f42 100644 --- a/compiler/rustc_target/src/spec/crt_objects.rs +++ b/compiler/rustc_target/src/spec/crt_objects.rs @@ -62,28 +62,6 @@ pub(super) fn all(obj: &'static str) -> CrtObjects { ]) } -pub(super) fn pre_musl_self_contained() -> CrtObjects { - new(&[ - (LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]), - (LinkOutputKind::DynamicPicExe, &["Scrt1.o", "crti.o", "crtbeginS.o"]), - (LinkOutputKind::StaticNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]), - (LinkOutputKind::StaticPicExe, &["rcrt1.o", "crti.o", "crtbeginS.o"]), - (LinkOutputKind::DynamicDylib, &["crti.o", "crtbeginS.o"]), - (LinkOutputKind::StaticDylib, &["crti.o", "crtbeginS.o"]), - ]) -} - -pub(super) fn post_musl_self_contained() -> CrtObjects { - new(&[ - (LinkOutputKind::DynamicNoPicExe, &["crtend.o", "crtn.o"]), - (LinkOutputKind::DynamicPicExe, &["crtendS.o", "crtn.o"]), - (LinkOutputKind::StaticNoPicExe, &["crtend.o", "crtn.o"]), - (LinkOutputKind::StaticPicExe, &["crtendS.o", "crtn.o"]), - (LinkOutputKind::DynamicDylib, &["crtendS.o", "crtn.o"]), - (LinkOutputKind::StaticDylib, &["crtendS.o", "crtn.o"]), - ]) -} - pub(super) fn pre_mingw_self_contained() -> CrtObjects { new(&[ (LinkOutputKind::DynamicNoPicExe, &["crt2.o"]), diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index fda8f004e..3e7e828a0 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -185,106 +185,6 @@ v("llvm-config", None, "set path to llvm-config") v("llvm-filecheck", None, "set path to LLVM's FileCheck utility") v("python", "build.python", "set path to python") v("android-ndk", "build.android-ndk", "set path to Android NDK") -v( - "musl-root", - "target.x86_64-unknown-linux-musl.musl-root", - "MUSL root installation directory (deprecated)", -) -v( - "musl-root-x86_64", - "target.x86_64-unknown-linux-musl.musl-root", - "x86_64-unknown-linux-musl install directory", -) -v( - "musl-root-i586", - "target.i586-unknown-linux-musl.musl-root", - "i586-unknown-linux-musl install directory", -) -v( - "musl-root-i686", - "target.i686-unknown-linux-musl.musl-root", - "i686-unknown-linux-musl install directory", -) -v( - "musl-root-arm", - "target.arm-unknown-linux-musleabi.musl-root", - "arm-unknown-linux-musleabi install directory", -) -v( - "musl-root-armhf", - "target.arm-unknown-linux-musleabihf.musl-root", - "arm-unknown-linux-musleabihf install directory", -) -v( - "musl-root-armv5te", - "target.armv5te-unknown-linux-musleabi.musl-root", - "armv5te-unknown-linux-musleabi install directory", -) -v( - "musl-root-armv7", - "target.armv7-unknown-linux-musleabi.musl-root", - "armv7-unknown-linux-musleabi install directory", -) -v( - "musl-root-armv7hf", - "target.armv7-unknown-linux-musleabihf.musl-root", - "armv7-unknown-linux-musleabihf install directory", -) -v( - "musl-root-aarch64", - "target.aarch64-unknown-linux-musl.musl-root", - "aarch64-unknown-linux-musl install directory", -) -v( - "musl-root-mips", - "target.mips-unknown-linux-musl.musl-root", - "mips-unknown-linux-musl install directory", -) -v( - "musl-root-mipsel", - "target.mipsel-unknown-linux-musl.musl-root", - "mipsel-unknown-linux-musl install directory", -) -v( - "musl-root-mips64", - "target.mips64-unknown-linux-muslabi64.musl-root", - "mips64-unknown-linux-muslabi64 install directory", -) -v( - "musl-root-mips64el", - "target.mips64el-unknown-linux-muslabi64.musl-root", - "mips64el-unknown-linux-muslabi64 install directory", -) -v( - "musl-root-powerpc64", - "target.powerpc64-unknown-linux-musl.musl-root", - "powerpc64-unknown-linux-musl install directory", -) -v( - "musl-root-powerpc64le", - "target.powerpc64le-unknown-linux-musl.musl-root", - "powerpc64le-unknown-linux-musl install directory", -) -v( - "musl-root-riscv32gc", - "target.riscv32gc-unknown-linux-musl.musl-root", - "riscv32gc-unknown-linux-musl install directory", -) -v( - "musl-root-riscv64gc", - "target.riscv64gc-unknown-linux-musl.musl-root", - "riscv64gc-unknown-linux-musl install directory", -) -v( - "musl-root-loongarch64", - "target.loongarch64-unknown-linux-musl.musl-root", - "loongarch64-unknown-linux-musl install directory", -) -v( - "musl-root-wali-wasm32", - "target.wasm32-wali-linux-musl.musl-root", - "wasm32-wali-linux-musl install directory", -) v( "qemu-armhf-rootfs", "target.arm-unknown-linux-gnueabihf.qemu-rootfs", diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 11f2a28bb..0270fafcc 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -382,54 +382,7 @@ fn copy_self_contained_objects( t!(fs::create_dir_all(&libdir_self_contained)); let mut target_deps = vec![]; - // Copies the libc and CRT objects. - // - // rustc historically provides a more self-contained installation for musl targets - // not requiring the presence of a native musl toolchain. For example, it can fall back - // to using gcc from a glibc-targeting toolchain for linking. - // To do that we have to distribute musl startup objects as a part of Rust toolchain - // and link with them manually in the self-contained mode. - if target.needs_crt_begin_end() { - let srcdir = builder.musl_libdir(target).unwrap_or_else(|| { - panic!("Target {:?} does not have a \"musl-libdir\" key", target.triple) - }); - if !target.starts_with("wasm32") { - for &obj in &["libc.a", "crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] { - copy_and_stamp( - builder, - &libdir_self_contained, - &srcdir, - obj, - &mut target_deps, - DependencyType::TargetSelfContained, - ); - } - let crt_path = builder.ensure(llvm::CrtBeginEnd { target }); - for &obj in &["crtbegin.o", "crtbeginS.o", "crtend.o", "crtendS.o"] { - let src = crt_path.join(obj); - let target = libdir_self_contained.join(obj); - builder.copy_link(&src, &target, FileType::NativeLibrary); - target_deps.push((target, DependencyType::TargetSelfContained)); - } - } else { - // For wasm32 targets, we need to copy the libc.a and crt1-command.o files from the - // musl-libdir, but we don't need the other files. - for &obj in &["libc.a", "crt1-command.o"] { - copy_and_stamp( - builder, - &libdir_self_contained, - &srcdir, - obj, - &mut target_deps, - DependencyType::TargetSelfContained, - ); - } - } - if !target.starts_with("s390x") { - let libunwind_path = copy_llvm_libunwind(builder, target, &libdir_self_contained); - target_deps.push((libunwind_path, DependencyType::TargetSelfContained)); - } - } else if target.contains("-wasi") { + if target.contains("-wasi") { let srcdir = builder.wasi_libdir(target).unwrap_or_else(|| { panic!( "Target {:?} does not have a \"wasi-root\" key in bootstrap.toml \ @@ -660,15 +613,6 @@ pub fn std_cargo( .arg("--manifest-path") .arg(builder.src.join("library/sysroot/Cargo.toml")); - // Help the libc crate compile by assisting it in finding various - // sysroot native libraries. - if target.contains("musl") - && let Some(p) = builder.musl_libdir(target) - { - let root = format!("native={}", p.to_str().unwrap()); - cargo.rustflag("-L").rustflag(&root); - } - if target.contains("-wasi") && let Some(dir) = builder.wasi_libdir(target) { diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index c3935d981..509cba033 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -1581,9 +1581,6 @@ impl Step for CrtBeginEnd { } fn make_run(run: RunConfig<'_>) { - if run.target.needs_crt_begin_end() { - run.builder.ensure(CrtBeginEnd { target: run.target }); - } } /// Build crtbegin.o/crtend.o for musl target. diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 07405a030..4e4c4f72e 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -264,8 +264,6 @@ pub struct Config { pub print_step_timings: bool, pub print_step_rusage: bool, - // Fallback musl-root for all targets - pub musl_root: Option, pub prefix: Option, pub sysconfdir: Option, pub datadir: Option, @@ -543,7 +541,6 @@ impl Config { randomize_layout: rust_randomize_layout, default_linker: rust_default_linker, channel: rust_channel, - musl_root: rust_musl_root, rpath: rust_rpath, verbose_tests: rust_verbose_tests, optimize_tests: rust_optimize_tests, @@ -883,8 +880,6 @@ impl Config { rpath: target_rpath, rustflags: target_rustflags, crt_static: target_crt_static, - musl_root: target_musl_root, - musl_libdir: target_musl_libdir, wasi_root: target_wasi_root, qemu_rootfs: target_qemu_rootfs, no_std: target_no_std, @@ -957,8 +952,6 @@ impl Config { target.crt_static = target_crt_static; target.default_linker = target_default_linker; target.default_linker_linux_override = default_linker_linux_override; - target.musl_root = target_musl_root.map(PathBuf::from); - target.musl_libdir = target_musl_libdir.map(PathBuf::from); target.wasi_root = target_wasi_root.map(PathBuf::from); target.qemu_rootfs = target_qemu_rootfs.map(PathBuf::from); target.runner = target_runner; @@ -1411,7 +1404,6 @@ impl Config { low_priority: build_low_priority.unwrap_or(false), mandir: install_mandir.map(PathBuf::from), miri_info, - musl_root: rust_musl_root.map(PathBuf::from), ninja_in_file: llvm_ninja.unwrap_or(true), nodejs: build_nodejs.map(PathBuf::from), omit_git_hash, diff --git a/src/bootstrap/src/core/config/target_selection.rs b/src/bootstrap/src/core/config/target_selection.rs index 47f6d6f38..a519b6655 100644 --- a/src/bootstrap/src/core/config/target_selection.rs +++ b/src/bootstrap/src/core/config/target_selection.rs @@ -96,10 +96,6 @@ impl TargetSelection { env::var("OSTYPE").is_ok_and(|v| v.to_lowercase().contains("cygwin")) } - pub fn needs_crt_begin_end(&self) -> bool { - self.contains("musl") && !self.contains("unikraft") - } - /// Path to the file defining the custom target, if any. pub fn filepath(&self) -> Option<&Path> { self.file.as_ref().map(Path::new) diff --git a/src/bootstrap/src/core/config/toml/rust.rs b/src/bootstrap/src/core/config/toml/rust.rs index 48042ba56..083970f1b 100644 --- a/src/bootstrap/src/core/config/toml/rust.rs +++ b/src/bootstrap/src/core/config/toml/rust.rs @@ -31,7 +31,6 @@ define_config! { incremental: Option = "incremental", default_linker: Option = "default-linker", channel: Option = "channel", - musl_root: Option = "musl-root", rpath: Option = "rpath", rustflags: Option> = "rustflags", strip: Option = "strip", @@ -346,7 +345,6 @@ pub fn check_incompatible_options_for_ci_rustc( debuginfo_level_tools: _, debuginfo_level_tests: _, backtrace: _, - musl_root: _, verbose_tests: _, optimize_tests: _, codegen_tests: _, diff --git a/src/bootstrap/src/core/config/toml/target.rs b/src/bootstrap/src/core/config/toml/target.rs index 847b75e69..5ad42917a 100644 --- a/src/bootstrap/src/core/config/toml/target.rs +++ b/src/bootstrap/src/core/config/toml/target.rs @@ -39,8 +39,6 @@ define_config! { rpath: Option = "rpath", rustflags: Option> = "rustflags", crt_static: Option = "crt-static", - musl_root: Option = "musl-root", - musl_libdir: Option = "musl-libdir", wasi_root: Option = "wasi-root", qemu_rootfs: Option = "qemu-rootfs", no_std: Option = "no-std", @@ -73,8 +71,6 @@ pub struct Target { pub rpath: Option, pub rustflags: Vec, pub crt_static: Option, - pub musl_root: Option, - pub musl_libdir: Option, pub wasi_root: Option, pub qemu_rootfs: Option, pub runner: Option, diff --git a/src/bootstrap/src/core/sanity.rs b/src/bootstrap/src/core/sanity.rs index 67f4eb37b..6f2cf48b0 100644 --- a/src/bootstrap/src/core/sanity.rs +++ b/src/bootstrap/src/core/sanity.rs @@ -374,22 +374,6 @@ than building it. continue; } - // Make sure musl-root is valid. - if target.contains("musl") && !target.contains("unikraft") { - match build.musl_libdir(*target) { - Some(libdir) => { - if fs::metadata(libdir.join("libc.a")).is_err() { - panic!("couldn't find libc.a in musl libdir: {}", libdir.display()); - } - } - None => panic!( - "when targeting MUSL either the rust.musl-root \ - option or the target.$TARGET.musl-root option must \ - be specified in bootstrap.toml" - ), - } - } - if need_cmake && target.is_msvc() { // There are three builds of cmake on windows: MSVC, MinGW, and // Cygwin. The Cygwin build does not have generators for Visual diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 857c0539e..ebe12d747 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1389,35 +1389,6 @@ impl Build { } } - /// Returns the "musl root" for this `target`, if defined. - /// - /// If this is a native target (host is also musl) and no musl-root is given, - /// it falls back to the system toolchain in /usr. - fn musl_root(&self, target: TargetSelection) -> Option<&Path> { - let configured_root = self - .config - .target_config - .get(&target) - .and_then(|t| t.musl_root.as_ref()) - .or(self.config.musl_root.as_ref()) - .map(|p| &**p); - - if self.config.is_host_target(target) && configured_root.is_none() { - Some(Path::new("/usr")) - } else { - configured_root - } - } - - /// Returns the "musl libdir" for this `target`. - fn musl_libdir(&self, target: TargetSelection) -> Option { - self.config - .target_config - .get(&target) - .and_then(|t| t.musl_libdir.clone()) - .or_else(|| self.musl_root(target).map(|root| root.join("lib"))) - } - /// Returns the `lib` directory for the WASI target specified, if /// configured. /// diff --git a/src/bootstrap/src/utils/cc_detect.rs b/src/bootstrap/src/utils/cc_detect.rs index 0662ae304..f6373f44e 100644 --- a/src/bootstrap/src/utils/cc_detect.rs +++ b/src/bootstrap/src/utils/cc_detect.rs @@ -195,30 +195,6 @@ fn default_compiler( } } - "mips-unknown-linux-musl" if compiler == Language::C => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - Some(PathBuf::from("mips-linux-musl-gcc")) - } else { - None - } - } - "mipsel-unknown-linux-musl" if compiler == Language::C => { - if cfg.get_compiler().path().to_str() == Some("gcc") { - Some(PathBuf::from("mipsel-linux-musl-gcc")) - } else { - None - } - } - - t if t.contains("musl") && compiler == Language::C => { - if let Some(root) = build.musl_root(target) { - let guess = root.join("bin/musl-gcc"); - if guess.exists() { Some(guess) } else { None } - } else { - None - } - } - t if t.contains("-wasi") => { let root = if let Some(path) = build.wasi_sdk_path.as_ref() { path -- 2.52.0