@@ -791,7 +791,8 @@ fn apple_sdkroot_wrong() {
791791 let wrong_sdkroot = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" ;
792792 let test = Test :: clang ( ) ;
793793 test. gcc ( )
794- . __set_env ( "SDKROOT" , wrong_sdkroot)
794+ // TODO fix-me https://github.com/rust-lang/cc-rs/pull/1516#discussion_r2295709756
795+ //.__set_env("SDKROOT", wrong_sdkroot)
795796 . target ( "aarch64-apple-ios" )
796797 . file ( "foo.c" )
797798 . compile ( "foo" ) ;
@@ -851,3 +852,100 @@ fn clang_android() {
851852 test. cmd ( 0 ) . must_not_have ( "--target=arm-linux-androideabi" ) ;
852853 }
853854}
855+
856+ #[ cfg( windows) ]
857+ #[ cfg( not( disable_clang_cl_tests) ) ]
858+ mod msvc_clang_cl_tests {
859+ use super :: { reset_env, Test } ;
860+
861+ #[ test]
862+ fn msvc_prefer_clang_cl_over_msvc_disabled_by_default ( ) {
863+ reset_env ( ) ;
864+
865+ let test = Test :: msvc_autodetect ( ) ;
866+
867+ // When prefer_clang_cl_over_msvc is not called (default false), should use MSVC
868+ let compiler = test
869+ . gcc ( )
870+ . try_get_compiler ( )
871+ . expect ( "Failed to get compiler" ) ;
872+
873+ // By default, should be using MSVC (cl.exe) and NOT clang-cl
874+ assert ! ( compiler. is_like_msvc( ) , "Should use MSVC by default" ) ;
875+ assert ! (
876+ !compiler. is_like_clang_cl( ) ,
877+ "Should not use clang-cl by default"
878+ ) ;
879+ }
880+
881+ #[ test]
882+ fn msvc_prefer_clang_cl_over_msvc_enabled ( ) {
883+ reset_env ( ) ;
884+
885+ let test = Test :: msvc_autodetect ( ) ;
886+
887+ let compiler = test
888+ . gcc ( )
889+ // When prefer_clang_cl_over_msvc is true, should use clang-cl.exe
890+ . prefer_clang_cl_over_msvc ( true )
891+ . try_get_compiler ( )
892+ . expect ( "Failed to get compiler" ) ;
893+
894+ assert ! (
895+ compiler. is_like_clang_cl( ) ,
896+ "clang-cl.exe should be identified as clang-cl-like, got {:?}" ,
897+ compiler
898+ ) ;
899+ assert ! (
900+ compiler. is_like_msvc( ) ,
901+ "clang-cl should still be MSVC-like"
902+ ) ;
903+ }
904+
905+ #[ test]
906+ fn msvc_prefer_clang_cl_over_msvc_respects_explicit_cc_env ( ) {
907+ reset_env ( ) ;
908+
909+ let test = Test :: msvc_autodetect ( ) ;
910+
911+ //std::env::set_var("CC", "cl.exe");
912+ let compiler = test
913+ . gcc ( )
914+ . __set_env ( "CC" , "cl.exe" )
915+ . prefer_clang_cl_over_msvc ( true )
916+ . try_get_compiler ( )
917+ . expect ( "Failed to get compiler" ) ;
918+
919+ // The preference should not override explicit compiler setting
920+ assert ! ( compiler. is_like_msvc( ) , "Should still be MSVC-like" ) ;
921+ assert ! (
922+ !compiler. is_like_clang_cl( ) ,
923+ "Should NOT use clang-cl when CC is explicitly set to cl.exe, got {:?}" ,
924+ compiler
925+ ) ;
926+ std:: env:: remove_var ( "CC" ) ; // Clean up after test
927+ }
928+
929+ #[ test]
930+ fn msvc_prefer_clang_cl_over_msvc_cpp_mode ( ) {
931+ reset_env ( ) ;
932+
933+ let test = Test :: msvc_autodetect ( ) ;
934+ let compiler = test
935+ . gcc ( )
936+ . cpp ( true )
937+ . prefer_clang_cl_over_msvc ( true )
938+ . try_get_compiler ( )
939+ . expect ( "Failed to get compiler" ) ;
940+
941+ // Verify clang-cl.exe works correctly in C++ mode
942+ assert ! (
943+ compiler. is_like_clang_cl( ) ,
944+ "clang-cl.exe should be identified as clang-cl-like in C++ mode"
945+ ) ;
946+ assert ! (
947+ compiler. is_like_msvc( ) ,
948+ "clang-cl should still be MSVC-like in C++ mode"
949+ ) ;
950+ }
951+ }
0 commit comments