Skip to content

Commit 2b56c9e

Browse files
NobodyXudennisameling
authored andcommitted
Add prefer_clang_cl_over_msvc
1 parent ca81dcc commit 2b56c9e

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/lib.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ pub struct Build {
351351
shell_escaped_flags: Option<bool>,
352352
build_cache: Arc<BuildCache>,
353353
inherit_rustflags: bool,
354+
prefer_clang_cl_over_msvc: bool,
354355
}
355356

356357
/// Represents the types of errors that may occur while using cc-rs.
@@ -479,6 +480,7 @@ impl Build {
479480
shell_escaped_flags: None,
480481
build_cache: Arc::default(),
481482
inherit_rustflags: true,
483+
prefer_clang_cl_over_msvc: false,
482484
}
483485
}
484486

@@ -1290,6 +1292,14 @@ impl Build {
12901292
self
12911293
}
12921294

1295+
/// Prefer to use clang-cl over msvc.
1296+
///
1297+
/// This option defaults to `false`.
1298+
pub fn prefer_clang_cl_over_msvc(&mut self, prefer_clang_cl_over_msvc: bool) -> &mut Build {
1299+
self.prefer_clang_cl_over_msvc = prefer_clang_cl_over_msvc;
1300+
self
1301+
}
1302+
12931303
#[doc(hidden)]
12941304
pub fn __set_env<A, B>(&mut self, a: A, b: B) -> &mut Build
12951305
where
@@ -2868,10 +2878,17 @@ impl Build {
28682878
}
28692879
let target = self.get_target()?;
28702880
let raw_target = self.get_raw_target()?;
2871-
let (env, msvc, gnu, traditional, clang) = if self.cpp {
2872-
("CXX", "cl.exe", "g++", "c++", "clang++")
2881+
2882+
let msvc = if self.prefer_clang_cl_over_msvc {
2883+
"clang-cl.exe"
2884+
} else {
2885+
"cl.exe"
2886+
};
2887+
2888+
let (env, gnu, traditional, clang) = if self.cpp {
2889+
("CXX", "g++", "c++", "clang++")
28732890
} else {
2874-
("CC", "cl.exe", "gcc", "cc", "clang")
2891+
("CC", "gcc", "cc", "clang")
28752892
};
28762893

28772894
// On historical Solaris systems, "cc" may have been Sun Studio, which
@@ -2884,7 +2901,7 @@ impl Build {
28842901
traditional
28852902
};
28862903

2887-
let cl_exe = self.windows_registry_find_tool(&target, "cl.exe");
2904+
let cl_exe = self.windows_registry_find_tool(&target, msvc);
28882905

28892906
let tool_opt: Option<Tool> = self
28902907
.env_tool(env)

0 commit comments

Comments
 (0)