Skip to content

Commit 09fb58f

Browse files
refactor: move both sides of --driver-mode=cl check to Tool::get_base_compiler
Do this by plumbing through `args` associated with the compiler wrapper, if any, instead of handling it in calling code.
1 parent 4e1c4e6 commit 09fb58f

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,16 +2753,13 @@ impl Build {
27532753
let tool_opt: Option<Tool> = self
27542754
.env_tool(env)
27552755
.map(|(tool, wrapper, args)| {
2756-
// find the driver mode, if any
2757-
const DRIVER_MODE: &str = "--driver-mode=";
2758-
let driver_mode = args.iter().find_map(|a| a.strip_suffix(DRIVER_MODE));
27592756
// Chop off leading/trailing whitespace to work around
27602757
// semi-buggy build scripts which are shared in
27612758
// makefiles/configure scripts (where spaces are far more
27622759
// lenient)
2763-
let mut t = Tool::with_clang_driver(
2760+
let mut t = Tool::with_args(
27642761
tool,
2765-
driver_mode,
2762+
args.clone(),
27662763
&self.build_cache.cached_compiler_family,
27672764
&self.cargo_output,
27682765
out_dir,
@@ -2882,7 +2879,7 @@ impl Build {
28822879
};
28832880
let mut nvcc_tool = Tool::with_features(
28842881
nvcc,
2885-
None,
2882+
vec![],
28862883
self.cuda,
28872884
&self.build_cache.cached_compiler_family,
28882885
&self.cargo_output,

src/tool.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,24 @@ impl Tool {
4646
) -> Self {
4747
Self::with_features(
4848
path,
49-
None,
49+
vec![],
5050
false,
5151
cached_compiler_family,
5252
cargo_output,
5353
out_dir,
5454
)
5555
}
5656

57-
pub(crate) fn with_clang_driver(
57+
pub(crate) fn with_args(
5858
path: PathBuf,
59-
clang_driver: Option<&str>,
59+
args: Vec<String>,
6060
cached_compiler_family: &RwLock<HashMap<Box<Path>, ToolFamily>>,
6161
cargo_output: &CargoOutput,
6262
out_dir: Option<&Path>,
6363
) -> Self {
6464
Self::with_features(
6565
path,
66-
clang_driver,
66+
args,
6767
false,
6868
cached_compiler_family,
6969
cargo_output,
@@ -88,7 +88,7 @@ impl Tool {
8888

8989
pub(crate) fn with_features(
9090
path: PathBuf,
91-
clang_driver: Option<&str>,
91+
args: Vec<String>,
9292
cuda: bool,
9393
cached_compiler_family: &RwLock<HashMap<Box<Path>, ToolFamily>>,
9494
cargo_output: &CargoOutput,
@@ -235,12 +235,19 @@ impl Tool {
235235
Some(fname) if fname.ends_with("cl") || fname == "cl.exe" => {
236236
ToolFamily::Msvc { clang_cl: false }
237237
}
238-
Some(fname) if fname.contains("clang") => match clang_driver {
239-
Some("cl") => ToolFamily::Msvc { clang_cl: true },
240-
_ => ToolFamily::Clang {
241-
zig_cc: is_zig_cc(&path, cargo_output),
242-
},
243-
},
238+
Some(fname) if fname.contains("clang") => {
239+
let is_clang_cl = args
240+
.iter()
241+
.find_map(|a| a.strip_prefix("--driver-mode="))
242+
.map_or(false, |dm| dm == "cl");
243+
if is_clang_cl {
244+
ToolFamily::Msvc { clang_cl: true }
245+
} else {
246+
ToolFamily::Clang {
247+
zig_cc: is_zig_cc(&path, cargo_output),
248+
}
249+
}
250+
}
244251
Some(fname) if fname.contains("zig") => ToolFamily::Clang { zig_cc: true },
245252
_ => ToolFamily::Gnu,
246253
}

0 commit comments

Comments
 (0)