| author | |
| committer | |
| log | 67735c6f1557092efe6e8c1712445c30655fe283 |
| tree | 82eaedf770f3893192bb251bbae0db470762f230 |
| parent | 5ee5933ade09c535bd1806d91cb606f49d07acea |
| signature |
...zig run, zig build, compiler_rt.a, and builtin.a11 files changed, 166 insertions(+), 34 deletions(-)
src/all_types.hpp+1| ... | @@ -1718,6 +1718,7 @@ struct CodeGen { | ... | @@ -1718,6 +1718,7 @@ struct CodeGen { |
| 1718 | bool verbose_cimport; | 1718 | bool verbose_cimport; |
| 1719 | bool error_during_imports; | 1719 | bool error_during_imports; |
| 1720 | bool generate_error_name_table; | 1720 | bool generate_error_name_table; |
| 1721 | bool enable_cache; | ||
| 1721 | 1722 | ||
| 1722 | //////////////////////////// Participates in Input Parameter Cache Hash | 1723 | //////////////////////////// Participates in Input Parameter Cache Hash |
| 1723 | ZigList<LinkLib *> link_libs_list; | 1724 | ZigList<LinkLib *> link_libs_list; |
src/analyze.cpp+8| ... | @@ -6367,3 +6367,11 @@ not_integer: | ... | @@ -6367,3 +6367,11 @@ not_integer: |
| 6367 | } | 6367 | } |
| 6368 | return nullptr; | 6368 | return nullptr; |
| 6369 | } | 6369 | } |
| 6370 | |||
| 6371 | Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents) { | ||
| 6372 | if (g->enable_cache) { | ||
| 6373 | return cache_add_file_fetch(&g->cache_hash, resolved_path, contents); | ||
| 6374 | } else { | ||
| 6375 | return os_fetch_file_path(resolved_path, contents, false); | ||
| 6376 | } | ||
| 6377 | } |
src/analyze.hpp+3| ... | @@ -210,4 +210,7 @@ ZigType *get_primitive_type(CodeGen *g, Buf *name); | ... | @@ -210,4 +210,7 @@ ZigType *get_primitive_type(CodeGen *g, Buf *name); |
| 210 | bool calling_convention_allows_zig_types(CallingConvention cc); | 210 | bool calling_convention_allows_zig_types(CallingConvention cc); |
| 211 | const char *calling_convention_name(CallingConvention cc); | 211 | const char *calling_convention_name(CallingConvention cc); |
| 212 | 212 | ||
| 213 | |||
| 214 | Error ATTRIBUTE_MUST_USE file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents); | ||
| 215 | |||
| 213 | #endif | 216 | #endif |
src/cache_hash.cpp+8| ... | @@ -467,3 +467,11 @@ void cache_release(CacheHash *ch) { | ... | @@ -467,3 +467,11 @@ void cache_release(CacheHash *ch) { |
| 467 | assert(ch->manifest_file_path != nullptr); | 467 | assert(ch->manifest_file_path != nullptr); |
| 468 | os_file_close(ch->manifest_file); | 468 | os_file_close(ch->manifest_file); |
| 469 | } | 469 | } |
| 470 | |||
| 471 | Buf *get_random_basename() { | ||
| 472 | Buf *result = buf_alloc(); | ||
| 473 | for (size_t i = 0; i < 16; i += 1) { | ||
| 474 | buf_append_char(result, base64_fs_alphabet[rand() % 64]); | ||
| 475 | } | ||
| 476 | return result; | ||
| 477 | } |
src/cache_hash.hpp+5| ... | @@ -67,4 +67,9 @@ Error ATTRIBUTE_MUST_USE cache_final(CacheHash *ch, Buf *out_b64_digest); | ... | @@ -67,4 +67,9 @@ Error ATTRIBUTE_MUST_USE cache_final(CacheHash *ch, Buf *out_b64_digest); |
| 67 | // Until this function is called, no one will be able to get a lock on your input params. | 67 | // Until this function is called, no one will be able to get a lock on your input params. |
| 68 | void cache_release(CacheHash *ch); | 68 | void cache_release(CacheHash *ch); |
| 69 | 69 | ||
| 70 | |||
| 71 | |||
| 72 | // Completely independent function. Just returns a random filename safe basename. | ||
| 73 | Buf *get_random_basename(); | ||
| 74 | |||
| 70 | #endif | 75 | #endif |
src/codegen.cpp+74-29| ... | @@ -7048,7 +7048,7 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package | ... | @@ -7048,7 +7048,7 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package |
| 7048 | *resolved_path = os_path_resolve(resolve_paths, 1); | 7048 | *resolved_path = os_path_resolve(resolve_paths, 1); |
| 7049 | Buf *import_code = buf_alloc(); | 7049 | Buf *import_code = buf_alloc(); |
| 7050 | Error err; | 7050 | Error err; |
| 7051 | if ((err = cache_add_file_fetch(&g->cache_hash, resolved_path, import_code))) { | 7051 | if ((err = file_fetch(g, resolved_path, import_code))) { |
| 7052 | zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err)); | 7052 | zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err)); |
| 7053 | } | 7053 | } |
| 7054 | 7054 | ||
| ... | @@ -7480,10 +7480,7 @@ static void gen_h_file(CodeGen *g) { | ... | @@ -7480,10 +7480,7 @@ static void gen_h_file(CodeGen *g) { |
| 7480 | GenH *gen_h = &gen_h_data; | 7480 | GenH *gen_h = &gen_h_data; |
| 7481 | 7481 | ||
| 7482 | assert(!g->is_test_build); | 7482 | assert(!g->is_test_build); |
| 7483 | 7483 | assert(g->out_h_path != nullptr); | |
| 7484 | if (!g->out_h_path) { | ||
| 7485 | g->out_h_path = buf_sprintf("%s.h", buf_ptr(g->root_out_name)); | ||
| 7486 | } | ||
| 7487 | 7484 | ||
| 7488 | FILE *out_h = fopen(buf_ptr(g->out_h_path), "wb"); | 7485 | FILE *out_h = fopen(buf_ptr(g->out_h_path), "wb"); |
| 7489 | if (!out_h) | 7486 | if (!out_h) |
| ... | @@ -7790,17 +7787,56 @@ static void resolve_out_paths(CodeGen *g) { | ... | @@ -7790,17 +7787,56 @@ static void resolve_out_paths(CodeGen *g) { |
| 7790 | zig_unreachable(); | 7787 | zig_unreachable(); |
| 7791 | } | 7788 | } |
| 7792 | 7789 | ||
| 7793 | os_path_join(&g->artifact_dir, o_basename, &g->o_file_output_path); | 7790 | if (g->enable_cache || g->out_type != OutTypeObj) { |
| 7791 | os_path_join(&g->artifact_dir, o_basename, &g->o_file_output_path); | ||
| 7792 | } else { | ||
| 7793 | buf_init_from_buf(&g->o_file_output_path, o_basename); | ||
| 7794 | } | ||
| 7794 | 7795 | ||
| 7795 | if (g->out_type == OutTypeObj) { | 7796 | if (g->out_type == OutTypeObj) { |
| 7796 | buf_init_from_buf(&g->output_file_path, &g->o_file_output_path); | 7797 | buf_init_from_buf(&g->output_file_path, &g->o_file_output_path); |
| 7797 | } else if (g->out_type == OutTypeExe) { | 7798 | } else if (g->out_type == OutTypeExe) { |
| 7798 | assert(g->root_out_name); | 7799 | if (!g->enable_cache && g->wanted_output_file_path != nullptr) { |
| 7800 | buf_init_from_buf(&g->output_file_path, g->wanted_output_file_path); | ||
| 7801 | } else { | ||
| 7802 | assert(g->root_out_name); | ||
| 7799 | 7803 | ||
| 7800 | Buf basename = BUF_INIT; | 7804 | Buf basename = BUF_INIT; |
| 7801 | buf_init_from_buf(&basename, g->root_out_name); | 7805 | buf_init_from_buf(&basename, g->root_out_name); |
| 7802 | buf_append_str(&basename, target_exe_file_ext(&g->zig_target)); | 7806 | buf_append_str(&basename, target_exe_file_ext(&g->zig_target)); |
| 7803 | os_path_join(&g->artifact_dir, &basename, &g->output_file_path); | 7807 | if (g->enable_cache) { |
| 7808 | os_path_join(&g->artifact_dir, &basename, &g->output_file_path); | ||
| 7809 | } else { | ||
| 7810 | buf_init_from_buf(&g->output_file_path, &basename); | ||
| 7811 | } | ||
| 7812 | } | ||
| 7813 | } else if (g->out_type == OutTypeLib) { | ||
| 7814 | if (!g->enable_cache && g->wanted_output_file_path != nullptr) { | ||
| 7815 | buf_init_from_buf(&g->output_file_path, g->wanted_output_file_path); | ||
| 7816 | } else { | ||
| 7817 | Buf basename = BUF_INIT; | ||
| 7818 | buf_init_from_buf(&basename, g->root_out_name); | ||
| 7819 | buf_append_str(&basename, target_lib_file_ext(&g->zig_target, g->is_static, | ||
| 7820 | g->version_major, g->version_minor, g->version_patch)); | ||
| 7821 | if (g->enable_cache) { | ||
| 7822 | os_path_join(&g->artifact_dir, &basename, &g->output_file_path); | ||
| 7823 | } else { | ||
| 7824 | buf_init_from_buf(&g->output_file_path, &basename); | ||
| 7825 | } | ||
| 7826 | } | ||
| 7827 | } else { | ||
| 7828 | zig_unreachable(); | ||
| 7829 | } | ||
| 7830 | |||
| 7831 | if (g->want_h_file && !g->out_h_path) { | ||
| 7832 | assert(g->root_out_name); | ||
| 7833 | Buf *h_basename = buf_sprintf("%s.h", buf_ptr(g->root_out_name)); | ||
| 7834 | if (g->enable_cache) { | ||
| 7835 | g->out_h_path = buf_alloc(); | ||
| 7836 | os_path_join(&g->artifact_dir, h_basename, g->out_h_path); | ||
| 7837 | } else { | ||
| 7838 | g->out_h_path = h_basename; | ||
| 7839 | } | ||
| 7804 | } | 7840 | } |
| 7805 | } | 7841 | } |
| 7806 | 7842 | ||
| ... | @@ -7809,23 +7845,26 @@ void codegen_build_and_link(CodeGen *g) { | ... | @@ -7809,23 +7845,26 @@ void codegen_build_and_link(CodeGen *g) { |
| 7809 | Error err; | 7845 | Error err; |
| 7810 | assert(g->out_type != OutTypeUnknown); | 7846 | assert(g->out_type != OutTypeUnknown); |
| 7811 | 7847 | ||
| 7812 | codegen_add_time_event(g, "Check Cache"); | ||
| 7813 | |||
| 7814 | Buf *stage1_dir = get_stage1_cache_path(); | 7848 | Buf *stage1_dir = get_stage1_cache_path(); |
| 7849 | Buf *artifact_dir = buf_alloc(); | ||
| 7850 | Buf digest = BUF_INIT; | ||
| 7851 | if (g->enable_cache) { | ||
| 7852 | codegen_add_time_event(g, "Check Cache"); | ||
| 7815 | 7853 | ||
| 7816 | Buf *manifest_dir = buf_alloc(); | 7854 | Buf *manifest_dir = buf_alloc(); |
| 7817 | os_path_join(stage1_dir, buf_create_from_str("build"), manifest_dir); | 7855 | os_path_join(stage1_dir, buf_create_from_str("build"), manifest_dir); |
| 7818 | 7856 | ||
| 7819 | Buf digest = BUF_INIT; | 7857 | if ((err = check_cache(g, manifest_dir, &digest))) { |
| 7820 | if ((err = check_cache(g, manifest_dir, &digest))) { | 7858 | fprintf(stderr, "Unable to check cache: %s\n", err_str(err)); |
| 7821 | fprintf(stderr, "Unable to check cache: %s\n", err_str(err)); | 7859 | exit(1); |
| 7822 | exit(1); | 7860 | } |
| 7823 | } | ||
| 7824 | 7861 | ||
| 7825 | Buf *artifact_dir = buf_alloc(); | 7862 | os_path_join(stage1_dir, buf_create_from_str("artifact"), artifact_dir); |
| 7826 | os_path_join(stage1_dir, buf_create_from_str("artifact"), artifact_dir); | 7863 | } else { |
| 7864 | os_path_join(stage1_dir, buf_create_from_str("tmp"), artifact_dir); | ||
| 7865 | } | ||
| 7827 | 7866 | ||
| 7828 | if (buf_len(&digest) != 0) { | 7867 | if (g->enable_cache && buf_len(&digest) != 0) { |
| 7829 | os_path_join(artifact_dir, &digest, &g->artifact_dir); | 7868 | os_path_join(artifact_dir, &digest, &g->artifact_dir); |
| 7830 | resolve_out_paths(g); | 7869 | resolve_out_paths(g); |
| 7831 | } else { | 7870 | } else { |
| ... | @@ -7836,11 +7875,16 @@ void codegen_build_and_link(CodeGen *g) { | ... | @@ -7836,11 +7875,16 @@ void codegen_build_and_link(CodeGen *g) { |
| 7836 | gen_global_asm(g); | 7875 | gen_global_asm(g); |
| 7837 | gen_root_source(g); | 7876 | gen_root_source(g); |
| 7838 | 7877 | ||
| 7839 | if ((err = cache_final(&g->cache_hash, &digest))) { | 7878 | if (g->enable_cache) { |
| 7840 | fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err)); | 7879 | if ((err = cache_final(&g->cache_hash, &digest))) { |
| 7841 | exit(1); | 7880 | fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err)); |
| 7881 | exit(1); | ||
| 7882 | } | ||
| 7883 | os_path_join(artifact_dir, &digest, &g->artifact_dir); | ||
| 7884 | } else { | ||
| 7885 | Buf *tmp_basename = get_random_basename(); | ||
| 7886 | os_path_join(artifact_dir, tmp_basename, &g->artifact_dir); | ||
| 7842 | } | 7887 | } |
| 7843 | os_path_join(artifact_dir, &digest, &g->artifact_dir); | ||
| 7844 | if ((err = os_make_path(&g->artifact_dir))) { | 7888 | if ((err = os_make_path(&g->artifact_dir))) { |
| 7845 | fprintf(stderr, "Unable to create artifact directory: %s\n", err_str(err)); | 7889 | fprintf(stderr, "Unable to create artifact directory: %s\n", err_str(err)); |
| 7846 | exit(1); | 7890 | exit(1); |
| ... | @@ -7857,9 +7901,10 @@ void codegen_build_and_link(CodeGen *g) { | ... | @@ -7857,9 +7901,10 @@ void codegen_build_and_link(CodeGen *g) { |
| 7857 | codegen_link(g); | 7901 | codegen_link(g); |
| 7858 | } | 7902 | } |
| 7859 | } | 7903 | } |
| 7860 | // TODO hard link output_file_path to wanted_output_file_path | ||
| 7861 | 7904 | ||
| 7862 | cache_release(&g->cache_hash); | 7905 | if (g->enable_cache) { |
| 7906 | cache_release(&g->cache_hash); | ||
| 7907 | } | ||
| 7863 | codegen_add_time_event(g, "Done"); | 7908 | codegen_add_time_event(g, "Done"); |
| 7864 | } | 7909 | } |
| 7865 | 7910 |
src/ir.cpp+2-2| ... | @@ -16277,7 +16277,7 @@ static ZigType *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImpor | ... | @@ -16277,7 +16277,7 @@ static ZigType *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImpor |
| 16277 | return ira->codegen->builtin_types.entry_namespace; | 16277 | return ira->codegen->builtin_types.entry_namespace; |
| 16278 | } | 16278 | } |
| 16279 | 16279 | ||
| 16280 | if ((err = cache_add_file_fetch(&ira->codegen->cache_hash, resolved_path, import_code))) { | 16280 | if ((err = file_fetch(ira->codegen, resolved_path, import_code))) { |
| 16281 | if (err == ErrorFileNotFound) { | 16281 | if (err == ErrorFileNotFound) { |
| 16282 | ir_add_error_node(ira, source_node, | 16282 | ir_add_error_node(ira, source_node, |
| 16283 | buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); | 16283 | buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); |
| ... | @@ -18108,7 +18108,7 @@ static ZigType *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionE | ... | @@ -18108,7 +18108,7 @@ static ZigType *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionE |
| 18108 | // load from file system into const expr | 18108 | // load from file system into const expr |
| 18109 | Buf *file_contents = buf_alloc(); | 18109 | Buf *file_contents = buf_alloc(); |
| 18110 | int err; | 18110 | int err; |
| 18111 | if ((err = cache_add_file_fetch(&ira->codegen->cache_hash, &file_path, file_contents))) { | 18111 | if ((err = file_fetch(ira->codegen, &file_path, file_contents))) { |
| 18112 | if (err == ErrorFileNotFound) { | 18112 | if (err == ErrorFileNotFound) { |
| 18113 | ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(&file_path))); | 18113 | ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(&file_path))); |
| 18114 | return ira->codegen->builtin_types.entry_invalid; | 18114 | return ira->codegen->builtin_types.entry_invalid; |
src/link.cpp+1| ... | @@ -58,6 +58,7 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) | ... | @@ -58,6 +58,7 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) |
| 58 | new_link_lib->provided_explicitly = link_lib->provided_explicitly; | 58 | new_link_lib->provided_explicitly = link_lib->provided_explicitly; |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | child_gen->enable_cache = true; | ||
| 61 | codegen_build_and_link(child_gen); | 62 | codegen_build_and_link(child_gen); |
| 62 | return &child_gen->output_file_path; | 63 | return &child_gen->output_file_path; |
| 63 | } | 64 | } |
src/main.cpp+47-3| ... | @@ -34,6 +34,7 @@ static int usage(const char *arg0) { | ... | @@ -34,6 +34,7 @@ static int usage(const char *arg0) { |
| 34 | "Compile Options:\n" | 34 | "Compile Options:\n" |
| 35 | " --assembly [source] add assembly file to build\n" | 35 | " --assembly [source] add assembly file to build\n" |
| 36 | " --cache-dir [path] override the cache directory\n" | 36 | " --cache-dir [path] override the cache directory\n" |
| 37 | " --cache [auto|off|on] build to the global cache and print output path to stdout\n" | ||
| 37 | " --color [auto|off|on] enable or disable colored error messages\n" | 38 | " --color [auto|off|on] enable or disable colored error messages\n" |
| 38 | " --emit [asm|bin|llvm-ir] emit a specific file format as compilation output\n" | 39 | " --emit [asm|bin|llvm-ir] emit a specific file format as compilation output\n" |
| 39 | " --enable-timing-info print timing diagnostics\n" | 40 | " --enable-timing-info print timing diagnostics\n" |
| ... | @@ -257,6 +258,24 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) { | ... | @@ -257,6 +258,24 @@ static void add_package(CodeGen *g, CliPkg *cli_pkg, PackageTableEntry *pkg) { |
| 257 | } | 258 | } |
| 258 | } | 259 | } |
| 259 | 260 | ||
| 261 | enum CacheOpt { | ||
| 262 | CacheOptAuto, | ||
| 263 | CacheOptOn, | ||
| 264 | CacheOptOff, | ||
| 265 | }; | ||
| 266 | |||
| 267 | static bool get_cache_opt(CacheOpt opt, bool default_value) { | ||
| 268 | switch (opt) { | ||
| 269 | case CacheOptAuto: | ||
| 270 | return default_value; | ||
| 271 | case CacheOptOn: | ||
| 272 | return true; | ||
| 273 | case CacheOptOff: | ||
| 274 | return false; | ||
| 275 | } | ||
| 276 | zig_unreachable(); | ||
| 277 | } | ||
| 278 | |||
| 260 | int main(int argc, char **argv) { | 279 | int main(int argc, char **argv) { |
| 261 | if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) { | 280 | if (argc == 2 && strcmp(argv[1], "BUILD_INFO") == 0) { |
| 262 | printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", | 281 | printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", |
| ... | @@ -301,6 +320,7 @@ int main(int argc, char **argv) { | ... | @@ -301,6 +320,7 @@ int main(int argc, char **argv) { |
| 301 | bool verbose_llvm_ir = false; | 320 | bool verbose_llvm_ir = false; |
| 302 | bool verbose_cimport = false; | 321 | bool verbose_cimport = false; |
| 303 | ErrColor color = ErrColorAuto; | 322 | ErrColor color = ErrColorAuto; |
| 323 | CacheOpt enable_cache = CacheOptAuto; | ||
| 304 | const char *libc_lib_dir = nullptr; | 324 | const char *libc_lib_dir = nullptr; |
| 305 | const char *libc_static_lib_dir = nullptr; | 325 | const char *libc_static_lib_dir = nullptr; |
| 306 | const char *libc_include_dir = nullptr; | 326 | const char *libc_include_dir = nullptr; |
| ... | @@ -465,6 +485,7 @@ int main(int argc, char **argv) { | ... | @@ -465,6 +485,7 @@ int main(int argc, char **argv) { |
| 465 | PackageTableEntry *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname), | 485 | PackageTableEntry *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname), |
| 466 | buf_ptr(&build_file_basename)); | 486 | buf_ptr(&build_file_basename)); |
| 467 | g->root_package->package_table.put(buf_create_from_str("@build"), build_pkg); | 487 | g->root_package->package_table.put(buf_create_from_str("@build"), build_pkg); |
| 488 | g->enable_cache = get_cache_opt(enable_cache, true); | ||
| 468 | codegen_build_and_link(g); | 489 | codegen_build_and_link(g); |
| 469 | 490 | ||
| 470 | Termination term; | 491 | Termination term; |
| ... | @@ -562,6 +583,17 @@ int main(int argc, char **argv) { | ... | @@ -562,6 +583,17 @@ int main(int argc, char **argv) { |
| 562 | fprintf(stderr, "--color options are 'auto', 'on', or 'off'\n"); | 583 | fprintf(stderr, "--color options are 'auto', 'on', or 'off'\n"); |
| 563 | return usage(arg0); | 584 | return usage(arg0); |
| 564 | } | 585 | } |
| 586 | } else if (strcmp(arg, "--cache") == 0) { | ||
| 587 | if (strcmp(argv[i], "auto") == 0) { | ||
| 588 | enable_cache = CacheOptAuto; | ||
| 589 | } else if (strcmp(argv[i], "on") == 0) { | ||
| 590 | enable_cache = CacheOptOn; | ||
| 591 | } else if (strcmp(argv[i], "off") == 0) { | ||
| 592 | enable_cache = CacheOptOff; | ||
| 593 | } else { | ||
| 594 | fprintf(stderr, "--cache options are 'auto', 'on', or 'off'\n"); | ||
| 595 | return usage(arg0); | ||
| 596 | } | ||
| 565 | } else if (strcmp(arg, "--emit") == 0) { | 597 | } else if (strcmp(arg, "--emit") == 0) { |
| 566 | if (strcmp(argv[i], "asm") == 0) { | 598 | if (strcmp(argv[i], "asm") == 0) { |
| 567 | emit_file_type = EmitFileTypeAssembly; | 599 | emit_file_type = EmitFileTypeAssembly; |
| ... | @@ -894,6 +926,7 @@ int main(int argc, char **argv) { | ... | @@ -894,6 +926,7 @@ int main(int argc, char **argv) { |
| 894 | if (cmd == CmdBuild || cmd == CmdRun) { | 926 | if (cmd == CmdBuild || cmd == CmdRun) { |
| 895 | codegen_set_emit_file_type(g, emit_file_type); | 927 | codegen_set_emit_file_type(g, emit_file_type); |
| 896 | 928 | ||
| 929 | g->enable_cache = get_cache_opt(enable_cache, cmd == CmdRun); | ||
| 897 | codegen_build_and_link(g); | 930 | codegen_build_and_link(g); |
| 898 | if (timing_info) | 931 | if (timing_info) |
| 899 | codegen_print_timing_report(g, stdout); | 932 | codegen_print_timing_report(g, stdout); |
| ... | @@ -913,9 +946,17 @@ int main(int argc, char **argv) { | ... | @@ -913,9 +946,17 @@ int main(int argc, char **argv) { |
| 913 | Termination term; | 946 | Termination term; |
| 914 | os_spawn_process(exec_path, args, &term); | 947 | os_spawn_process(exec_path, args, &term); |
| 915 | return term.code; | 948 | return term.code; |
| 949 | } else if (cmd == CmdBuild) { | ||
| 950 | if (g->enable_cache) { | ||
| 951 | printf("%s\n", buf_ptr(&g->output_file_path)); | ||
| 952 | if (g->out_h_path != nullptr) { | ||
| 953 | printf("%s\n", buf_ptr(g->out_h_path)); | ||
| 954 | } | ||
| 955 | } | ||
| 956 | return EXIT_SUCCESS; | ||
| 957 | } else { | ||
| 958 | zig_unreachable(); | ||
| 916 | } | 959 | } |
| 917 | |||
| 918 | return EXIT_SUCCESS; | ||
| 919 | } else if (cmd == CmdTranslateC) { | 960 | } else if (cmd == CmdTranslateC) { |
| 920 | codegen_translate_c(g, in_file_buf); | 961 | codegen_translate_c(g, in_file_buf); |
| 921 | ast_render(g, stdout, g->root_import->root, 4); | 962 | ast_render(g, stdout, g->root_import->root, 4); |
| ... | @@ -928,8 +969,11 @@ int main(int argc, char **argv) { | ... | @@ -928,8 +969,11 @@ int main(int argc, char **argv) { |
| 928 | ZigTarget native; | 969 | ZigTarget native; |
| 929 | get_native_target(&native); | 970 | get_native_target(&native); |
| 930 | 971 | ||
| 972 | g->enable_cache = get_cache_opt(enable_cache, false); | ||
| 931 | codegen_build_and_link(g); | 973 | codegen_build_and_link(g); |
| 932 | Buf *test_exe_path = &g->output_file_path; | 974 | Buf *test_exe_path_unresolved = &g->output_file_path; |
| 975 | Buf *test_exe_path = buf_alloc(); | ||
| 976 | *test_exe_path = os_path_resolve(&test_exe_path_unresolved, 1); | ||
| 933 | 977 | ||
| 934 | for (size_t i = 0; i < test_exec_args.length; i += 1) { | 978 | for (size_t i = 0; i < test_exec_args.length; i += 1) { |
| 935 | if (test_exec_args.items[i] == nullptr) { | 979 | if (test_exec_args.items[i] == nullptr) { |
src/target.cpp+16| ... | @@ -813,6 +813,22 @@ const char *target_exe_file_ext(ZigTarget *target) { | ... | @@ -813,6 +813,22 @@ const char *target_exe_file_ext(ZigTarget *target) { |
| 813 | } | 813 | } |
| 814 | } | 814 | } |
| 815 | 815 | ||
| 816 | const char *target_lib_file_ext(ZigTarget *target, bool is_static, size_t version_major, size_t version_minor, size_t version_patch) { | ||
| 817 | if (target->os == OsWindows) { | ||
| 818 | if (is_static) { | ||
| 819 | return ".lib"; | ||
| 820 | } else { | ||
| 821 | return ".dll"; | ||
| 822 | } | ||
| 823 | } else { | ||
| 824 | if (is_static) { | ||
| 825 | return ".a"; | ||
| 826 | } else { | ||
| 827 | return buf_ptr(buf_sprintf(".so.%zu", version_major)); | ||
| 828 | } | ||
| 829 | } | ||
| 830 | } | ||
| 831 | |||
| 816 | enum FloatAbi { | 832 | enum FloatAbi { |
| 817 | FloatAbiHard, | 833 | FloatAbiHard, |
| 818 | FloatAbiSoft, | 834 | FloatAbiSoft, |
src/target.hpp+1| ... | @@ -113,6 +113,7 @@ const char *target_o_file_ext(ZigTarget *target); | ... | @@ -113,6 +113,7 @@ const char *target_o_file_ext(ZigTarget *target); |
| 113 | const char *target_asm_file_ext(ZigTarget *target); | 113 | const char *target_asm_file_ext(ZigTarget *target); |
| 114 | const char *target_llvm_ir_file_ext(ZigTarget *target); | 114 | const char *target_llvm_ir_file_ext(ZigTarget *target); |
| 115 | const char *target_exe_file_ext(ZigTarget *target); | 115 | const char *target_exe_file_ext(ZigTarget *target); |
| 116 | const char *target_lib_file_ext(ZigTarget *target, bool is_static, size_t version_major, size_t version_minor, size_t version_patch); | ||
| 116 | 117 | ||
| 117 | Buf *target_dynamic_linker(ZigTarget *target); | 118 | Buf *target_dynamic_linker(ZigTarget *target); |
| 118 | 119 |