| ... | ... | @@ -3753,22 +3753,64 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P |
| 3753 | 3753 | }; |
| 3754 | 3754 | const o_basename = try std.fmt.allocPrint(arena, "{s}{s}", .{ o_basename_noext, out_ext }); |
| 3755 | 3755 | |
| 3756 | try argv.appendSlice(&[_][]const u8{ |
| 3757 | self_exe_path, |
| 3758 | "clang", |
| 3759 | c_object.src.src_path, |
| 3760 | }); |
| 3761 | try argv.appendSlice(c_object.src.extra_flags); |
| 3762 | |
| 3763 | const ext = classifyFileExt(c_object.src.src_path); |
| 3764 | |
| 3765 | // When all these flags are true, it means that the entire purpose of |
| 3766 | // this compilation is to perform a single zig cc operation. This means |
| 3767 | // that we could "tail call" clang by doing an execve, and any use of |
| 3768 | // the caching system would actually be problematic since the user is |
| 3769 | // presumably doing their own caching by using dep file flags. |
| 3770 | if (comp.disable_c_depfile and comp.clang_passthrough_mode and std.process.can_execv and direct_o) { |
| 3771 | try comp.addCCArgs(arena, &argv, ext, null); |
| 3772 | |
| 3773 | const out_obj_path = if (comp.bin_file.options.emit) |emit| |
| 3774 | try emit.directory.join(arena, &.{emit.sub_path}) |
| 3775 | else |
| 3776 | "/dev/null"; |
| 3777 | |
| 3778 | try argv.ensureUnusedCapacity(5); |
| 3779 | switch (comp.clang_preprocessor_mode) { |
| 3780 | .no => argv.appendSliceAssumeCapacity(&[_][]const u8{ "-c", "-o", out_obj_path }), |
| 3781 | .yes => argv.appendSliceAssumeCapacity(&[_][]const u8{ "-E", "-o", out_obj_path }), |
| 3782 | .stdout => argv.appendAssumeCapacity("-E"), |
| 3783 | } |
| 3784 | |
| 3785 | if (comp.emit_asm != null) { |
| 3786 | argv.appendAssumeCapacity("-S"); |
| 3787 | } else if (comp.emit_llvm_ir != null) { |
| 3788 | argv.appendSliceAssumeCapacity(&[_][]const u8{ "-emit-llvm", "-S" }); |
| 3789 | } else if (comp.emit_llvm_bc != null) { |
| 3790 | argv.appendAssumeCapacity("-emit-llvm"); |
| 3791 | } |
| 3792 | |
| 3793 | if (comp.verbose_cc) { |
| 3794 | dump_argv(argv.items); |
| 3795 | } |
| 3796 | |
| 3797 | const err = std.process.execv(arena, argv.items); |
| 3798 | fatal("unable to execv clang: {s}", .{@errorName(err)}); |
| 3799 | } |
| 3800 | |
| 3756 | 3801 | // We can't know the digest until we do the C compiler invocation, |
| 3757 | 3802 | // so we need a temporary filename. |
| 3758 | 3803 | const out_obj_path = try comp.tmpFilePath(arena, o_basename); |
| 3759 | 3804 | var zig_cache_tmp_dir = try comp.local_cache_directory.handle.makeOpenPath("tmp", .{}); |
| 3760 | 3805 | defer zig_cache_tmp_dir.close(); |
| 3761 | 3806 | |
| 3762 | | try argv.appendSlice(&[_][]const u8{ self_exe_path, "clang" }); |
| 3763 | | |
| 3764 | | const ext = classifyFileExt(c_object.src.src_path); |
| 3765 | 3807 | const out_dep_path: ?[]const u8 = if (comp.disable_c_depfile or !ext.clangSupportsDepFile()) |
| 3766 | 3808 | null |
| 3767 | 3809 | else |
| 3768 | 3810 | try std.fmt.allocPrint(arena, "{s}.d", .{out_obj_path}); |
| 3769 | 3811 | try comp.addCCArgs(arena, &argv, ext, out_dep_path); |
| 3770 | 3812 | |
| 3771 | | try argv.ensureUnusedCapacity(6 + c_object.src.extra_flags.len); |
| 3813 | try argv.ensureUnusedCapacity(5); |
| 3772 | 3814 | switch (comp.clang_preprocessor_mode) { |
| 3773 | 3815 | .no => argv.appendSliceAssumeCapacity(&[_][]const u8{ "-c", "-o", out_obj_path }), |
| 3774 | 3816 | .yes => argv.appendSliceAssumeCapacity(&[_][]const u8{ "-E", "-o", out_obj_path }), |
| ... | ... | @@ -3783,8 +3825,6 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P |
| 3783 | 3825 | argv.appendAssumeCapacity("-emit-llvm"); |
| 3784 | 3826 | } |
| 3785 | 3827 | } |
| 3786 | | argv.appendAssumeCapacity(c_object.src.src_path); |
| 3787 | | argv.appendSliceAssumeCapacity(c_object.src.extra_flags); |
| 3788 | 3828 | |
| 3789 | 3829 | if (comp.verbose_cc) { |
| 3790 | 3830 | dump_argv(argv.items); |