]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_driver/lib.rs
Auto merge of #57101 - o01eg:fix-57014, r=alexcrichton
[rust.git] / src / librustc_driver / lib.rs
index 5527c0ad387874a62379cf2f92352b9f0703ddc8..5ff3dc14cdc8a10d9c6020fa62268f0965b7bc73 100644 (file)
@@ -1,13 +1,3 @@
-// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 //! The Rust compiler.
 //!
 //! # Note
 extern crate syntax_ext;
 extern crate syntax_pos;
 
-// Note that the linkage here should be all that we need, on Linux we're not
-// prefixing the symbols here so this should naturally override our default
-// allocator. On OSX it should override via the zone allocator. We shouldn't
-// enable this by default on other platforms, so other platforms aren't handled
-// here yet.
-#[cfg(feature = "jemalloc-sys")]
-extern crate jemalloc_sys;
-
 use driver::CompileController;
 use pretty::{PpMode, UserIdentifiedItem};
 
@@ -294,37 +276,35 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
     }
 
     let target = session::config::host_triple();
-    let mut sysroot_candidates = vec![filesearch::get_or_default_sysroot()];
+    // get target libdir path based on executable binary path
+    let sysroot = filesearch::get_or_default_sysroot();
+    let mut libdir_candidates = vec![filesearch::make_target_lib_path(&sysroot, &target)];
     let path = current_dll_path()
         .and_then(|s| s.canonicalize().ok());
     if let Some(dll) = path {
-        // use `parent` twice to chop off the file name and then also the
-        // directory containing the dll which should be either `lib` or `bin`.
-        if let Some(path) = dll.parent().and_then(|p| p.parent()) {
+        // use `parent` once to chop off the file name
+        if let Some(path) = dll.parent() {
             // The original `path` pointed at the `rustc_driver` crate's dll.
             // Now that dll should only be in one of two locations. The first is
-            // in the compiler's libdir, for example `$sysroot/lib/*.dll`. The
+            // in the compiler's libdir, for example `$sysroot/$libdir/*.dll`. The
             // other is the target's libdir, for example
-            // `$sysroot/lib/rustlib/$target/lib/*.dll`.
+            // `$sysroot/$libdir/rustlib/$target/lib/*.dll`.
             //
             // We don't know which, so let's assume that if our `path` above
-            // ends in `$target` we *could* be in the target libdir, and always
-            // assume that we may be in the main libdir.
-            sysroot_candidates.push(path.to_owned());
-
-            if path.ends_with(target) {
-                sysroot_candidates.extend(path.parent() // chop off `$target`
-                    .and_then(|p| p.parent())           // chop off `rustlib`
-                    .and_then(|p| p.parent())           // chop off `lib`
-                    .map(|s| s.to_owned()));
+            // doesn't end in `$target` we *could* be in the main libdir, and always
+            // assume that we may be in the target libdir.
+            libdir_candidates.push(path.to_owned());
+
+            if !path.parent().map_or(false, |p| p.ends_with(target)) {
+                libdir_candidates.push(path.join(filesearch::target_lib_path(target)));
             }
         }
     }
 
-    let sysroot = sysroot_candidates.iter()
-        .map(|sysroot| {
-            let libdir = filesearch::relative_target_lib_path(&sysroot, &target);
-            sysroot.join(libdir).with_file_name(
+    let sysroot = libdir_candidates.iter()
+        .map(|libdir| {
+            debug!("Trying target libdir: {}", libdir.display());
+            libdir.with_file_name(
                 option_env!("CFG_CODEGEN_BACKENDS_DIR").unwrap_or("codegen-backends"))
         })
         .filter(|f| {
@@ -333,12 +313,12 @@ fn get_codegen_sysroot(backend_name: &str) -> fn() -> Box<dyn CodegenBackend> {
         })
         .next();
     let sysroot = sysroot.unwrap_or_else(|| {
-        let candidates = sysroot_candidates.iter()
+        let candidates = libdir_candidates.iter()
             .map(|p| p.display().to_string())
             .collect::<Vec<_>>()
             .join("\n* ");
         let err = format!("failed to find a `codegen-backends` folder \
-                           in the sysroot candidates:\n* {}", candidates);
+                           in the libdir candidates:\n* {}", candidates);
         early_error(ErrorOutputType::default(), &err);
     });
     info!("probing {} for a codegen backend", sysroot.display());