@@ -59,6 +59,7 @@ use std::process::Command;
5959pub struct Config {
6060 path : PathBuf ,
6161 generator : Option < OsString > ,
62+ generator_toolset : Option < OsString > ,
6263 cflags : OsString ,
6364 cxxflags : OsString ,
6465 asmflags : OsString ,
@@ -182,6 +183,7 @@ impl Config {
182183 Config {
183184 path : env:: current_dir ( ) . unwrap ( ) . join ( path) ,
184185 generator : None ,
186+ generator_toolset : None ,
185187 cflags : OsString :: new ( ) ,
186188 cxxflags : OsString :: new ( ) ,
187189 asmflags : OsString :: new ( ) ,
@@ -224,6 +226,15 @@ impl Config {
224226 self
225227 }
226228
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+
227238 /// Adds a custom flag to pass down to the C compiler, supplementing those
228239 /// that this library already passes.
229240 pub fn cflag < P : AsRef < OsStr > > ( & mut self , flag : P ) -> & mut Config {
@@ -572,13 +583,19 @@ impl Config {
572583 }
573584 if !is_ninja && !using_nmake_generator {
574585 if target. contains ( "x86_64" ) {
575- cmd. arg ( "-Thost=x64" ) ;
586+ if self . generator_toolset . is_none ( ) {
587+ cmd. arg ( "-Thost=x64" ) ;
588+ }
576589 cmd. arg ( "-Ax64" ) ;
577590 } else if target. contains ( "thumbv7a" ) {
578- cmd. arg ( "-Thost=x64" ) ;
591+ if self . generator_toolset . is_none ( ) {
592+ cmd. arg ( "-Thost=x64" ) ;
593+ }
579594 cmd. arg ( "-Aarm" ) ;
580595 } else if target. contains ( "aarch64" ) {
581- cmd. arg ( "-Thost=x64" ) ;
596+ if self . generator_toolset . is_none ( ) {
597+ cmd. arg ( "-Thost=x64" ) ;
598+ }
582599 cmd. arg ( "-AARM64" ) ;
583600 } else if target. contains ( "i686" ) {
584601 use cc:: windows_registry:: { find_vs_version, VsVers } ;
@@ -587,7 +604,9 @@ impl Config {
587604 // 32-bit x86 toolset used to be the default for all hosts,
588605 // but Visual Studio 2019 changed the default toolset to match the host,
589606 // 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+ }
591610 cmd. arg ( "-AWin32" ) ;
592611 }
593612 _ => { }
@@ -614,6 +633,9 @@ impl Config {
614633 if let Some ( ref generator) = generator {
615634 cmd. arg ( "-G" ) . arg ( generator) ;
616635 }
636+ if let Some ( ref generator_toolset) = self . generator_toolset {
637+ cmd. arg ( "-T" ) . arg ( generator_toolset) ;
638+ }
617639 let profile = self . get_profile ( ) . to_string ( ) ;
618640 for & ( ref k, ref v) in & self . defines {
619641 let mut os = OsString :: from ( "-D" ) ;
0 commit comments