diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-03-13 12:56:58 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-03-13 12:56:58 -0400 |
| commit | 54edbc6815e42457cd28fa9f1b94e732504b3fc9 (patch) | |
| tree | 36c97169bf0cd59326a93b8c3c0d458f94aed8a9 /src/codegen.cpp | |
| parent | 4cb55d3af6a71467b7d4399bedb961c81e9ad3d5 (diff) | |
| parent | d495dcc3c952c99e5358d9610cf09eb856f643b0 (diff) | |
| download | zig-54edbc6815e42457cd28fa9f1b94e732504b3fc9.tar.gz zig-54edbc6815e42457cd28fa9f1b94e732504b3fc9.zip | |
Merge remote-tracking branch 'origin/master' into llvm8
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 63 |
1 files changed, 38 insertions, 25 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index b996c2367a..52ba3bb591 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -7724,8 +7724,11 @@ static Error define_builtin_compile_vars(CodeGen *g) { Buf digest = BUF_INIT; buf_resize(&digest, 0); - if ((err = cache_hit(&cache_hash, &digest))) - return err; + if ((err = cache_hit(&cache_hash, &digest))) { + // Treat an invalid format error as a cache miss. + if (err != ErrorInvalidFormat) + return err; + } // We should always get a cache hit because there are no // files in the input hash. @@ -7890,7 +7893,7 @@ static void init(CodeGen *g) { } static void detect_dynamic_linker(CodeGen *g) { - if (g->dynamic_linker_path != nullptr) + if (g->dynamic_linker_path != nullptr || g->is_static) return; const char *standard_ld_path = target_dynamic_linker(g->zig_target); if (standard_ld_path == nullptr) @@ -7942,22 +7945,22 @@ static void detect_libc(CodeGen *g) { if (g->libc != nullptr || g->libc_link_lib == nullptr) return; - if (g->zig_target->os == OsLinux && target_abi_is_gnu(g->zig_target->abi)) { - // we have glibc headers and can build glibc start files from source - if (g->is_static && g->out_type == OutTypeExe) { - fprintf(stderr, "glibc does not support static linking\n"); - exit(1); - } + if (g->zig_target->os == OsLinux && target_abi_is_gnu(g->zig_target->abi) && + g->is_static && g->out_type == OutTypeExe) + { + fprintf(stderr, "glibc does not support static linking\n"); + exit(1); + } - Buf libc_include_dir = BUF_INIT; - os_path_join(g->zig_lib_dir, buf_create_from_str("libc" OS_SEP "include"), &libc_include_dir); + if (target_can_build_libc(g->zig_target)) { + const char *generic_name = target_libc_generic_name(g->zig_target); Buf *arch_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "%s-%s-%s", buf_ptr(g->zig_lib_dir), target_arch_name(g->zig_target->arch), target_os_name(g->zig_target->os), target_abi_name(g->zig_target->abi)); - Buf *generic_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "generic-glibc", - buf_ptr(g->zig_lib_dir)); + Buf *generic_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "generic-%s", + buf_ptr(g->zig_lib_dir), generic_name); g->libc_include_dir_len = 2; g->libc_include_dir_list = allocate<Buf*>(2); @@ -8011,11 +8014,14 @@ static void detect_libc(CodeGen *g) { } else if ((g->out_type == OutTypeExe || (g->out_type == OutTypeLib && !g->is_static)) && !target_is_darwin(g->zig_target)) { - // Currently darwin is the only platform that we can link libc on when not compiling natively, - // without a cross compiling libc kit. fprintf(stderr, - "Cannot link against libc for non-native OS '%s' without providing a libc installation file.\n" - "See `zig libc --help` for more details.\n", target_os_name(g->zig_target->os)); + "Zig is unable to provide a libc for the chosen target '%s-%s-%s'.\n" + "The target is non-native, so Zig also cannot use the native libc installation.\n" + "Choose a target which has a libc available, or provide a libc installation text file.\n" + "See `zig libc --help` for more details.\n", + target_arch_name(g->zig_target->arch), + target_os_name(g->zig_target->os), + target_abi_name(g->zig_target->abi)); exit(1); } } @@ -8342,12 +8348,14 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) { Buf digest = BUF_INIT; buf_resize(&digest, 0); if ((err = cache_hit(cache_hash, &digest))) { - if (err == ErrorCacheUnavailable) { - // already printed error - } else { - fprintf(stderr, "unable to check cache when compiling C object: %s\n", err_str(err)); + if (err != ErrorInvalidFormat) { + if (err == ErrorCacheUnavailable) { + // already printed error + } else { + fprintf(stderr, "unable to check cache when compiling C object: %s\n", err_str(err)); + } + exit(1); } - exit(1); } bool is_cache_miss = (buf_len(&digest) == 0); if (is_cache_miss) { @@ -8993,7 +9001,10 @@ void codegen_print_timing_report(CodeGen *g, FILE *f) { } void codegen_add_time_event(CodeGen *g, const char *name) { - g->timing_events.append({os_get_time(), name}); + OsTimeStamp timestamp = os_timestamp_monotonic(); + double seconds = (double)timestamp.sec; + seconds += ((double)timestamp.nsec) / 1000000000.0; + g->timing_events.append({seconds, name}); } static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) { @@ -9090,8 +9101,10 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { cache_list_of_file(ch, g->link_objects.items, g->link_objects.length); buf_resize(digest, 0); - if ((err = cache_hit(ch, digest))) - return err; + if ((err = cache_hit(ch, digest))) { + if (err != ErrorInvalidFormat) + return err; + } if (ch->manifest_file_path != nullptr) { g->caches_to_release.append(ch); |
