Skip to content

Commit

Permalink
Fix wrong directories in PATH on Windows
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alexcrichton committed Oct 4, 2019
1 parent 0a59a76 commit 61188d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
43 changes: 22 additions & 21 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ pub struct TargetInfo {
crate_types: RefCell<HashMap<String, Option<(String, String)>>>,
/// `cfg` information extracted from `rustc --print=cfg`.
cfg: Vec<Cfg>,
/// Path to the "lib" directory in the sysroot.
pub sysroot_libdir: 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,
/// Extra flags to pass to `rustc`, see `env_args`.
pub rustflags: Vec<String>,
/// Extra flags to pass to `rustdoc`, see `env_args`.
Expand Down Expand Up @@ -127,24 +131,20 @@ impl TargetInfo {
output_err_info(&process, &output, &error)
),
};
let mut rustlib = PathBuf::from(line);
let sysroot_libdir = match kind {
CompileKind::Host => {
if cfg!(windows) {
rustlib.push("bin");
} else {
rustlib.push("lib");
}
rustlib
}
CompileKind::Target(target) => {
rustlib.push("lib");
rustlib.push("rustlib");
rustlib.push(target.short_name());
rustlib.push("lib");
rustlib
}
};
let mut sysroot_host_libdir = PathBuf::from(line);
if cfg!(windows) {
sysroot_host_libdir.push("bin");
} else {
sysroot_host_libdir.push("lib");
}
let mut sysroot_target_libdir = PathBuf::from(line);
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 cfg = lines
.map(|line| Ok(Cfg::from_str(line)?))
Expand All @@ -159,7 +159,8 @@ impl TargetInfo {
Ok(TargetInfo {
crate_type_process,
crate_types: RefCell::new(map),
sysroot_libdir,
sysroot_host_libdir,
sysroot_target_libdir,
// recalculate `rustflags` from above now that we have `cfg`
// information
rustflags: env_args(
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ impl<'cfg> Compilation<'cfg> {
root_output: PathBuf::from("/"),
deps_output: PathBuf::from("/"),
host_deps_output: PathBuf::from("/"),
host_dylib_path: bcx.info(CompileKind::Host).sysroot_libdir.clone(),
target_dylib_path: bcx.info(default_kind).sysroot_libdir.clone(),
host_dylib_path: bcx.info(default_kind).sysroot_host_libdir.clone(),
target_dylib_path: bcx.info(default_kind).sysroot_target_libdir.clone(),
tests: Vec::new(),
binaries: Vec::new(),
extra_env: HashMap::new(),
Expand Down

0 comments on commit 61188d7

Please sign in to comment.