authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-02 15:47:27-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-02 15:47:27-04:00
loge4edc6d118e0e0cd3510bbe89ca4a292436bb82f
treef2a90113d86d8157582e57a616b1bcfe2fedcb99
parent4aa797b6bb3716759738e057e90ac607e81ce6e5
signaturelock-open Commit is signed but in an unrecognized format.

zig cc: respect -MF -MV -MD options

Zig disables its caching and forwards these args when any are provided. see #4784

7 files changed, 68 insertions(+), 21 deletions(-)

src-self-hosted/clang_options_data.zig+25-4
......@@ -26,12 +26,26 @@ flagpd1("H"),
2626},
2727flagpd1("I-"),
2828flagpd1("M"),
29flagpd1("MD"),
29.{
30 .name = "MD",
31 .syntax = .flag,
32 .zig_equivalent = .dep_file,
33 .pd1 = true,
34 .pd2 = false,
35 .psl = false,
36},
3037flagpd1("MG"),
3138flagpd1("MM"),
3239flagpd1("MMD"),
3340flagpd1("MP"),
34flagpd1("MV"),
41.{
42 .name = "MV",
43 .syntax = .flag,
44 .zig_equivalent = .dep_file,
45 .pd1 = true,
46 .pd2 = false,
47 .psl = false,
48},
3549flagpd1("Mach"),
3650flagpd1("O0"),
3751flagpd1("O4"),
......@@ -490,7 +504,7 @@ sepd1("Zlinker-input"),
490504.{
491505 .name = "MD",
492506 .syntax = .flag,
493 .zig_equivalent = .other,
507 .zig_equivalent = .dep_file,
494508 .pd1 = true,
495509 .pd2 = false,
496510 .psl = true,
......@@ -5434,7 +5448,14 @@ joinpd1("mtp="),
54345448joinpd1("gz="),
54355449joinpd1("A-"),
54365450joinpd1("G="),
5437jspd1("MF"),
5451.{
5452 .name = "MF",
5453 .syntax = .joined_or_separate,
5454 .zig_equivalent = .dep_file,
5455 .pd1 = true,
5456 .pd2 = false,
5457 .psl = false,
5458},
54385459jspd1("MJ"),
54395460jspd1("MQ"),
54405461jspd1("MT"),
src-self-hosted/stage2.zig+1
......@@ -1290,6 +1290,7 @@ pub const ClangArgIterator = extern struct {
12901290 linker_input_z,
12911291 lib_dir,
12921292 mcpu,
1293 dep_file,
12931294 };
12941295
12951296 const Args = struct {
src/all_types.hpp+2-1
......@@ -2230,6 +2230,7 @@ struct CodeGen {
22302230 bool reported_bad_link_libc_error;
22312231 bool is_dynamic; // shared library rather than static library. dynamic musl rather than static musl.
22322232 bool need_frame_size_prefix_data;
2233 bool disable_c_depfile;
22332234
22342235 //////////////////////////// Participates in Input Parameter Cache Hash
22352236 /////// Note: there is a separate cache hash for builtin.zig, when adding fields,
......@@ -2258,6 +2259,7 @@ struct CodeGen {
22582259 const ZigTarget *zig_target;
22592260 TargetSubsystem subsystem; // careful using this directly; see detect_subsystem
22602261 ValgrindSupport valgrind_support;
2262 CodeModel code_model;
22612263 bool strip_debug_symbols;
22622264 bool is_test_build;
22632265 bool is_single_threaded;
......@@ -2278,7 +2280,6 @@ struct CodeGen {
22782280 bool emit_asm;
22792281 bool emit_llvm_ir;
22802282 bool test_is_evented;
2281 CodeModel code_model;
22822283
22832284 Buf *root_out_name;
22842285 Buf *test_filter;
src/codegen.cpp+19-16
......@@ -9803,7 +9803,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
98039803 exit(1);
98049804 }
98059805 }
9806 bool is_cache_miss = (buf_len(&digest) == 0);
9806 bool is_cache_miss = g->disable_c_depfile || (buf_len(&digest) == 0);
98079807 if (is_cache_miss) {
98089808 // we can't know the digest until we do the C compiler invocation, so we
98099809 // need a tmp filename.
......@@ -9822,9 +9822,10 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
98229822 args.append("-c");
98239823 }
98249824
9825 Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path));
9825 Buf *out_dep_path = g->disable_c_depfile ? nullptr : buf_sprintf("%s.d", buf_ptr(out_obj_path));
9826 const char *out_dep_path_cstr = (out_dep_path == nullptr) ? nullptr : buf_ptr(out_dep_path);
98269827 FileExt ext = classify_file_ext(buf_ptr(c_source_basename), buf_len(c_source_basename));
9827 add_cc_args(g, args, buf_ptr(out_dep_path), false, ext);
9828 add_cc_args(g, args, out_dep_path_cstr, false, ext);
98289829
98299830 args.append("-o");
98309831 args.append(buf_ptr(out_obj_path));
......@@ -9845,22 +9846,24 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
98459846 exit(1);
98469847 }
98479848
9848 // add the files depended on to the cache system
9849 if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) {
9850 // Don't treat the absence of the .d file as a fatal error, the
9851 // compiler may not produce one eg. when compiling .s files
9849 if (out_dep_path != nullptr) {
9850 // add the files depended on to the cache system
9851 if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) {
9852 // Don't treat the absence of the .d file as a fatal error, the
9853 // compiler may not produce one eg. when compiling .s files
9854 if (err != ErrorFileNotFound) {
9855 fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err));
9856 exit(1);
9857 }
9858 }
98529859 if (err != ErrorFileNotFound) {
9853 fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err));
9854 exit(1);
9860 os_delete_file(out_dep_path);
98559861 }
9856 }
9857 if (err != ErrorFileNotFound) {
9858 os_delete_file(out_dep_path);
9859 }
98609862
9861 if ((err = cache_final(cache_hash, &digest))) {
9862 fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
9863 exit(1);
9863 if ((err = cache_final(cache_hash, &digest))) {
9864 fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
9865 exit(1);
9866 }
98649867 }
98659868 artifact_dir = buf_alloc();
98669869 os_path_join(o_dir, &digest, artifact_dir);
src/main.cpp+8
......@@ -458,6 +458,7 @@ static int main0(int argc, char **argv) {
458458 bool only_pp_or_asm = false;
459459 bool ensure_libc_on_non_freestanding = false;
460460 bool ensure_libcpp_on_non_freestanding = false;
461 bool disable_c_depfile = false;
461462
462463 ZigList<const char *> llvm_argv = {0};
463464 llvm_argv.append("zig (LLVM option parsing)");
......@@ -741,6 +742,12 @@ static int main0(int argc, char **argv) {
741742 case Stage2ClangArgMCpu:
742743 mcpu = it.only_arg;
743744 break;
745 case Stage2ClangArgDepFile:
746 disable_c_depfile = true;
747 for (size_t i = 0; i < it.other_args_len; i += 1) {
748 clang_argv.append(it.other_args_ptr[i]);
749 }
750 break;
744751 }
745752 }
746753 // Parse linker args
......@@ -1520,6 +1527,7 @@ static int main0(int argc, char **argv) {
15201527 g->system_linker_hack = system_linker_hack;
15211528 g->function_sections = function_sections;
15221529 g->code_model = code_model;
1530 g->disable_c_depfile = disable_c_depfile;
15231531
15241532 if (override_soname) {
15251533 g->override_soname = buf_create_from_str(override_soname);
src/stage2.h+1
......@@ -349,6 +349,7 @@ enum Stage2ClangArg {
349349 Stage2ClangArgLinkerInputZ,
350350 Stage2ClangArgLibDir,
351351 Stage2ClangArgMCpu,
352 Stage2ClangArgDepFile,
352353};
353354
354355// ABI warning
tools/update_clang_options.zig+12
......@@ -194,6 +194,18 @@ const known_options = [_]KnownOpt{
194194 .name = "mtune",
195195 .ident = "mcpu",
196196 },
197 .{
198 .name = "MD",
199 .ident = "dep_file",
200 },
201 .{
202 .name = "MV",
203 .ident = "dep_file",
204 },
205 .{
206 .name = "MF",
207 .ident = "dep_file",
208 },
197209};
198210
199211const blacklisted_options = [_][]const u8{};