| ... | @@ -9057,80 +9057,13 @@ static void detect_libc(CodeGen *g) { | ... | @@ -9057,80 +9057,13 @@ static void detect_libc(CodeGen *g) { |
| 9057 | if (g->zig_target->is_native_os) { | 9057 | if (g->zig_target->is_native_os) { |
| 9058 | g->libc = heap::c_allocator.create<Stage2LibCInstallation>(); | 9058 | g->libc = heap::c_allocator.create<Stage2LibCInstallation>(); |
| 9059 | | 9059 | |
| 9060 | // search for native_libc.txt in following dirs: | 9060 | if ((err = stage2_libc_find_native(g->libc))) { |
| 9061 | // - LOCAL_CACHE_DIR | 9061 | fprintf(stderr, |
| 9062 | // - GLOBAL_CACHE_DIR | 9062 | "Unable to link against libc: Unable to find libc installation: %s\n" |
| 9063 | // if not found create at: | 9063 | "See `zig libc --help` for more details.\n", err_str(err)); |
| 9064 | // - GLOBAL_CACHE_DIR | 9064 | exit(1); |
| 9065 | // be mindful local/global caches may be the same dir | | |
| 9066 | | | |
| 9067 | Buf basename = BUF_INIT; | | |
| 9068 | buf_init_from_str(&basename, "native_libc.txt"); | | |
| 9069 | | | |
| 9070 | Buf local_libc_txt = BUF_INIT; | | |
| 9071 | os_path_join(g->cache_dir, &basename, &local_libc_txt); | | |
| 9072 | | | |
| 9073 | Buf global_libc_txt = BUF_INIT; | | |
| 9074 | os_path_join(get_global_cache_dir(), &basename, &global_libc_txt); | | |
| 9075 | | | |
| 9076 | Buf *pathnames[3] = { nullptr }; | | |
| 9077 | size_t pathnames_idx = 0; | | |
| 9078 | | | |
| 9079 | pathnames[pathnames_idx] = &local_libc_txt; | | |
| 9080 | pathnames_idx += 1; | | |
| 9081 | | | |
| 9082 | if (!buf_eql_buf(pathnames[0], &global_libc_txt)) { | | |
| 9083 | pathnames[pathnames_idx] = &global_libc_txt; | | |
| 9084 | pathnames_idx += 1; | | |
| 9085 | } | | |
| 9086 | | | |
| 9087 | Buf* libc_txt = nullptr; | | |
| 9088 | for (auto name : pathnames) { | | |
| 9089 | if (name == nullptr) | | |
| 9090 | break; | | |
| 9091 | | | |
| 9092 | bool result; | | |
| 9093 | if (os_file_exists(name, &result) != ErrorNone || !result) | | |
| 9094 | continue; | | |
| 9095 | | | |
| 9096 | libc_txt = name; | | |
| 9097 | break; | | |
| 9098 | } | 9065 | } |
| 9099 | | 9066 | |
| 9100 | if (libc_txt == nullptr) | | |
| 9101 | libc_txt = &global_libc_txt; | | |
| 9102 | | | |
| 9103 | if ((err = stage2_libc_parse(g->libc, buf_ptr(libc_txt)))) { | | |
| 9104 | if ((err = stage2_libc_find_native(g->libc))) { | | |
| 9105 | fprintf(stderr, | | |
| 9106 | "Unable to link against libc: Unable to find libc installation: %s\n" | | |
| 9107 | "See `zig libc --help` for more details.\n", err_str(err)); | | |
| 9108 | exit(1); | | |
| 9109 | } | | |
| 9110 | Buf libc_txt_dir = BUF_INIT; | | |
| 9111 | os_path_dirname(libc_txt, &libc_txt_dir); | | |
| 9112 | buf_deinit(&libc_txt_dir); | | |
| 9113 | if ((err = os_make_path(&libc_txt_dir))) { | | |
| 9114 | fprintf(stderr, "Unable to create %s directory: %s\n", | | |
| 9115 | buf_ptr(g->cache_dir), err_str(err)); | | |
| 9116 | exit(1); | | |
| 9117 | } | | |
| 9118 | Buf *native_libc_tmp = buf_sprintf("%s.tmp", buf_ptr(libc_txt)); | | |
| 9119 | FILE *file = fopen(buf_ptr(native_libc_tmp), "wb"); | | |
| 9120 | if (file == nullptr) { | | |
| 9121 | fprintf(stderr, "Unable to open %s: %s\n", buf_ptr(native_libc_tmp), strerror(errno)); | | |
| 9122 | exit(1); | | |
| 9123 | } | | |
| 9124 | stage2_libc_render(g->libc, file); | | |
| 9125 | if (fclose(file) != 0) { | | |
| 9126 | fprintf(stderr, "Unable to save %s: %s\n", buf_ptr(native_libc_tmp), strerror(errno)); | | |
| 9127 | exit(1); | | |
| 9128 | } | | |
| 9129 | if ((err = os_rename(native_libc_tmp, libc_txt))) { | | |
| 9130 | fprintf(stderr, "Unable to create %s: %s\n", buf_ptr(libc_txt), err_str(err)); | | |
| 9131 | exit(1); | | |
| 9132 | } | | |
| 9133 | } | | |
| 9134 | bool want_sys_dir = !mem_eql_mem(g->libc->include_dir, g->libc->include_dir_len, | 9067 | bool want_sys_dir = !mem_eql_mem(g->libc->include_dir, g->libc->include_dir_len, |
| 9135 | g->libc->sys_include_dir, g->libc->sys_include_dir_len); | 9068 | g->libc->sys_include_dir, g->libc->sys_include_dir_len); |
| 9136 | size_t want_um_and_shared_dirs = (g->zig_target->os == OsWindows) ? 2 : 0; | 9069 | size_t want_um_and_shared_dirs = (g->zig_target->os == OsWindows) ? 2 : 0; |
| ... | @@ -9164,10 +9097,6 @@ static void detect_libc(CodeGen *g) { | ... | @@ -9164,10 +9097,6 @@ static void detect_libc(CodeGen *g) { |
| 9164 | g->libc_include_dir_len += 1; | 9097 | g->libc_include_dir_len += 1; |
| 9165 | } | 9098 | } |
| 9166 | assert(g->libc_include_dir_len == dir_count); | 9099 | assert(g->libc_include_dir_len == dir_count); |
| 9167 | | | |
| 9168 | buf_deinit(&global_libc_txt); | | |
| 9169 | buf_deinit(&local_libc_txt); | | |
| 9170 | buf_deinit(&basename); | | |
| 9171 | } else if ((g->out_type == OutTypeExe || (g->out_type == OutTypeLib && g->is_dynamic)) && | 9100 | } else if ((g->out_type == OutTypeExe || (g->out_type == OutTypeLib && g->is_dynamic)) && |
| 9172 | !target_os_is_darwin(g->zig_target->os)) | 9101 | !target_os_is_darwin(g->zig_target->os)) |
| 9173 | { | 9102 | { |