diff options
| author | Michaƫl Larouche <michael.larouche@gmail.com> | 2020-04-04 18:41:16 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-04-05 11:01:35 -0400 |
| commit | c4a5f519f22511ce90bfe0aca0690b24cc592f88 (patch) | |
| tree | c5b74949cb47f84d3357bbe4088d05f4b07911b2 /src/codegen.cpp | |
| parent | cd20e0cc672249555709e1b58a415ddd50b03ad9 (diff) | |
| download | zig-c4a5f519f22511ce90bfe0aca0690b24cc592f88.tar.gz zig-c4a5f519f22511ce90bfe0aca0690b24cc592f88.zip | |
Do not parse native_libc.txt anymore when linking on native target, always run detection of libc.
Fixes #4772
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 81 |
1 files changed, 5 insertions, 76 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index ed8fcf54d7..84168f509f 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -9057,80 +9057,13 @@ static void detect_libc(CodeGen *g) { if (g->zig_target->is_native_os) { g->libc = heap::c_allocator.create<Stage2LibCInstallation>(); - // search for native_libc.txt in following dirs: - // - LOCAL_CACHE_DIR - // - GLOBAL_CACHE_DIR - // if not found create at: - // - GLOBAL_CACHE_DIR - // be mindful local/global caches may be the same dir - - Buf basename = BUF_INIT; - buf_init_from_str(&basename, "native_libc.txt"); - - Buf local_libc_txt = BUF_INIT; - os_path_join(g->cache_dir, &basename, &local_libc_txt); - - Buf global_libc_txt = BUF_INIT; - os_path_join(get_global_cache_dir(), &basename, &global_libc_txt); - - Buf *pathnames[3] = { nullptr }; - size_t pathnames_idx = 0; - - pathnames[pathnames_idx] = &local_libc_txt; - pathnames_idx += 1; - - if (!buf_eql_buf(pathnames[0], &global_libc_txt)) { - pathnames[pathnames_idx] = &global_libc_txt; - pathnames_idx += 1; - } - - Buf* libc_txt = nullptr; - for (auto name : pathnames) { - if (name == nullptr) - break; - - bool result; - if (os_file_exists(name, &result) != ErrorNone || !result) - continue; - - libc_txt = name; - break; + if ((err = stage2_libc_find_native(g->libc))) { + fprintf(stderr, + "Unable to link against libc: Unable to find libc installation: %s\n" + "See `zig libc --help` for more details.\n", err_str(err)); + exit(1); } - if (libc_txt == nullptr) - libc_txt = &global_libc_txt; - - if ((err = stage2_libc_parse(g->libc, buf_ptr(libc_txt)))) { - if ((err = stage2_libc_find_native(g->libc))) { - fprintf(stderr, - "Unable to link against libc: Unable to find libc installation: %s\n" - "See `zig libc --help` for more details.\n", err_str(err)); - exit(1); - } - Buf libc_txt_dir = BUF_INIT; - os_path_dirname(libc_txt, &libc_txt_dir); - buf_deinit(&libc_txt_dir); - if ((err = os_make_path(&libc_txt_dir))) { - fprintf(stderr, "Unable to create %s directory: %s\n", - buf_ptr(g->cache_dir), err_str(err)); - exit(1); - } - Buf *native_libc_tmp = buf_sprintf("%s.tmp", buf_ptr(libc_txt)); - FILE *file = fopen(buf_ptr(native_libc_tmp), "wb"); - if (file == nullptr) { - fprintf(stderr, "Unable to open %s: %s\n", buf_ptr(native_libc_tmp), strerror(errno)); - exit(1); - } - stage2_libc_render(g->libc, file); - if (fclose(file) != 0) { - fprintf(stderr, "Unable to save %s: %s\n", buf_ptr(native_libc_tmp), strerror(errno)); - exit(1); - } - if ((err = os_rename(native_libc_tmp, libc_txt))) { - fprintf(stderr, "Unable to create %s: %s\n", buf_ptr(libc_txt), err_str(err)); - exit(1); - } - } bool want_sys_dir = !mem_eql_mem(g->libc->include_dir, g->libc->include_dir_len, g->libc->sys_include_dir, g->libc->sys_include_dir_len); size_t want_um_and_shared_dirs = (g->zig_target->os == OsWindows) ? 2 : 0; @@ -9164,10 +9097,6 @@ static void detect_libc(CodeGen *g) { g->libc_include_dir_len += 1; } assert(g->libc_include_dir_len == dir_count); - - buf_deinit(&global_libc_txt); - buf_deinit(&local_libc_txt); - buf_deinit(&basename); } else if ((g->out_type == OutTypeExe || (g->out_type == OutTypeLib && g->is_dynamic)) && !target_os_is_darwin(g->zig_target->os)) { |
