Skip to content

Commit

Permalink
Update parsing llvm-config output
Browse files Browse the repository at this point in the history
Now it prints full paths on MSVC, but we're only interested in path names
  • Loading branch information
alexcrichton authored and badboy committed Jul 29, 2016
1 parent 75bcda4 commit 0509be1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/etc/mklldeps.py
Expand Up @@ -77,6 +77,13 @@ def runErr(args):
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\"")
Expand Down
19 changes: 15 additions & 4 deletions src/librustc_llvm/build.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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") {
Expand All @@ -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));
Expand Down

0 comments on commit 0509be1

Please sign in to comment.