@@ -902,3 +902,41 @@ fn test_rustc_abi() {
902
902
assert ! ( !check_ignore( & config, "//@ ignore-rustc_abi-x86-sse2" ) ) ;
903
903
assert ! ( check_ignore( & config, "//@ only-rustc_abi-x86-sse2" ) ) ;
904
904
}
905
+
906
+ #[ test]
907
+ fn test_supported_crate_types ( ) {
908
+ // Basic assumptions check on under-test compiler's `--print=supported-crate-types` output based
909
+ // on knowledge about the cherry-picked `x86_64-unknown-linux-gnu` and `wasm32-unknown-unknown`
910
+ // targets. Also smoke tests the `needs-crate-type` directive itself.
911
+
912
+ use std:: collections:: HashSet ;
913
+
914
+ let config = cfg ( ) . target ( "x86_64-unknown-linux-gnu" ) . build ( ) ;
915
+ assert_eq ! (
916
+ config. supported_crate_types( ) . iter( ) . map( String :: as_str) . collect:: <HashSet <_>>( ) ,
917
+ HashSet :: from( [ "bin" , "cdylib" , "dylib" , "lib" , "proc-macro" , "rlib" , "staticlib" ] ) ,
918
+ ) ;
919
+ assert ! ( !check_ignore( & config, "//@ needs-crate-type: rlib" ) ) ;
920
+ assert ! ( !check_ignore( & config, "//@ needs-crate-type: dylib" ) ) ;
921
+ assert ! ( !check_ignore(
922
+ & config,
923
+ "//@ needs-crate-type: bin, cdylib, dylib, lib, proc-macro, rlib, staticlib"
924
+ ) ) ;
925
+
926
+ let config = cfg ( ) . target ( "wasm32-unknown-unknown" ) . build ( ) ;
927
+ assert_eq ! (
928
+ config. supported_crate_types( ) . iter( ) . map( String :: as_str) . collect:: <HashSet <_>>( ) ,
929
+ HashSet :: from( [ "bin" , "cdylib" , "lib" , "rlib" , "staticlib" ] ) ,
930
+ ) ;
931
+
932
+ // rlib is supported
933
+ assert ! ( !check_ignore( & config, "//@ needs-crate-type: rlib" ) ) ;
934
+ // dylib is not
935
+ assert ! ( check_ignore( & config, "//@ needs-crate-type: dylib" ) ) ;
936
+ // If multiple crate types are specified, then all specified crate types need to be supported.
937
+ assert ! ( check_ignore( & config, "//@ needs-crate-type: cdylib, dylib" ) ) ;
938
+ assert ! ( check_ignore(
939
+ & config,
940
+ "//@ needs-crate-type: bin, cdylib, dylib, lib, proc-macro, rlib, staticlib"
941
+ ) ) ;
942
+ }
0 commit comments