@@ -3020,6 +3020,32 @@ fn buildOutputType(
3020
3020
break :l global_cache_directory ;
3021
3021
};
3022
3022
3023
+ for (c_source_files .items ) | * src | {
3024
+ if (! mem .eql (u8 , src .src_path , "-" )) continue ;
3025
+
3026
+ const ext = src .ext orelse
3027
+ fatal ("-E or -x is required when reading from a non-regular file" , .{});
3028
+
3029
+ // "-" is stdin. Dump it to a real file.
3030
+ const sep = fs .path .sep_str ;
3031
+ const sub_path = try std .fmt .allocPrint (arena , "tmp" ++ sep ++ "{x}-stdin{s}" , .{
3032
+ std .crypto .random .int (u64 ), ext .canonicalName (target_info .target ),
3033
+ });
3034
+ try local_cache_directory .handle .makePath ("tmp" );
3035
+ // Note that in one of the happy paths, execve() is used to switch
3036
+ // to clang in which case any cleanup logic that exists for this
3037
+ // temporary file will not run and this temp file will be leaked.
3038
+ // Oh well. It's a minor punishment for using `-x c` which nobody
3039
+ // should be doing. Therefore, we make no effort to clean up. Using
3040
+ // `-` for stdin as a source file always leaks a temp file.
3041
+ var f = try local_cache_directory .handle .createFile (sub_path , .{});
3042
+ defer f .close ();
3043
+ try f .writeFileAll (io .getStdIn (), .{});
3044
+
3045
+ // Convert `sub_path` to be relative to current working directory.
3046
+ src .src_path = try local_cache_directory .join (arena , &.{sub_path });
3047
+ }
3048
+
3023
3049
if (build_options .have_llvm and emit_asm != .no ) {
3024
3050
// LLVM has no way to set this non-globally.
3025
3051
const argv = [_ ][* :0 ]const u8 { "zig (LLVM option parsing)" , "--x86-asm-syntax=intel" };
0 commit comments