From 61188d791a29c1baae868f2ba0880c9d6db4092e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 4 Oct 2019 08:04:48 -0700 Subject: [PATCH] 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 --- .../compiler/build_context/target_info.rs | 43 ++++++++++--------- src/cargo/core/compiler/compilation.rs | 4 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 64b7f079ba2..273ceb0b413 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -28,8 +28,12 @@ pub struct TargetInfo { crate_types: RefCell>>, /// `cfg` information extracted from `rustc --print=cfg`. cfg: Vec, - /// 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, /// Extra flags to pass to `rustdoc`, see `env_args`. @@ -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)?)) @@ -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( diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 86afe35ac34..140a024b104 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -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(),