@@ -1042,6 +1042,13 @@ pub struct OutputFilenames {
1042
1042
crate_stem : String ,
1043
1043
/// Typically based on `.rs` input file name. Any '-' is preserved.
1044
1044
filestem : String ,
1045
+ /// A random string generated per invocation of rustc.
1046
+ ///
1047
+ /// This is prepended to all temporary files so that they do not collide
1048
+ /// during concurrent invocations of rustc, or past invocations that were
1049
+ /// preserved with a flag like `-C save-temps`, since these files may be
1050
+ /// hard-linked.
1051
+ invocation_temp : Option < String > ,
1045
1052
pub single_output_file : Option < OutFileName > ,
1046
1053
temps_directory : Option < PathBuf > ,
1047
1054
pub outputs : OutputTypes ,
@@ -1057,13 +1064,15 @@ impl OutputFilenames {
1057
1064
out_crate_name : String ,
1058
1065
out_filestem : String ,
1059
1066
single_output_file : Option < OutFileName > ,
1067
+ invocation_temp : Option < String > ,
1060
1068
temps_directory : Option < PathBuf > ,
1061
1069
extra : String ,
1062
1070
outputs : OutputTypes ,
1063
1071
) -> Self {
1064
1072
OutputFilenames {
1065
1073
out_directory,
1066
1074
single_output_file,
1075
+ invocation_temp,
1067
1076
temps_directory,
1068
1077
outputs,
1069
1078
crate_stem : format ! ( "{out_crate_name}{extra}" ) ,
@@ -1109,6 +1118,12 @@ impl OutputFilenames {
1109
1118
pub fn temp_path_ext_for_cgu ( & self , ext : & str , codegen_unit_name : & str ) -> PathBuf {
1110
1119
let mut extension = codegen_unit_name. to_string ( ) ;
1111
1120
1121
+ // Append `.{invocation_temp}` to ensure temporary files are unique.
1122
+ if let Some ( rng) = & self . invocation_temp {
1123
+ extension. push ( '.' ) ;
1124
+ extension. push_str ( rng) ;
1125
+ }
1126
+
1112
1127
// FIXME: This is sketchy that we're not appending `.rcgu` when the ext is empty.
1113
1128
// Append `.rcgu.{ext}`.
1114
1129
if !ext. is_empty ( ) {
0 commit comments