| ... | @@ -14,6 +14,7 @@ static const char *zig_libc_keys[] = { | ... | @@ -14,6 +14,7 @@ static const char *zig_libc_keys[] = { |
| 14 | "include_dir", | 14 | "include_dir", |
| 15 | "sys_include_dir", | 15 | "sys_include_dir", |
| 16 | "crt_dir", | 16 | "crt_dir", |
| | 17 | "static_crt_dir", |
| 17 | "msvc_lib_dir", | 18 | "msvc_lib_dir", |
| 18 | "kernel32_lib_dir", | 19 | "kernel32_lib_dir", |
| 19 | }; | 20 | }; |
| ... | @@ -34,6 +35,7 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) { | ... | @@ -34,6 +35,7 @@ static void zig_libc_init_empty(ZigLibCInstallation *libc) { |
| 34 | buf_init_from_str(&libc->include_dir, ""); | 35 | buf_init_from_str(&libc->include_dir, ""); |
| 35 | buf_init_from_str(&libc->sys_include_dir, ""); | 36 | buf_init_from_str(&libc->sys_include_dir, ""); |
| 36 | buf_init_from_str(&libc->crt_dir, ""); | 37 | buf_init_from_str(&libc->crt_dir, ""); |
| | 38 | buf_init_from_str(&libc->static_crt_dir, ""); |
| 37 | buf_init_from_str(&libc->msvc_lib_dir, ""); | 39 | buf_init_from_str(&libc->msvc_lib_dir, ""); |
| 38 | buf_init_from_str(&libc->kernel32_lib_dir, ""); | 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,8 +76,9 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget |
| 74 | match = match || zig_libc_match_key(name, value, found_keys, 0, &libc->include_dir); | 76 | match = match || zig_libc_match_key(name, value, found_keys, 0, &libc->include_dir); |
| 75 | match = match || zig_libc_match_key(name, value, found_keys, 1, &libc->sys_include_dir); | 77 | match = match || zig_libc_match_key(name, value, found_keys, 1, &libc->sys_include_dir); |
| 76 | match = match || zig_libc_match_key(name, value, found_keys, 2, &libc->crt_dir); | 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); | 79 | match = match || zig_libc_match_key(name, value, found_keys, 3, &libc->static_crt_dir); |
| 78 | match = match || zig_libc_match_key(name, value, found_keys, 4, &libc->kernel32_lib_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 | for (size_t i = 0; i < zig_libc_keys_len; i += 1) { | 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,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 | if (buf_len(&libc->msvc_lib_dir) == 0) { | 125 | if (buf_len(&libc->msvc_lib_dir) == 0) { |
| 114 | if (target->os == OsWindows && !target_abi_is_gnu(target->abi)) { | 126 | if (target->os == OsWindows && !target_abi_is_gnu(target->abi)) { |
| 115 | if (verbose) { | 127 | if (verbose) { |
| ... | @@ -261,7 +273,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b | ... | @@ -261,7 +273,7 @@ static Error zig_libc_find_native_include_dir_posix(ZigLibCInstallation *self, b |
| 261 | return ErrorFileNotFound; | 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 | const char *cc_exe = getenv("CC"); | 277 | const char *cc_exe = getenv("CC"); |
| 266 | cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe; | 278 | cc_exe = (cc_exe == nullptr) ? CC_EXE : cc_exe; |
| 267 | ZigList<const char *> args = {}; | 279 | ZigList<const char *> args = {}; |
| ... | @@ -308,6 +320,10 @@ static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool | ... | @@ -308,6 +320,10 @@ static Error zig_libc_find_native_crt_dir_posix(ZigLibCInstallation *self, bool |
| 308 | return zig_libc_cc_print_file_name("crt1.o", &self->crt_dir, true, verbose); | 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 | #if defined(ZIG_OS_WINDOWS) | 327 | #if defined(ZIG_OS_WINDOWS) |
| 312 | static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, bool verbose) { | 328 | static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self, ZigWindowsSDK *sdk, bool verbose) { |
| 313 | Error err; | 329 | Error err; |
| ... | @@ -320,7 +336,7 @@ static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self, | ... | @@ -320,7 +336,7 @@ static Error zig_libc_find_native_include_dir_windows(ZigLibCInstallation *self, |
| 320 | return ErrorNone; | 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 | bool verbose) | 340 | bool verbose) |
| 325 | { | 341 | { |
| 326 | Error err; | 342 | Error err; |
| ... | @@ -396,11 +412,16 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) { | ... | @@ -396,11 +412,16 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) { |
| 396 | "# On POSIX it's the directory that includes `sys/errno.h`.\n" | 412 | "# On POSIX it's the directory that includes `sys/errno.h`.\n" |
| 397 | "sys_include_dir=%s\n" | 413 | "sys_include_dir=%s\n" |
| 398 | "\n" | 414 | "\n" |
| 399 | "# The directory that contains `crt1.o`.\n" | 415 | "# The directory that contains `crt1.o` or `crt2.o`.\n" |
| 400 | "# On POSIX, can be found with `cc -print-file-name=crt1.o`.\n" | 416 | "# On POSIX, can be found with `cc -print-file-name=crt1.o`.\n" |
| 401 | "# Not needed when targeting MacOS.\n" | 417 | "# Not needed when targeting MacOS.\n" |
| 402 | "crt_dir=%s\n" | 418 | "crt_dir=%s\n" |
| 403 | "\n" | 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 | "# The directory that contains `vcruntime.lib`.\n" | 425 | "# The directory that contains `vcruntime.lib`.\n" |
| 405 | "# Only needed when targeting MSVC on Windows.\n" | 426 | "# Only needed when targeting MSVC on Windows.\n" |
| 406 | "msvc_lib_dir=%s\n" | 427 | "msvc_lib_dir=%s\n" |
| ... | @@ -413,6 +434,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) { | ... | @@ -413,6 +434,7 @@ void zig_libc_render(ZigLibCInstallation *self, FILE *file) { |
| 413 | buf_ptr(&self->include_dir), | 434 | buf_ptr(&self->include_dir), |
| 414 | buf_ptr(&self->sys_include_dir), | 435 | buf_ptr(&self->sys_include_dir), |
| 415 | buf_ptr(&self->crt_dir), | 436 | buf_ptr(&self->crt_dir), |
| | 437 | buf_ptr(&self->static_crt_dir), |
| 416 | buf_ptr(&self->msvc_lib_dir), | 438 | buf_ptr(&self->msvc_lib_dir), |
| 417 | buf_ptr(&self->kernel32_lib_dir) | 439 | buf_ptr(&self->kernel32_lib_dir) |
| 418 | ); | 440 | ); |
| ... | @@ -429,6 +451,8 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) { | ... | @@ -429,6 +451,8 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) { |
| 429 | return err; | 451 | return err; |
| 430 | if ((err = zig_libc_find_native_crt_dir_posix(self, verbose))) | 452 | if ((err = zig_libc_find_native_crt_dir_posix(self, verbose))) |
| 431 | return err; | 453 | return err; |
| | 454 | if ((err = zig_libc_find_native_static_crt_dir_posix(self, verbose))) |
| | 455 | return err; |
| 432 | return ErrorNone; | 456 | return ErrorNone; |
| 433 | } else { | 457 | } else { |
| 434 | ZigWindowsSDK *sdk; | 458 | ZigWindowsSDK *sdk; |
| ... | @@ -442,7 +466,7 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) { | ... | @@ -442,7 +466,7 @@ Error zig_libc_find_native(ZigLibCInstallation *self, bool verbose) { |
| 442 | return err; | 466 | return err; |
| 443 | if ((err = zig_libc_find_native_include_dir_windows(self, sdk, verbose))) | 467 | if ((err = zig_libc_find_native_include_dir_windows(self, sdk, verbose))) |
| 444 | return err; | 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 | return err; | 470 | return err; |
| 447 | return ErrorNone; | 471 | return ErrorNone; |
| 448 | case ZigFindWindowsSdkErrorOutOfMemory: | 472 | case ZigFindWindowsSdkErrorOutOfMemory: |