Skip to content

Commit 94522b6

Browse files
NobodyXudennisameling
authored andcommitted
Add prefer_clang_cl_over_msvc
1 parent 06f7709 commit 94522b6

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
@@ -2878,10 +2888,17 @@ impl Build {
28782888
}
28792889
let target = self.get_target()?;
28802890
let raw_target = self.get_raw_target()?;
2881-
let (env, msvc, gnu, traditional, clang) = if self.cpp {
2882-
("CXX", "cl.exe", "g++", "c++", "clang++")
2891+
2892+
let msvc = if self.prefer_clang_cl_over_msvc {
2893+
"clang-cl.exe"
2894+
} else {
2895+
"cl.exe"
2896+
};
2897+
2898+
let (env, gnu, traditional, clang) = if self.cpp {
2899+
("CXX", "g++", "c++", "clang++")
28832900
} else {
2884-
("CC", "cl.exe", "gcc", "cc", "clang")
2901+
("CC", "gcc", "cc", "clang")
28852902
};
28862903

28872904
// On historical Solaris systems, "cc" may have been Sun Studio, which
@@ -2894,7 +2911,7 @@ impl Build {
28942911
traditional
28952912
};
28962913

2897-
let cl_exe = self.windows_registry_find_tool(&target, "cl.exe");
2914+
let cl_exe = self.windows_registry_find_tool(&target, msvc);
28982915

28992916
let tool_opt: Option<Tool> = self
29002917
.env_tool(env)

0 commit comments

Comments
 (0)