@@ -68,13 +68,24 @@ pub fn encode_and_write_metadata(
6868 . unwrap_or_else ( |err| tcx. sess . fatal ( & format ! ( "couldn't create a temp dir: {}" , err) ) ) ;
6969 let metadata_tmpdir = MaybeTempDir :: new ( metadata_tmpdir, tcx. sess . opts . cg . save_temps ) ;
7070 let metadata_filename = metadata_tmpdir. as_ref ( ) . join ( METADATA_FILENAME ) ;
71+ let need_metadata_file = tcx. sess . opts . output_types . contains_key ( & OutputType :: Metadata ) ;
7172 let metadata = match metadata_kind {
7273 MetadataKind :: None => {
73- if tcx. sess . opts . json_artifact_notifications {
74- tcx. sess
75- . parse_sess
76- . span_diagnostic
77- . emit_artifact_notification ( & out_filename, "metadata" ) ;
74+ if need_metadata_file {
75+ // Though creating the empty file here seems to be meaningless, cargo expects it.
76+ if let Err ( e) = std:: fs:: File :: create ( & out_filename) {
77+ tcx. sess . fatal ( & format ! (
78+ "failed to create the file {}: {}" ,
79+ out_filename. display( ) ,
80+ e
81+ ) ) ;
82+ }
83+ if tcx. sess . opts . json_artifact_notifications {
84+ tcx. sess
85+ . parse_sess
86+ . span_diagnostic
87+ . emit_artifact_notification ( & out_filename, "metadata" ) ;
88+ }
7889 }
7990 EncodedMetadata :: empty ( )
8091 }
@@ -83,7 +94,6 @@ pub fn encode_and_write_metadata(
8394
8495 let _prof_timer = tcx. sess . prof . generic_activity ( "write_crate_metadata" ) ;
8596
86- let need_metadata_file = tcx. sess . opts . output_types . contains_key ( & OutputType :: Metadata ) ;
8797 let ( metadata_filename, metadata_tmpdir) = if need_metadata_file {
8898 if let Err ( e) = non_durable_rename ( & metadata_filename, & out_filename) {
8999 tcx. sess . fatal ( & format ! ( "failed to write {}: {}" , out_filename. display( ) , e) ) ;
0 commit comments