Skip to content

Commit 1b97bc6

Browse files
kvarkalexcrichton
authored andcommitted
Detect clang cl driver mode (#455)
1 parent 7ba57a8 commit 1b97bc6

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cc"
3-
version = "1.0.46"
3+
version = "1.0.47"
44
authors = ["Alex Crichton <[email protected]>"]
55
license = "MIT/Apache-2.0"
66
repository = "https://github.com/alexcrichton/cc-rs"

src/lib.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -1903,13 +1903,19 @@ impl Build {
19031903

19041904
let tool_opt: Option<Tool> = self
19051905
.env_tool(env)
1906-
.map(|(tool, cc, args)| {
1906+
.map(|(tool, wrapper, args)| {
1907+
// find the driver mode, if any
1908+
const DRIVER_MODE: &str = "--driver-mode=";
1909+
let driver_mode = args
1910+
.iter()
1911+
.find(|a| a.starts_with(DRIVER_MODE))
1912+
.map(|a| &a[DRIVER_MODE.len()..]);
19071913
// chop off leading/trailing whitespace to work around
19081914
// semi-buggy build scripts which are shared in
19091915
// makefiles/configure scripts (where spaces are far more
19101916
// lenient)
1911-
let mut t = Tool::new(PathBuf::from(tool.trim()));
1912-
if let Some(cc) = cc {
1917+
let mut t = Tool::with_clang_driver(PathBuf::from(tool.trim()), driver_mode);
1918+
if let Some(cc) = wrapper {
19131919
t.cc_wrapper_path = Some(PathBuf::from(cc));
19141920
}
19151921
for arg in args {
@@ -2062,7 +2068,7 @@ impl Build {
20622068
Err(_) => "nvcc".into(),
20632069
Ok(nvcc) => nvcc,
20642070
};
2065-
let mut nvcc_tool = Tool::with_features(PathBuf::from(nvcc), self.cuda);
2071+
let mut nvcc_tool = Tool::with_features(PathBuf::from(nvcc), None, self.cuda);
20662072
nvcc_tool
20672073
.args
20682074
.push(format!("-ccbin={}", tool.path.display()).into());
@@ -2329,11 +2335,15 @@ impl Default for Build {
23292335
}
23302336

23312337
impl Tool {
2332-
fn new(path: PathBuf) -> Tool {
2333-
Tool::with_features(path, false)
2338+
fn new(path: PathBuf) -> Self {
2339+
Tool::with_features(path, None, false)
23342340
}
23352341

2336-
fn with_features(path: PathBuf, cuda: bool) -> Tool {
2342+
fn with_clang_driver(path: PathBuf, clang_driver: Option<&str>) -> Self {
2343+
Self::with_features(path, clang_driver, false)
2344+
}
2345+
2346+
fn with_features(path: PathBuf, clang_driver: Option<&str>, cuda: bool) -> Self {
23372347
// Try to detect family of the tool from its name, falling back to Gnu.
23382348
let family = if let Some(fname) = path.file_name().and_then(|p| p.to_str()) {
23392349
if fname.contains("clang-cl") {
@@ -2345,13 +2355,17 @@ impl Tool {
23452355
{
23462356
ToolFamily::Msvc { clang_cl: false }
23472357
} else if fname.contains("clang") {
2348-
ToolFamily::Clang
2358+
match clang_driver {
2359+
Some("cl") => ToolFamily::Msvc { clang_cl: true },
2360+
_ => ToolFamily::Clang,
2361+
}
23492362
} else {
23502363
ToolFamily::Gnu
23512364
}
23522365
} else {
23532366
ToolFamily::Gnu
23542367
};
2368+
23552369
Tool {
23562370
path: path,
23572371
cc_wrapper_path: None,

0 commit comments

Comments
 (0)