Skip to content

Commit 0509be1

Browse files
alexcrichtonbadboy
authored andcommitted
Update parsing llvm-config output
Now it prints full paths on MSVC, but we're only interested in path names
1 parent 75bcda4 commit 0509be1

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/etc/mklldeps.py

+7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ def runErr(args):
7777
lib = lib.strip()[2:]
7878
elif lib[0] == '-':
7979
lib = lib.strip()[1:]
80+
# If this actually points at a literal file then we're on MSVC which now
81+
# prints full paths, so get just the name of the library and strip off the
82+
# trailing ".lib"
83+
elif os.path.exists(lib):
84+
lib = os.path.basename(lib)[:-4]
85+
elif lib[-4:] == '.lib':
86+
lib = lib[:-4]
8087
f.write("#[link(name = \"" + lib + "\"")
8188
if not llvm_shared and 'LLVM' in lib:
8289
f.write(", kind = \"static\"")

src/librustc_llvm/build.rs

+15-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern crate build_helper;
1313

1414
use std::process::Command;
1515
use std::env;
16-
use std::path::PathBuf;
16+
use std::path::{PathBuf, Path};
1717

1818
use build_helper::output;
1919

@@ -135,8 +135,17 @@ fn main() {
135135
&lib[2..]
136136
} else if lib.starts_with("-") {
137137
&lib[1..]
138+
} else if Path::new(lib).exists() {
139+
// On MSVC llvm-config will print the full name to libraries, but
140+
// we're only interested in the name part
141+
let name = Path::new(lib).file_name().unwrap().to_str().unwrap();
142+
name.trim_right_matches(".lib")
143+
} else if lib.ends_with(".lib") {
144+
// Some MSVC libraries just come up with `.lib` tacked on, so chop
145+
// that off
146+
lib.trim_right_matches(".lib")
138147
} else {
139-
continue;
148+
continue
140149
};
141150

142151
// Don't need or want this library, but LLVM's CMake build system
@@ -145,7 +154,7 @@ fn main() {
145154
// library and it otherwise may just pull in extra dependencies on
146155
// libedit which we don't want
147156
if name == "LLVMLineEditor" {
148-
continue;
157+
continue
149158
}
150159

151160
let kind = if name.starts_with("LLVM") {
@@ -165,7 +174,9 @@ fn main() {
165174
let mut cmd = Command::new(&llvm_config);
166175
cmd.arg("--ldflags");
167176
for lib in output(&mut cmd).split_whitespace() {
168-
if is_crossed {
177+
if lib.starts_with("-LIBPATH:") {
178+
println!("cargo:rustc-link-search=native={}", &lib[9..]);
179+
} else if is_crossed {
169180
if lib.starts_with("-L") {
170181
println!("cargo:rustc-link-search=native={}",
171182
lib[2..].replace(&host, &target));

0 commit comments

Comments
 (0)