@@ -851,3 +851,97 @@ fn clang_android() {
851
851
test. cmd ( 0 ) . must_not_have ( "--target=arm-linux-androideabi" ) ;
852
852
}
853
853
}
854
+
855
+ #[ test]
856
+ #[ cfg( windows) ]
857
+ fn msvc_prefer_clang_cl_over_msvc_disabled_by_default ( ) {
858
+ reset_env ( ) ;
859
+
860
+ let test = Test :: msvc_autodetect ( ) ;
861
+
862
+ // When prefer_clang_cl_over_msvc is not called (default false), should use MSVC
863
+ let compiler = test
864
+ . gcc ( )
865
+ . try_get_compiler ( )
866
+ . expect ( "Failed to get compiler" ) ;
867
+
868
+ // By default, should be using MSVC (cl.exe) and NOT clang-cl
869
+ assert ! ( compiler. is_like_msvc( ) , "Should use MSVC by default" ) ;
870
+ assert ! (
871
+ !compiler. is_like_clang_cl( ) ,
872
+ "Should not use clang-cl by default"
873
+ ) ;
874
+ }
875
+
876
+ #[ test]
877
+ #[ cfg( windows) ]
878
+ fn msvc_prefer_clang_cl_over_msvc_enabled ( ) {
879
+ reset_env ( ) ;
880
+
881
+ let test = Test :: msvc_autodetect ( ) ;
882
+
883
+ let compiler = test
884
+ . gcc ( )
885
+ // When prefer_clang_cl_over_msvc is true, should use clang-cl.exe
886
+ . prefer_clang_cl_over_msvc ( true )
887
+ . try_get_compiler ( )
888
+ . expect ( "Failed to get compiler" ) ;
889
+
890
+ assert ! (
891
+ compiler. is_like_clang_cl( ) ,
892
+ "clang-cl.exe should be identified as clang-cl-like, got {:?}" ,
893
+ compiler
894
+ ) ;
895
+ assert ! (
896
+ compiler. is_like_msvc( ) ,
897
+ "clang-cl should still be MSVC-like"
898
+ ) ;
899
+ }
900
+
901
+ #[ test]
902
+ #[ cfg( windows) ]
903
+ fn msvc_prefer_clang_cl_over_msvc_respects_explicit_cc_env ( ) {
904
+ reset_env ( ) ;
905
+
906
+ let test = Test :: msvc_autodetect ( ) ;
907
+ let compiler = test
908
+ . gcc ( )
909
+ // We can't set the CC=cl.exe environment variable directly in the test as it's removed
910
+ // in mod.rs, so we simulate it by setting the compiler directly
911
+ . compiler ( "cl.exe" )
912
+ . prefer_clang_cl_over_msvc ( true )
913
+ . try_get_compiler ( )
914
+ . expect ( "Failed to get compiler" ) ;
915
+
916
+ // The preference should not override explicit compiler setting
917
+ assert ! ( compiler. is_like_msvc( ) , "Should still be MSVC-like" ) ;
918
+ assert ! (
919
+ !compiler. is_like_clang_cl( ) ,
920
+ "Should NOT use clang-cl when CC is explicitly set to cl.exe, got {:?}" ,
921
+ compiler
922
+ ) ;
923
+ }
924
+
925
+ #[ test]
926
+ #[ cfg( windows) ]
927
+ fn msvc_prefer_clang_cl_over_msvc_cpp_mode ( ) {
928
+ reset_env ( ) ;
929
+
930
+ let test = Test :: msvc_autodetect ( ) ;
931
+ let compiler = test
932
+ . gcc ( )
933
+ . cpp ( true )
934
+ . prefer_clang_cl_over_msvc ( true )
935
+ . try_get_compiler ( )
936
+ . expect ( "Failed to get compiler" ) ;
937
+
938
+ // Verify clang-cl.exe works correctly in C++ mode
939
+ assert ! (
940
+ compiler. is_like_clang_cl( ) ,
941
+ "clang-cl.exe should be identified as clang-cl-like in C++ mode"
942
+ ) ;
943
+ assert ! (
944
+ compiler. is_like_msvc( ) ,
945
+ "clang-cl should still be MSVC-like in C++ mode"
946
+ ) ;
947
+ }
0 commit comments