| author | |
| committer | |
| log | dfada0cc77cb77a337baa784e4e96c7a94d217bb |
| tree | 95285d61908a6cadd5a5fbea4e969ddb6ddafa17 |
| parent | f4c5fa7ff46ad088e437dba237518df76736f087 |
3 files changed, 56 insertions(+), 56 deletions(-)
src/libc_installation.cpp+30-6| ... | ... | @@ -14,6 +14,7 @@ static const char *zig_libc_keys[] = { |
| 14 | 14 | "include_dir", |
| 15 | 15 | "sys_include_dir", |
| 16 | 16 | "crt_dir", |
| 17 | "static_crt_dir", | |
| 17 | 18 | "msvc_lib_dir", |
| 18 | 19 | "kernel32_lib_dir", |
| 19 | 20 | }; |
| ... | ... | @@ -34,6 +35,7 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) { |
| 34 | 35 | buf_init_from_str(&libc->include_dir, ""); |
| 35 | 36 | buf_init_from_str(&libc->sys_include_dir, ""); |
| 36 | 37 | buf_init_from_str(&libc->crt_dir, ""); |
| 38 | buf_init_from_str(&libc->static_crt_dir, ""); | |
| 37 | 39 | buf_init_from_str(&libc->msvc_lib_dir, ""); |
| 38 | 40 | buf_init_from_str(&libc->kernel32_lib_dir, ""); |
| 39 | 41 | } |
| ... | ... | @@ -74,8 +76,9 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget |
| 74 | 76 | match = match || zig_libc_match_key(name, value, found_keys, 0, &libc->include_dir); |
| 75 | 77 | match = match || zig_libc_match_key(name, value, found_keys, 1, &libc->sys_include_dir); |
| 76 | 78 | match = match || zig_libc_match_key(name, value, found_keys, 2, &libc->crt_dir); |
| 77 | match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->msvc_lib_dir); | |
| 78 | match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->kernel32_lib_dir); | |
| 79 | match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->static_crt_dir); | |
| 80 | match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->msvc_lib_dir); | |
| 81 | match = match || zig_libc_match_key(name, value, found_keys, 5, &libc->kernel32_lib_dir); | |
| 79 | 82 | } |
| 80 | 83 | |
| 81 | 84 | for (size_t i = 0; i < zig_libc_keys_len; i += 1) { |
| ... | ... | @@ -110,6 +113,15 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget |
| 110 | 113 | } |
| 111 | 114 | } |
| 112 | 115 | |
| 116 | if (buf_len(&libc->static_crt_dir) == 0) { | |
| 117 | if (target->os == OsWindows && target_abi_is_gnu(target->abi)) { | |
| 118 | if (verbose) { | |
| 119 | fprintf(stderr, "static_crt_dir may not be empty for %s\n", target_os_name(target->os)); | |
| 120 | } | |
| 121 | return ErrorSemanticAnalyzeFail; | |
| 122 | } | |
| 123 | } | |
| 124 | ||
| 113 | 125 | if (buf_len(&libc->msvc_lib_dir) == 0) { |
| 114 | 126 | if (target->os == OsWindows && !target_abi_is_gnu(target->abi)) { |
| 115 | 127 | if (verbose) { |
| ... | ... | @@ -261,7 +273,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b |
| 261 | 273 | return ErrorFileNotFound; |
| 262 | 274 | } |
| 263 | 275 | |
| 264 | Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirname, bool verbose) { | |
| 276 | static Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirname, bool verbose) { | |
| 265 | 277 | const char *cc_exe = getenv("CC"); |
| 266 | 278 | cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe; |
| 267 | 279 | ZigList<const char *> args = {}; |
| ... | ... | @@ -308,6 +320,10 @@ static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool |
| 308 | 320 | return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose); |
| 309 | 321 | } |
| 310 | 322 | |
| 323 | static Error zig_libc_find_native_static_crt_dir_posix(ZigLibCInstallation *self, bool verbose) { | |
| 324 | return zig_libc_cc_print_file_name("crtbegin.o", &self->static_crt_dir, true, verbose); | |
| 325 | } | |
| 326 | ||
| 311 | 327 | #if defined(ZIG_OS_WINDOWS) |
| 312 | 328 | static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, bool verbose) { |
| 313 | 329 | Error err; |
| ... | ... | @@ -320,7 +336,7 @@ static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self, |
| 320 | 336 | return ErrorNone; |
| 321 | 337 | } |
| 322 | 338 | |
| 323 | static Error zig_libc_find_crt_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, ZigTarget *target, | |
| 339 | static Error zig_libc_find_native_crt_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, ZigTarget *target, | |
| 324 | 340 | bool verbose) |
| 325 | 341 | { |
| 326 | 342 | Error err; |
| ... | ... | @@ -396,11 +412,16 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) { |
| 396 | 412 | "# On POSIX it's the directory that includes `sys/errno.h`.\n" |
| 397 | 413 | "sys_include_dir=%s\n" |
| 398 | 414 | "\n" |
| 399 | "# The directory that contains `crt1.o`.\n" | |
| 415 | "# The directory that contains `crt1.o` or `crt2.o`.\n" | |
| 400 | 416 | "# On POSIX, can be found with `cc -print-file-name=crt1.o`.\n" |
| 401 | 417 | "# Not needed when targeting MacOS.\n" |
| 402 | 418 | "crt_dir=%s\n" |
| 403 | 419 | "\n" |
| 420 | "# The directory that contains `crtbegin.o`.\n" | |
| 421 | "# On POSIX, can be found with `cc -print-file-name=crtbegin.o`.\n" | |
| 422 | "# Not needed when targeting MacOS.\n" | |
| 423 | "static_crt_dir=%s\n" | |
| 424 | "\n" | |
| 404 | 425 | "# The directory that contains `vcruntime.lib`.\n" |
| 405 | 426 | "# Only needed when targeting MSVC on Windows.\n" |
| 406 | 427 | "msvc_lib_dir=%s\n" |
| ... | ... | @@ -413,6 +434,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) { |
| 413 | 434 | buf_ptr(&self->include_dir), |
| 414 | 435 | buf_ptr(&self->sys_include_dir), |
| 415 | 436 | buf_ptr(&self->crt_dir), |
| 437 | buf_ptr(&self->static_crt_dir), | |
| 416 | 438 | buf_ptr(&self->msvc_lib_dir), |
| 417 | 439 | buf_ptr(&self->kernel32_lib_dir) |
| 418 | 440 | ); |
| ... | ... | @@ -429,6 +451,8 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) { |
| 429 | 451 | return err; |
| 430 | 452 | if ((err = zig_libc_find_native_crt_dir_posix(self, verbose))) |
| 431 | 453 | return err; |
| 454 | if ((err = zig_libc_find_native_static_crt_dir_posix(self, verbose))) | |
| 455 | return err; | |
| 432 | 456 | return ErrorNone; |
| 433 | 457 | } else { |
| 434 | 458 | ZigWindowsSDK *sdk; |
| ... | ... | @@ -442,7 +466,7 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) { |
| 442 | 466 | return err; |
| 443 | 467 | if ((err = zig_libc_find_native_include_dir_windows(self, sdk, verbose))) |
| 444 | 468 | return err; |
| 445 | if ((err = zig_libc_find_crt_dir_windows(self, sdk, &native_target, verbose))) | |
| 469 | if ((err = zig_libc_find_native_crt_dir_windows(self, sdk, &native_target, verbose))) | |
| 446 | 470 | return err; |
| 447 | 471 | return ErrorNone; |
| 448 | 472 | case ZigFindWindowsSdkErrorOutOfMemory: |
src/libc_installation.hpp+1-2| ... | ... | @@ -19,6 +19,7 @@ struct ZigLibCInstallation { |
| 19 | 19 | Buf include_dir; |
| 20 | 20 | Buf sys_include_dir; |
| 21 | 21 | Buf crt_dir; |
| 22 | Buf static_crt_dir; | |
| 22 | 23 | Buf msvc_lib_dir; |
| 23 | 24 | Buf kernel32_lib_dir; |
| 24 | 25 | }; |
| ... | ... | @@ -29,6 +30,4 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file); |
| 29 | 30 | |
| 30 | 31 | Error ATTRIBUTE_MUST_USE zig_libc_find_native(ZigLibCInstallation *self, bool verbose); |
| 31 | 32 | |
| 32 | Error zig_libc_cc_print_file_name(const char *o_file, Buf *out, bool want_dirname, bool verbose); | |
| 33 | ||
| 34 | 33 | #endif |
src/link.cpp+25-48| ... | ... | @@ -1170,12 +1170,8 @@ static const char *get_libc_file(ZigLibCInstallation *lib, const char *file) { |
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | static const char *get_libc_static_file(ZigLibCInstallation *lib, const char *file) { |
| 1173 | Buf *static_crt_dir = buf_alloc(); | |
| 1174 | 1173 | Buf *out_buf = buf_alloc(); |
| 1175 | if (zig_libc_cc_print_file_name(file, static_crt_dir, true, true) != ErrorNone) { | |
| 1176 | abort(); | |
| 1177 | } | |
| 1178 | os_path_join(static_crt_dir, buf_create_from_str(file), out_buf); | |
| 1174 | os_path_join(&lib->static_crt_dir, buf_create_from_str(file), out_buf); | |
| 1179 | 1175 | return buf_ptr(out_buf); |
| 1180 | 1176 | } |
| 1181 | 1177 | |
| ... | ... | @@ -1198,35 +1194,33 @@ static void add_mingw_link_args(LinkJob *lj, bool is_library) { |
| 1198 | 1194 | |
| 1199 | 1195 | lj->args.append(get_libc_static_file(g->libc, "crtbegin.o")); |
| 1200 | 1196 | |
| 1201 | if (g->libc_link_lib != nullptr) { | |
| 1202 | lj->args.append("libmingw32.a"); | |
| 1197 | lj->args.append(get_libc_file(g->libc, "libmingw32.a")); | |
| 1203 | 1198 | |
| 1204 | if (is_dll) { | |
| 1205 | lj->args.append(get_libc_static_file(g->libc, "libgcc_s.a")); | |
| 1206 | lj->args.append(get_libc_static_file(g->libc, "libgcc.a")); | |
| 1207 | } else { | |
| 1208 | lj->args.append(get_libc_static_file(g->libc, "libgcc.a")); | |
| 1209 | lj->args.append(get_libc_static_file(g->libc, "libgcc_eh.a")); | |
| 1210 | } | |
| 1199 | if (is_dll) { | |
| 1200 | lj->args.append(get_libc_static_file(g->libc, "libgcc_s.a")); | |
| 1201 | lj->args.append(get_libc_static_file(g->libc, "libgcc.a")); | |
| 1202 | } else { | |
| 1203 | lj->args.append(get_libc_static_file(g->libc, "libgcc.a")); | |
| 1204 | lj->args.append(get_libc_static_file(g->libc, "libgcc_eh.a")); | |
| 1205 | } | |
| 1211 | 1206 | |
| 1212 | lj->args.append(get_libc_static_file(g->libc, "libssp.a")); | |
| 1213 | lj->args.append("libmoldname.a"); | |
| 1214 | lj->args.append("libmingwex.a"); | |
| 1215 | lj->args.append("libmsvcrt.a"); | |
| 1207 | lj->args.append(get_libc_static_file(g->libc, "libssp.a")); | |
| 1208 | lj->args.append(get_libc_file(g->libc, "libmoldname.a")); | |
| 1209 | lj->args.append(get_libc_file(g->libc, "libmingwex.a")); | |
| 1210 | lj->args.append(get_libc_file(g->libc, "libmsvcrt.a")); | |
| 1216 | 1211 | |
| 1217 | if (g->subsystem == TargetSubsystemWindows) { | |
| 1218 | lj->args.append("libgdi32.a"); | |
| 1219 | lj->args.append("libcomdlg32.a"); | |
| 1220 | } | |
| 1212 | if (g->subsystem == TargetSubsystemWindows) { | |
| 1213 | lj->args.append(get_libc_file(g->libc, "libgdi32.a")); | |
| 1214 | lj->args.append(get_libc_file(g->libc, "libcomdlg32.a")); | |
| 1215 | } | |
| 1221 | 1216 | |
| 1222 | lj->args.append("libadvapi32.a"); | |
| 1223 | lj->args.append("libadvapi32.a"); | |
| 1224 | lj->args.append("libshell32.a"); | |
| 1225 | lj->args.append("libuser32.a"); | |
| 1226 | lj->args.append("libkernel32.a"); | |
| 1217 | lj->args.append(get_libc_file(g->libc, "libadvapi32.a")); | |
| 1218 | lj->args.append(get_libc_file(g->libc, "libadvapi32.a")); | |
| 1219 | lj->args.append(get_libc_file(g->libc, "libshell32.a")); | |
| 1220 | lj->args.append(get_libc_file(g->libc, "libuser32.a")); | |
| 1221 | lj->args.append(get_libc_file(g->libc, "libkernel32.a")); | |
| 1227 | 1222 | |
| 1228 | lj->args.append(get_libc_static_file(g->libc, "crtend.o")); | |
| 1229 | } | |
| 1223 | lj->args.append(get_libc_static_file(g->libc, "crtend.o")); | |
| 1230 | 1224 | } |
| 1231 | 1225 | |
| 1232 | 1226 | static void add_win_link_args(LinkJob *lj, bool is_library) { |
| ... | ... | @@ -1359,25 +1353,8 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 1359 | 1353 | } |
| 1360 | 1354 | if (link_lib->provided_explicitly) { |
| 1361 | 1355 | if (target_abi_is_gnu(lj->codegen->zig_target->abi)) { |
| 1362 | static const char *test_names[3] = { "%s\\lib%s.dll.a", "%s\\lib%s.a", nullptr }; | |
| 1363 | bool exists = false; | |
| 1364 | ||
| 1365 | for (size_t i = 0; test_names[i] != nullptr && !exists; i++) { | |
| 1366 | for (size_t j = 0; j < g->lib_dirs.length; j += 1) { | |
| 1367 | const char *lib_dir = g->lib_dirs.at(j); | |
| 1368 | Buf *test_path = buf_sprintf(test_names[i], lib_dir, buf_ptr(link_lib->name)); | |
| 1369 | if (os_file_exists(test_path, &exists) != ErrorNone) { | |
| 1370 | zig_panic("link: unable to check if file exists: %s", buf_ptr(test_path)); | |
| 1371 | } else if (exists) { | |
| 1372 | lj->args.append(buf_ptr(test_path)); | |
| 1373 | break; | |
| 1374 | } | |
| 1375 | } | |
| 1376 | } | |
| 1377 | ||
| 1378 | if (!exists) { | |
| 1379 | zig_panic("link: unable to find library: %s", buf_ptr(link_lib->name)); | |
| 1380 | } | |
| 1356 | Buf *lib_name = buf_sprintf("lib%s.a", buf_ptr(link_lib->name)); | |
| 1357 | lj->args.append(buf_ptr(lib_name)); | |
| 1381 | 1358 | } else { |
| 1382 | 1359 | lj->args.append(buf_ptr(link_lib->name)); |
| 1383 | 1360 | } |