Skip to content

Commit

Permalink
refactor: remove unused sysroot_host_libdir
Browse files Browse the repository at this point in the history
Copy from <rust-lang#10469 (comment)>:

> I've never been entirely clear why it does this. rust-lang#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 rust-lang/rust#116412
* servo has moved off from plugins: servo/servo#30508

So should generally be fine.
  • Loading branch information
weihanglo committed Feb 20, 2024
1 parent 762c7d8 commit 1f32908
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
26 changes: 10 additions & 16 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ pub struct TargetInfo {
support_split_debuginfo: Vec<String>,
/// 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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 0 additions & 9 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ pub struct Compilation<'gctx> {
/// May be for the host or for a specific target.
pub deps_output: HashMap<CompileKind, PathBuf>,

/// 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<CompileKind, PathBuf>,

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 1f32908

Please sign in to comment.