From 1f32908497436a4bf006f2b2baa60f2f38bf2169 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Tue, 20 Feb 2024 14:52:12 -0500 Subject: [PATCH] refactor: remove unused `sysroot_host_libdir` Copy from : > I've never been entirely clear why it does this. #4006 didn't really > explain why it added the corresponding host_dylib_path. I can't envision > a scenario where it matters. I think compiler plugins and proc-macros > should load just fine, since libstd.so should already be loaded by the > compiler. Also, rustc uses rpath these days, and on Windows libstd.so is > placed in the bin directory which will be searched first anyways. > > On balance, I think it should be safe to just remove sysroot_host_libdir. > I can't come up with a scenario where it matters, at least on > windows/macos/linux. One issue is that this is most likely to affect > plugins, but those are deprecated and I think only Servo was the real > holdout. A concern is that nobody is going to test this use case before > it hits stable. Also, * compiler plugins were removed https://github.com/rust-lang/rust/pull/116412 * servo has moved off from plugins: https://github.com/servo/servo/pull/30508 So should generally be fine. --- .../compiler/build_context/target_info.rs | 26 +++++++------------ src/cargo/core/compiler/compilation.rs | 9 ------- 2 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 864196e1ca17..fcb4074e96ed 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -48,9 +48,6 @@ pub struct TargetInfo { support_split_debuginfo: Vec, /// Path to the sysroot. pub sysroot: PathBuf, - /// Path to the "lib" or "bin" directory that rustc uses for its dynamic - /// libraries. - pub sysroot_host_libdir: PathBuf, /// Path to the "lib" directory in the sysroot which rustc uses for linking /// target libraries. pub sysroot_target_libdir: PathBuf, @@ -224,19 +221,17 @@ impl TargetInfo { return error_missing_print_output("sysroot", &process, &output, &error); }; let sysroot = PathBuf::from(line); - let sysroot_host_libdir = if cfg!(windows) { - sysroot.join("bin") - } else { - sysroot.join("lib") + let sysroot_target_libdir = { + let mut libdir = sysroot.clone(); + libdir.push("lib"); + libdir.push("rustlib"); + libdir.push(match &kind { + CompileKind::Host => rustc.host.as_str(), + CompileKind::Target(target) => target.short_name(), + }); + libdir.push("lib"); + libdir }; - let mut sysroot_target_libdir = sysroot.clone(); - sysroot_target_libdir.push("lib"); - sysroot_target_libdir.push("rustlib"); - sysroot_target_libdir.push(match &kind { - CompileKind::Host => rustc.host.as_str(), - CompileKind::Target(target) => target.short_name(), - }); - sysroot_target_libdir.push("lib"); let support_split_debuginfo = { // HACK: abuse `--print=crate-name` to use `___` as a delimiter. @@ -303,7 +298,6 @@ impl TargetInfo { crate_type_process, crate_types: RefCell::new(map), sysroot, - sysroot_host_libdir, sysroot_target_libdir, rustflags, rustdocflags: extra_args( diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index f6ddf34b07d2..018792d2b135 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -74,9 +74,6 @@ pub struct Compilation<'gctx> { /// May be for the host or for a specific target. pub deps_output: HashMap, - /// The path to the host libdir for the compiler used - sysroot_host_libdir: PathBuf, - /// The path to libstd for each target sysroot_target_libdir: HashMap, @@ -128,11 +125,6 @@ impl<'gctx> Compilation<'gctx> { native_dirs: BTreeSet::new(), root_output: HashMap::new(), deps_output: HashMap::new(), - sysroot_host_libdir: bcx - .target_data - .info(CompileKind::Host) - .sysroot_host_libdir - .clone(), sysroot_target_libdir: get_sysroot_target_libdir(bcx)?, tests: Vec::new(), binaries: Vec::new(), @@ -282,7 +274,6 @@ impl<'gctx> Compilation<'gctx> { let mut search_path = Vec::new(); if is_rustc_tool { search_path.push(self.deps_output[&CompileKind::Host].clone()); - search_path.push(self.sysroot_host_libdir.clone()); } else { search_path.extend(super::filter_dynamic_search_path( self.native_dirs.iter(),