Skip to content

Commit 6925462

Browse files
committed
Auto merge of #7482 - alexcrichton:fix-bin, r=ehuss
Fix wrong directories in PATH on Windows This fixes an accidental regression from #7425 where `PATH` was being augmented on Windows with the wrong search path for target/host libraries. This commit fixes the issue by simply always calculating the host/target library paths for `TargetInfo`, and then we explicitly use the same `TargetInfo` for filling out information in `Compilation`. Closes #7475
2 parents 0fe1638 + 61188d7 commit 6925462

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ pub struct TargetInfo {
2828
crate_types: RefCell<HashMap<String, Option<(String, String)>>>,
2929
/// `cfg` information extracted from `rustc --print=cfg`.
3030
cfg: Vec<Cfg>,
31-
/// Path to the "lib" directory in the sysroot.
32-
pub sysroot_libdir: PathBuf,
31+
/// Path to the "lib" or "bin" directory that rustc uses for its dynamic
32+
/// libraries.
33+
pub sysroot_host_libdir: PathBuf,
34+
/// Path to the "lib" directory in the sysroot which rustc uses for linking
35+
/// target libraries.
36+
pub sysroot_target_libdir: PathBuf,
3337
/// Extra flags to pass to `rustc`, see `env_args`.
3438
pub rustflags: Vec<String>,
3539
/// Extra flags to pass to `rustdoc`, see `env_args`.
@@ -129,24 +133,20 @@ impl TargetInfo {
129133
output_err_info(&process, &output, &error)
130134
),
131135
};
132-
let mut rustlib = PathBuf::from(line);
133-
let sysroot_libdir = match kind {
134-
CompileKind::Host => {
135-
if cfg!(windows) {
136-
rustlib.push("bin");
137-
} else {
138-
rustlib.push("lib");
139-
}
140-
rustlib
141-
}
142-
CompileKind::Target(target) => {
143-
rustlib.push("lib");
144-
rustlib.push("rustlib");
145-
rustlib.push(target.short_name());
146-
rustlib.push("lib");
147-
rustlib
148-
}
149-
};
136+
let mut sysroot_host_libdir = PathBuf::from(line);
137+
if cfg!(windows) {
138+
sysroot_host_libdir.push("bin");
139+
} else {
140+
sysroot_host_libdir.push("lib");
141+
}
142+
let mut sysroot_target_libdir = PathBuf::from(line);
143+
sysroot_target_libdir.push("lib");
144+
sysroot_target_libdir.push("rustlib");
145+
sysroot_target_libdir.push(match &kind {
146+
CompileKind::Host => rustc.host.as_str(),
147+
CompileKind::Target(target) => target.short_name(),
148+
});
149+
sysroot_target_libdir.push("lib");
150150

151151
let cfg = lines
152152
.map(|line| Ok(Cfg::from_str(line)?))
@@ -161,7 +161,8 @@ impl TargetInfo {
161161
Ok(TargetInfo {
162162
crate_type_process,
163163
crate_types: RefCell::new(map),
164-
sysroot_libdir,
164+
sysroot_host_libdir,
165+
sysroot_target_libdir,
165166
// recalculate `rustflags` from above now that we have `cfg`
166167
// information
167168
rustflags: env_args(

src/cargo/core/compiler/compilation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ impl<'cfg> Compilation<'cfg> {
101101
root_output: PathBuf::from("/"),
102102
deps_output: PathBuf::from("/"),
103103
host_deps_output: PathBuf::from("/"),
104-
host_dylib_path: bcx.info(CompileKind::Host).sysroot_libdir.clone(),
105-
target_dylib_path: bcx.info(default_kind).sysroot_libdir.clone(),
104+
host_dylib_path: bcx.info(default_kind).sysroot_host_libdir.clone(),
105+
target_dylib_path: bcx.info(default_kind).sysroot_target_libdir.clone(),
106106
tests: Vec::new(),
107107
binaries: Vec::new(),
108108
extra_env: HashMap::new(),

0 commit comments

Comments
 (0)