@@ -59,6 +59,7 @@ use std::process::Command;
59
59
pub struct Config {
60
60
path : PathBuf ,
61
61
generator : Option < OsString > ,
62
+ generator_toolset : Option < OsString > ,
62
63
cflags : OsString ,
63
64
cxxflags : OsString ,
64
65
asmflags : OsString ,
@@ -182,6 +183,7 @@ impl Config {
182
183
Config {
183
184
path : env:: current_dir ( ) . unwrap ( ) . join ( path) ,
184
185
generator : None ,
186
+ generator_toolset : None ,
185
187
cflags : OsString :: new ( ) ,
186
188
cxxflags : OsString :: new ( ) ,
187
189
asmflags : OsString :: new ( ) ,
@@ -224,6 +226,15 @@ impl Config {
224
226
self
225
227
}
226
228
229
+ /// Sets the toolset name (-T) if supported by generator.
230
+ /// Can be used to compile with CLang/LLV instead of msvc when Visual Studio generator is selected.
231
+ ///
232
+ /// If unset, will use the default toolset of the selected generator.
233
+ pub fn generator_toolset < T : AsRef < OsStr > > ( & mut self , toolset_name : T ) -> & mut Config {
234
+ self . generator_toolset = Some ( toolset_name. as_ref ( ) . to_owned ( ) ) ;
235
+ self
236
+ }
237
+
227
238
/// Adds a custom flag to pass down to the C compiler, supplementing those
228
239
/// that this library already passes.
229
240
pub fn cflag < P : AsRef < OsStr > > ( & mut self , flag : P ) -> & mut Config {
@@ -572,13 +583,19 @@ impl Config {
572
583
}
573
584
if !is_ninja && !using_nmake_generator {
574
585
if target. contains ( "x86_64" ) {
575
- cmd. arg ( "-Thost=x64" ) ;
586
+ if self . generator_toolset . is_none ( ) {
587
+ cmd. arg ( "-Thost=x64" ) ;
588
+ }
576
589
cmd. arg ( "-Ax64" ) ;
577
590
} else if target. contains ( "thumbv7a" ) {
578
- cmd. arg ( "-Thost=x64" ) ;
591
+ if self . generator_toolset . is_none ( ) {
592
+ cmd. arg ( "-Thost=x64" ) ;
593
+ }
579
594
cmd. arg ( "-Aarm" ) ;
580
595
} else if target. contains ( "aarch64" ) {
581
- cmd. arg ( "-Thost=x64" ) ;
596
+ if self . generator_toolset . is_none ( ) {
597
+ cmd. arg ( "-Thost=x64" ) ;
598
+ }
582
599
cmd. arg ( "-AARM64" ) ;
583
600
} else if target. contains ( "i686" ) {
584
601
use cc:: windows_registry:: { find_vs_version, VsVers } ;
@@ -587,7 +604,9 @@ impl Config {
587
604
// 32-bit x86 toolset used to be the default for all hosts,
588
605
// but Visual Studio 2019 changed the default toolset to match the host,
589
606
// so we need to manually override it for x86 targets
590
- cmd. arg ( "-Thost=x86" ) ;
607
+ if self . generator_toolset . is_none ( ) {
608
+ cmd. arg ( "-Thost=x86" ) ;
609
+ }
591
610
cmd. arg ( "-AWin32" ) ;
592
611
}
593
612
_ => { }
@@ -614,6 +633,9 @@ impl Config {
614
633
if let Some ( ref generator) = generator {
615
634
cmd. arg ( "-G" ) . arg ( generator) ;
616
635
}
636
+ if let Some ( ref generator_toolset) = self . generator_toolset {
637
+ cmd. arg ( "-T" ) . arg ( generator_toolset) ;
638
+ }
617
639
let profile = self . get_profile ( ) . to_string ( ) ;
618
640
for & ( ref k, ref v) in & self . defines {
619
641
let mut os = OsString :: from ( "-D" ) ;
0 commit comments