authorgravatar for zhylmzr@gmail.comzhylmzr <zhylmzr@gmail.com> 2024-07-23 01:53:51+08:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-01-29 10:48:36+01:00
log308ba80597864ab12b77cff1ce28f001ad551fdf
tree3b8d28b3622a8ad508d54e31fef8baa1ba645af0
parent7843deb16be3e28068398c1397345c8bb22ea6c6

fix(cc): make link and preprocessor logic to be more consistent with

clang's behavior. 1. `zig cc main.c -o /dev/null` shouldn't emit a.out 2. `zig cc -E main.c` and `zig cc -E main -o -` should output to stdout

1 files changed, 8 insertions(+), 3 deletions(-)

src/main.zig+8-3
......@@ -2718,7 +2718,9 @@ fn buildOutputType(
27182718 switch (c_out_mode orelse .link) {
27192719 .link => {
27202720 create_module.opts.output_mode = if (is_shared_lib) .Lib else .Exe;
2721 emit_bin = if (out_path) |p| .{ .yes = p } else EmitBin.yes_a_out;
2721 if (emit_bin != .no) {
2722 emit_bin = if (out_path) |p| .{ .yes = p } else EmitBin.yes_a_out;
2723 }
27222724 if (emit_llvm) {
27232725 fatal("-emit-llvm cannot be used when linking", .{});
27242726 }
......@@ -2768,10 +2770,13 @@ fn buildOutputType(
27682770 emit_bin = if (out_path) |p| .{ .yes = p } else .yes_default_path;
27692771 clang_preprocessor_mode = .pch;
27702772 } else {
2771 if (out_path) |p| {
2772 emit_bin = .{ .yes = p };
2773 // If the output path is "-" (stdout), then we need to emit the preprocessed output to stdout
2774 // like "clang -E main.c -o -" does.
2775 if (out_path != null and !mem.eql(u8, out_path.?, "-")) {
2776 emit_bin = .{ .yes = out_path.? };
27732777 clang_preprocessor_mode = .yes;
27742778 } else {
2779 emit_bin = .no;
27752780 clang_preprocessor_mode = .stdout;
27762781 }
27772782 }