Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect clang cl driver mode #455

Merged
merged 1 commit into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cc"
version = "1.0.46"
version = "1.0.47"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
license = "MIT/Apache-2.0"
repository = "https://github.com/alexcrichton/cc-rs"
Expand Down
30 changes: 22 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1903,13 +1903,19 @@ impl Build {

let tool_opt: Option<Tool> = self
.env_tool(env)
.map(|(tool, cc, args)| {
.map(|(tool, wrapper, args)| {
// find the driver mode, if any
const DRIVER_MODE: &str = "--driver-mode=";
let driver_mode = args
.iter()
.find(|a| a.starts_with(DRIVER_MODE))
.map(|a| &a[DRIVER_MODE.len()..]);
// chop off leading/trailing whitespace to work around
// semi-buggy build scripts which are shared in
// makefiles/configure scripts (where spaces are far more
// lenient)
let mut t = Tool::new(PathBuf::from(tool.trim()));
if let Some(cc) = cc {
let mut t = Tool::with_clang_driver(PathBuf::from(tool.trim()), driver_mode);
if let Some(cc) = wrapper {
t.cc_wrapper_path = Some(PathBuf::from(cc));
}
for arg in args {
Expand Down Expand Up @@ -2062,7 +2068,7 @@ impl Build {
Err(_) => "nvcc".into(),
Ok(nvcc) => nvcc,
};
let mut nvcc_tool = Tool::with_features(PathBuf::from(nvcc), self.cuda);
let mut nvcc_tool = Tool::with_features(PathBuf::from(nvcc), None, self.cuda);
nvcc_tool
.args
.push(format!("-ccbin={}", tool.path.display()).into());
Expand Down Expand Up @@ -2329,11 +2335,15 @@ impl Default for Build {
}

impl Tool {
fn new(path: PathBuf) -> Tool {
Tool::with_features(path, false)
fn new(path: PathBuf) -> Self {
Tool::with_features(path, None, false)
}

fn with_features(path: PathBuf, cuda: bool) -> Tool {
fn with_clang_driver(path: PathBuf, clang_driver: Option<&str>) -> Self {
Self::with_features(path, clang_driver, false)
}

fn with_features(path: PathBuf, clang_driver: Option<&str>, cuda: bool) -> Self {
// Try to detect family of the tool from its name, falling back to Gnu.
let family = if let Some(fname) = path.file_name().and_then(|p| p.to_str()) {
if fname.contains("clang-cl") {
Expand All @@ -2345,13 +2355,17 @@ impl Tool {
{
ToolFamily::Msvc { clang_cl: false }
} else if fname.contains("clang") {
ToolFamily::Clang
match clang_driver {
Some("cl") => ToolFamily::Msvc { clang_cl: true },
_ => ToolFamily::Clang,
}
} else {
ToolFamily::Gnu
}
} else {
ToolFamily::Gnu
};

Tool {
path: path,
cc_wrapper_path: None,
Expand Down