diff --git a/src/etc/mklldeps.py b/src/etc/mklldeps.py index 8381e4f70409..24b007576aa2 100644 --- a/src/etc/mklldeps.py +++ b/src/etc/mklldeps.py @@ -77,6 +77,13 @@ for lib in out.strip().replace("\n", ' ').split(' '): lib = lib.strip()[2:] elif lib[0] == '-': lib = lib.strip()[1:] + # If this actually points at a literal file then we're on MSVC which now + # prints full paths, so get just the name of the library and strip off the + # trailing ".lib" + elif os.path.exists(lib): + lib = os.path.basename(lib)[:-4] + elif lib[-4:] == '.lib': + lib = lib[:-4] f.write("#[link(name = \"" + lib + "\"") if not llvm_shared and 'LLVM' in lib: f.write(", kind = \"static\"") diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index a2c808cbcb6b..085ea240a505 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -13,7 +13,7 @@ extern crate build_helper; use std::process::Command; use std::env; -use std::path::PathBuf; +use std::path::{PathBuf, Path}; use build_helper::output; @@ -135,8 +135,17 @@ fn main() { &lib[2..] } else if lib.starts_with("-") { &lib[1..] + } else if Path::new(lib).exists() { + // On MSVC llvm-config will print the full name to libraries, but + // we're only interested in the name part + let name = Path::new(lib).file_name().unwrap().to_str().unwrap(); + name.trim_right_matches(".lib") + } else if lib.ends_with(".lib") { + // Some MSVC libraries just come up with `.lib` tacked on, so chop + // that off + lib.trim_right_matches(".lib") } else { - continue; + continue }; // Don't need or want this library, but LLVM's CMake build system @@ -145,7 +154,7 @@ fn main() { // library and it otherwise may just pull in extra dependencies on // libedit which we don't want if name == "LLVMLineEditor" { - continue; + continue } let kind = if name.starts_with("LLVM") { @@ -165,7 +174,9 @@ fn main() { let mut cmd = Command::new(&llvm_config); cmd.arg("--ldflags"); for lib in output(&mut cmd).split_whitespace() { - if is_crossed { + if lib.starts_with("-LIBPATH:") { + println!("cargo:rustc-link-search=native={}", &lib[9..]); + } else if is_crossed { if lib.starts_with("-L") { println!("cargo:rustc-link-search=native={}", lib[2..].replace(&host, &target));