Skip to content

Commit 61188d7

Browse files
committed
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
1 parent 0a59a76 commit 61188d7

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`.
@@ -127,24 +131,20 @@ impl TargetInfo {
127131
output_err_info(&process, &output, &error)
128132
),
129133
};
130-
let mut rustlib = PathBuf::from(line);
131-
let sysroot_libdir = match kind {
132-
CompileKind::Host => {
133-
if cfg!(windows) {
134-
rustlib.push("bin");
135-
} else {
136-
rustlib.push("lib");
137-
}
138-
rustlib
139-
}
140-
CompileKind::Target(target) => {
141-
rustlib.push("lib");
142-
rustlib.push("rustlib");
143-
rustlib.push(target.short_name());
144-
rustlib.push("lib");
145-
rustlib
146-
}
147-
};
134+
let mut sysroot_host_libdir = PathBuf::from(line);
135+
if cfg!(windows) {
136+
sysroot_host_libdir.push("bin");
137+
} else {
138+
sysroot_host_libdir.push("lib");
139+
}
140+
let mut sysroot_target_libdir = PathBuf::from(line);
141+
sysroot_target_libdir.push("lib");
142+
sysroot_target_libdir.push("rustlib");
143+
sysroot_target_libdir.push(match &kind {
144+
CompileKind::Host => rustc.host.as_str(),
145+
CompileKind::Target(target) => target.short_name(),
146+
});
147+
sysroot_target_libdir.push("lib");
148148

149149
let cfg = lines
150150
.map(|line| Ok(Cfg::from_str(line)?))
@@ -159,7 +159,8 @@ impl TargetInfo {
159159
Ok(TargetInfo {
160160
crate_type_process,
161161
crate_types: RefCell::new(map),
162-
sysroot_libdir,
162+
sysroot_host_libdir,
163+
sysroot_target_libdir,
163164
// recalculate `rustflags` from above now that we have `cfg`
164165
// information
165166
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)