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