@@ -37,7 +37,7 @@ use std::collections::hash_map::RandomState;
37
37
#[ cfg( feature = "dist-client" ) ]
38
38
use std:: env:: consts:: { DLL_PREFIX , EXE_EXTENSION } ;
39
39
use std:: env:: consts:: DLL_EXTENSION ;
40
- use std:: ffi:: { OsStr , OsString } ;
40
+ use std:: ffi:: OsString ;
41
41
use std:: fmt;
42
42
use std:: fs;
43
43
use std:: hash:: Hash ;
@@ -133,7 +133,7 @@ pub struct ParsedArguments {
133
133
dep_info : Option < PathBuf > ,
134
134
/// rustc says that emits .rlib for --emit=metadata
135
135
/// https://github.com/rust-lang/rust/issues/54852
136
- rename_rlib_to_rmeta : bool ,
136
+ emit : HashSet < String > ,
137
137
/// The value of any `--color` option passed on the commandline.
138
138
color_mode : ColorMode ,
139
139
}
@@ -317,6 +317,9 @@ fn get_compiler_outputs<T>(creator: &T,
317
317
let outputs = run_input_output ( cmd, None ) ;
318
318
Box :: new ( outputs. and_then ( move |output| -> Result < _ > {
319
319
let outstr = String :: from_utf8 ( output. stdout ) . chain_err ( || "Error parsing rustc output" ) ?;
320
+ if log_enabled ! ( Trace ) {
321
+ trace ! ( "get_compiler_outputs: {:?}" , outstr) ;
322
+ }
320
323
Ok ( outstr. lines ( ) . map ( |l| l. to_owned ( ) ) . collect ( ) )
321
324
} ) )
322
325
}
@@ -873,8 +876,6 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
873
876
cannot_cache ! ( "unsupported --emit" ) ;
874
877
}
875
878
876
- let rename_rlib_to_rmeta = emit. contains ( "metadata" ) && !emit. contains ( "link" ) ;
877
-
878
879
// Figure out the dep-info filename, if emitting dep-info.
879
880
let dep_info = if emit. contains ( "dep-info" ) {
880
881
let mut dep_info = crate_name. clone ( ) ;
@@ -915,7 +916,7 @@ fn parse_arguments(arguments: &[OsString], cwd: &Path) -> CompilerArguments<Pars
915
916
staticlibs : staticlibs,
916
917
crate_name : crate_name. to_string ( ) ,
917
918
dep_info : dep_info. map ( |s| s. into ( ) ) ,
918
- rename_rlib_to_rmeta ,
919
+ emit ,
919
920
color_mode,
920
921
} )
921
922
}
@@ -948,7 +949,7 @@ impl<T> CompilerHasher<T> for RustHasher
948
949
crate_name,
949
950
crate_types,
950
951
dep_info,
951
- rename_rlib_to_rmeta ,
952
+ emit ,
952
953
color_mode : _,
953
954
} ,
954
955
} = me;
@@ -1064,7 +1065,26 @@ impl<T> CompilerHasher<T> for RustHasher
1064
1065
let flat_os_string_arguments: Vec < OsString > = os_string_arguments. into_iter ( )
1065
1066
. flat_map ( |( arg, val) | iter:: once ( arg) . into_iter ( ) . chain ( val) )
1066
1067
. collect ( ) ;
1067
- Box :: new ( get_compiler_outputs ( & creator, & executable, & flat_os_string_arguments, & cwd, & env_vars) . map ( move |outputs| {
1068
+ Box :: new ( get_compiler_outputs ( & creator, & executable, & flat_os_string_arguments, & cwd, & env_vars) . map ( move |mut outputs| {
1069
+ if emit. contains ( "metadata" ) {
1070
+ // rustc currently does not report rmeta outputs with --print file-names
1071
+ // --emit metadata the rlib is printed, and with --emit metadata,link
1072
+ // only the rlib is printed.
1073
+ let rlibs: HashSet < _ > = outputs. iter ( ) . cloned ( ) . filter ( |p| {
1074
+ p. ends_with ( ".rlib" )
1075
+ } ) . collect ( ) ;
1076
+ for lib in rlibs {
1077
+ let rmeta = lib. replacen ( ".rlib" , ".rmeta" , 1 ) ;
1078
+ // Do this defensively for future versions of rustc that may
1079
+ // be fixed.
1080
+ if !outputs. contains ( & rmeta) {
1081
+ outputs. push ( rmeta) ;
1082
+ }
1083
+ if !emit. contains ( "link" ) {
1084
+ outputs. retain ( |p| * p != lib) ;
1085
+ }
1086
+ }
1087
+ }
1068
1088
let output_dir = PathBuf :: from ( output_dir) ;
1069
1089
// Convert output files into a map of basename -> full path.
1070
1090
let mut outputs = outputs. into_iter ( )
@@ -1085,14 +1105,6 @@ impl<T> CompilerHasher<T> for RustHasher
1085
1105
arguments. push ( Argument :: WithValue ( "--color" , ArgData :: Color ( "always" . into ( ) ) , ArgDisposition :: Separated ) ) ;
1086
1106
let inputs = source_files. into_iter ( ) . chain ( abs_externs) . chain ( abs_staticlibs) . collect ( ) ;
1087
1107
1088
- if rename_rlib_to_rmeta {
1089
- for output in outputs. values_mut ( ) {
1090
- if output. extension ( ) == Some ( OsStr :: new ( "rlib" ) ) {
1091
- output. set_extension ( "rmeta" ) ;
1092
- }
1093
- }
1094
- }
1095
-
1096
1108
HashResult {
1097
1109
key : m. finish ( ) ,
1098
1110
compilation : Box :: new ( RustCompilation {
@@ -2038,6 +2050,9 @@ c:/foo/bar.rs:
2038
2050
for s in [ "foo.rs" , "bar.rs" , "bar.rlib" , "libbaz.a" ] . iter ( ) {
2039
2051
f. touch ( s) . unwrap ( ) ;
2040
2052
}
2053
+ let mut emit = HashSet :: new ( ) ;
2054
+ emit. insert ( "link" . to_string ( ) ) ;
2055
+ emit. insert ( "metadata" . to_string ( ) ) ;
2041
2056
let hasher = Box :: new ( RustHasher {
2042
2057
executable : "rustc" . into ( ) ,
2043
2058
host : "x86-64-unknown-unknown-unknown" . to_owned ( ) ,
@@ -2063,7 +2078,7 @@ c:/foo/bar.rs:
2063
2078
crate_name : "foo" . into ( ) ,
2064
2079
crate_types : CrateTypes { rlib : true , staticlib : false } ,
2065
2080
dep_info : None ,
2066
- rename_rlib_to_rmeta : false ,
2081
+ emit : emit ,
2067
2082
color_mode : ColorMode :: Auto ,
2068
2083
}
2069
2084
} ) ;
@@ -2108,7 +2123,7 @@ c:/foo/bar.rs:
2108
2123
assert_eq ! ( res. key, digest) ;
2109
2124
let mut out = res. compilation . outputs ( ) . map ( |( k, _) | k. to_owned ( ) ) . collect :: < Vec < _ > > ( ) ;
2110
2125
out. sort ( ) ;
2111
- assert_eq ! ( out, vec![ "foo.a" , "foo.rlib" ] ) ;
2126
+ assert_eq ! ( out, vec![ "foo.a" , "foo.rlib" , "foo.rmeta" ] ) ;
2112
2127
}
2113
2128
2114
2129
fn hash_key < ' a , F > ( f : & TestFixture , args : & [ OsString ] , env_vars : & [ ( OsString , OsString ) ] ,
0 commit comments