| author | |
| committer | |
| log | cbb6d2239f84ee13279655fc591530a23301d188 |
| tree | c89c4ecb59a0a91521ff32b81755ac56fb9336d7 |
| parent | 8cfb0cfbcee8161c52f71bccc3cf1b8d988f83b0 |
See #539
before we close the issue we should also detect MSVC 2017
but this gets us started with supporting MSVC 20156 files changed, 91 insertions(+), 5 deletions(-)
src/all_types.hpp+2| ... | @@ -1461,6 +1461,8 @@ struct CodeGen { | ... | @@ -1461,6 +1461,8 @@ struct CodeGen { |
| 1461 | Buf *libc_lib_dir; | 1461 | Buf *libc_lib_dir; |
| 1462 | Buf *libc_static_lib_dir; | 1462 | Buf *libc_static_lib_dir; |
| 1463 | Buf *libc_include_dir; | 1463 | Buf *libc_include_dir; |
| 1464 | Buf *msvc_lib_dir; | ||
| 1465 | Buf *kernel32_lib_dir; | ||
| 1464 | Buf *zig_lib_dir; | 1466 | Buf *zig_lib_dir; |
| 1465 | Buf *zig_std_dir; | 1467 | Buf *zig_std_dir; |
| 1466 | Buf *zig_c_headers_dir; | 1468 | Buf *zig_c_headers_dir; |
src/analyze.cpp+55| ... | @@ -3359,6 +3359,61 @@ void find_libc_include_path(CodeGen *g) { | ... | @@ -3359,6 +3359,61 @@ void find_libc_include_path(CodeGen *g) { |
| 3359 | } | 3359 | } |
| 3360 | 3360 | ||
| 3361 | void find_libc_lib_path(CodeGen *g) { | 3361 | void find_libc_lib_path(CodeGen *g) { |
| 3362 | #ifdef ZIG_OS_WINDOWS | ||
| 3363 | if (!g->msvc_lib_dir && g->zig_target.os == ZigLLVM_Win32) { | ||
| 3364 | Buf *msvc_lib_dir; | ||
| 3365 | if (g->zig_target.arch.arch == ZigLLVM_arm) { | ||
| 3366 | msvc_lib_dir = buf_create_from_str("C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\lib\\arm"); | ||
| 3367 | } else if (g->zig_target.arch.arch == ZigLLVM_x86_64) { | ||
| 3368 | msvc_lib_dir = buf_create_from_str("C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\lib\\amd64"); | ||
| 3369 | } else if (g->zig_target.arch.arch == ZigLLVM_x86) { | ||
| 3370 | msvc_lib_dir = buf_create_from_str("C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\lib"); | ||
| 3371 | } else { | ||
| 3372 | zig_panic("unable to determine msvc lib path"); | ||
| 3373 | } | ||
| 3374 | Buf *test_path = buf_alloc(); | ||
| 3375 | os_path_join(msvc_lib_dir, buf_create_from_str("vcruntime.lib"), test_path); | ||
| 3376 | bool result; | ||
| 3377 | int err; | ||
| 3378 | if ((err = os_file_exists(test_path, &result))) { | ||
| 3379 | result = false; | ||
| 3380 | } | ||
| 3381 | if (result) { | ||
| 3382 | g->msvc_lib_dir = msvc_lib_dir; | ||
| 3383 | } else { | ||
| 3384 | zig_panic("Unable to determine msvc lib path."); | ||
| 3385 | } | ||
| 3386 | } | ||
| 3387 | |||
| 3388 | if (!g->kernel32_lib_dir && g->zig_target.os == ZigLLVM_Win32) { | ||
| 3389 | Buf *kernel32_lib_dir; | ||
| 3390 | if (g->zig_target.arch.arch == ZigLLVM_arm) { | ||
| 3391 | kernel32_lib_dir = buf_create_from_str( | ||
| 3392 | "C:\\Program Files (x86)\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\arm"); | ||
| 3393 | } else if (g->zig_target.arch.arch == ZigLLVM_x86_64) { | ||
| 3394 | kernel32_lib_dir = buf_create_from_str( | ||
| 3395 | "C:\\Program Files (x86)\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\x64"); | ||
| 3396 | } else if (g->zig_target.arch.arch == ZigLLVM_x86) { | ||
| 3397 | kernel32_lib_dir = buf_create_from_str( | ||
| 3398 | "C:\\Program Files (x86)\\Windows Kits\\8.1\\Lib\\winv6.3\\um\\x86"); | ||
| 3399 | } else { | ||
| 3400 | zig_panic("unable to determine kernel32 lib path"); | ||
| 3401 | } | ||
| 3402 | Buf *test_path = buf_alloc(); | ||
| 3403 | os_path_join(kernel32_lib_dir, buf_create_from_str("kernel32.lib"), test_path); | ||
| 3404 | bool result; | ||
| 3405 | int err; | ||
| 3406 | if ((err = os_file_exists(test_path, &result))) { | ||
| 3407 | result = false; | ||
| 3408 | } | ||
| 3409 | if (result) { | ||
| 3410 | g->kernel32_lib_dir = kernel32_lib_dir; | ||
| 3411 | } else { | ||
| 3412 | zig_panic("Unable to determine kernel32 lib path."); | ||
| 3413 | } | ||
| 3414 | } | ||
| 3415 | #endif | ||
| 3416 | |||
| 3362 | // later we can handle this better by reporting an error via the normal mechanism | 3417 | // later we can handle this better by reporting an error via the normal mechanism |
| 3363 | if (!g->libc_lib_dir || buf_len(g->libc_lib_dir) == 0) { | 3418 | if (!g->libc_lib_dir || buf_len(g->libc_lib_dir) == 0) { |
| 3364 | zig_panic("Unable to determine libc lib path."); | 3419 | zig_panic("Unable to determine libc lib path."); |
src/codegen.cpp+12| ... | @@ -117,6 +117,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out | ... | @@ -117,6 +117,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out |
| 117 | g->libc_lib_dir = buf_create_from_str(""); | 117 | g->libc_lib_dir = buf_create_from_str(""); |
| 118 | g->libc_static_lib_dir = buf_create_from_str(""); | 118 | g->libc_static_lib_dir = buf_create_from_str(""); |
| 119 | g->libc_include_dir = buf_create_from_str(""); | 119 | g->libc_include_dir = buf_create_from_str(""); |
| 120 | g->msvc_lib_dir = nullptr; | ||
| 121 | g->kernel32_lib_dir = nullptr; | ||
| 120 | g->each_lib_rpath = false; | 122 | g->each_lib_rpath = false; |
| 121 | } else { | 123 | } else { |
| 122 | // native compilation, we can rely on the configuration stuff | 124 | // native compilation, we can rely on the configuration stuff |
| ... | @@ -127,6 +129,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out | ... | @@ -127,6 +129,8 @@ CodeGen *codegen_create(Buf *root_src_path, const ZigTarget *target, OutType out |
| 127 | g->libc_lib_dir = buf_create_from_str(ZIG_LIBC_LIB_DIR); | 129 | g->libc_lib_dir = buf_create_from_str(ZIG_LIBC_LIB_DIR); |
| 128 | g->libc_static_lib_dir = buf_create_from_str(ZIG_LIBC_STATIC_LIB_DIR); | 130 | g->libc_static_lib_dir = buf_create_from_str(ZIG_LIBC_STATIC_LIB_DIR); |
| 129 | g->libc_include_dir = buf_create_from_str(ZIG_LIBC_INCLUDE_DIR); | 131 | g->libc_include_dir = buf_create_from_str(ZIG_LIBC_INCLUDE_DIR); |
| 132 | g->msvc_lib_dir = nullptr; // find it at runtime | ||
| 133 | g->kernel32_lib_dir = nullptr; // find it at runtime | ||
| 130 | #ifdef ZIG_EACH_LIB_RPATH | 134 | #ifdef ZIG_EACH_LIB_RPATH |
| 131 | g->each_lib_rpath = true; | 135 | g->each_lib_rpath = true; |
| 132 | #endif | 136 | #endif |
| ... | @@ -228,6 +232,14 @@ void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) { | ... | @@ -228,6 +232,14 @@ void codegen_set_libc_include_dir(CodeGen *g, Buf *libc_include_dir) { |
| 228 | g->libc_include_dir = libc_include_dir; | 232 | g->libc_include_dir = libc_include_dir; |
| 229 | } | 233 | } |
| 230 | 234 | ||
| 235 | void codegen_set_msvc_lib_dir(CodeGen *g, Buf *msvc_lib_dir) { | ||
| 236 | g->msvc_lib_dir = msvc_lib_dir; | ||
| 237 | } | ||
| 238 | |||
| 239 | void codegen_set_kernel32_lib_dir(CodeGen *g, Buf *kernel32_lib_dir) { | ||
| 240 | g->kernel32_lib_dir = kernel32_lib_dir; | ||
| 241 | } | ||
| 242 | |||
| 231 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker) { | 243 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker) { |
| 232 | g->dynamic_linker = dynamic_linker; | 244 | g->dynamic_linker = dynamic_linker; |
| 233 | } | 245 | } |
src/codegen.hpp+2| ... | @@ -31,6 +31,8 @@ void codegen_set_out_name(CodeGen *codegen, Buf *out_name); | ... | @@ -31,6 +31,8 @@ void codegen_set_out_name(CodeGen *codegen, Buf *out_name); |
| 31 | void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir); | 31 | void codegen_set_libc_lib_dir(CodeGen *codegen, Buf *libc_lib_dir); |
| 32 | void codegen_set_libc_static_lib_dir(CodeGen *g, Buf *libc_static_lib_dir); | 32 | void codegen_set_libc_static_lib_dir(CodeGen *g, Buf *libc_static_lib_dir); |
| 33 | void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir); | 33 | void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir); |
| 34 | void codegen_set_msvc_lib_dir(CodeGen *codegen, Buf *msvc_lib_dir); | ||
| 35 | void codegen_set_kernel32_lib_dir(CodeGen *codegen, Buf *kernel32_lib_dir); | ||
| 34 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker); | 36 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker); |
| 35 | void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole); | 37 | void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole); |
| 36 | void codegen_set_windows_unicode(CodeGen *g, bool municode); | 38 | void codegen_set_windows_unicode(CodeGen *g, bool municode); |
src/link.cpp+8-5| ... | @@ -397,6 +397,14 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -397,6 +397,14 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 397 | 397 | ||
| 398 | lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&lj->out_file)))); | 398 | lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&lj->out_file)))); |
| 399 | 399 | ||
| 400 | if (g->libc_link_lib != nullptr) { | ||
| 401 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->msvc_lib_dir)))); | ||
| 402 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->kernel32_lib_dir)))); | ||
| 403 | |||
| 404 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_lib_dir)))); | ||
| 405 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_static_lib_dir)))); | ||
| 406 | } | ||
| 407 | |||
| 400 | if (lj->link_in_crt) { | 408 | if (lj->link_in_crt) { |
| 401 | const char *lib_str = g->is_static ? "lib" : ""; | 409 | const char *lib_str = g->is_static ? "lib" : ""; |
| 402 | const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : ""; | 410 | const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : ""; |
| ... | @@ -441,11 +449,6 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -441,11 +449,6 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 441 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", lib_dir))); | 449 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", lib_dir))); |
| 442 | } | 450 | } |
| 443 | 451 | ||
| 444 | if (g->libc_link_lib != nullptr) { | ||
| 445 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_lib_dir)))); | ||
| 446 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_static_lib_dir)))); | ||
| 447 | } | ||
| 448 | |||
| 449 | for (size_t i = 0; i < g->link_objects.length; i += 1) { | 452 | for (size_t i = 0; i < g->link_objects.length; i += 1) { |
| 450 | lj->args.append((const char *)buf_ptr(g->link_objects.at(i))); | 453 | lj->args.append((const char *)buf_ptr(g->link_objects.at(i))); |
| 451 | } | 454 | } |
src/main.cpp+12| ... | @@ -59,6 +59,8 @@ static int usage(const char *arg0) { | ... | @@ -59,6 +59,8 @@ static int usage(const char *arg0) { |
| 59 | " --each-lib-rpath add rpath for each used dynamic library\n" | 59 | " --each-lib-rpath add rpath for each used dynamic library\n" |
| 60 | " --libc-lib-dir [path] directory where libc crt1.o resides\n" | 60 | " --libc-lib-dir [path] directory where libc crt1.o resides\n" |
| 61 | " --libc-static-lib-dir [path] directory where libc crtbegin.o resides\n" | 61 | " --libc-static-lib-dir [path] directory where libc crtbegin.o resides\n" |
| 62 | " --msvc-lib-dir [path] (windows) directory where vcruntime.lib resides\n" | ||
| 63 | " --kernel32-lib-dir [path] (windows) directory where kernel32.lib resides\n" | ||
| 62 | " --library [lib] link against lib\n" | 64 | " --library [lib] link against lib\n" |
| 63 | " --library-path [dir] add a directory to the library search path\n" | 65 | " --library-path [dir] add a directory to the library search path\n" |
| 64 | " --linker-script [path] use a custom linker script\n" | 66 | " --linker-script [path] use a custom linker script\n" |
| ... | @@ -279,6 +281,8 @@ int main(int argc, char **argv) { | ... | @@ -279,6 +281,8 @@ int main(int argc, char **argv) { |
| 279 | const char *libc_lib_dir = nullptr; | 281 | const char *libc_lib_dir = nullptr; |
| 280 | const char *libc_static_lib_dir = nullptr; | 282 | const char *libc_static_lib_dir = nullptr; |
| 281 | const char *libc_include_dir = nullptr; | 283 | const char *libc_include_dir = nullptr; |
| 284 | const char *msvc_lib_dir = nullptr; | ||
| 285 | const char *kernel32_lib_dir = nullptr; | ||
| 282 | const char *zig_install_prefix = nullptr; | 286 | const char *zig_install_prefix = nullptr; |
| 283 | const char *dynamic_linker = nullptr; | 287 | const char *dynamic_linker = nullptr; |
| 284 | ZigList<const char *> clang_argv = {0}; | 288 | ZigList<const char *> clang_argv = {0}; |
| ... | @@ -518,6 +522,10 @@ int main(int argc, char **argv) { | ... | @@ -518,6 +522,10 @@ int main(int argc, char **argv) { |
| 518 | libc_static_lib_dir = argv[i]; | 522 | libc_static_lib_dir = argv[i]; |
| 519 | } else if (strcmp(arg, "--libc-include-dir") == 0) { | 523 | } else if (strcmp(arg, "--libc-include-dir") == 0) { |
| 520 | libc_include_dir = argv[i]; | 524 | libc_include_dir = argv[i]; |
| 525 | } else if (strcmp(arg, "--msvc-lib-dir") == 0) { | ||
| 526 | msvc_lib_dir = argv[i]; | ||
| 527 | } else if (strcmp(arg, "--kernel32-lib-dir") == 0) { | ||
| 528 | kernel32_lib_dir = argv[i]; | ||
| 521 | } else if (strcmp(arg, "--zig-install-prefix") == 0) { | 529 | } else if (strcmp(arg, "--zig-install-prefix") == 0) { |
| 522 | zig_install_prefix = argv[i]; | 530 | zig_install_prefix = argv[i]; |
| 523 | } else if (strcmp(arg, "--dynamic-linker") == 0) { | 531 | } else if (strcmp(arg, "--dynamic-linker") == 0) { |
| ... | @@ -728,6 +736,10 @@ int main(int argc, char **argv) { | ... | @@ -728,6 +736,10 @@ int main(int argc, char **argv) { |
| 728 | codegen_set_libc_static_lib_dir(g, buf_create_from_str(libc_static_lib_dir)); | 736 | codegen_set_libc_static_lib_dir(g, buf_create_from_str(libc_static_lib_dir)); |
| 729 | if (libc_include_dir) | 737 | if (libc_include_dir) |
| 730 | codegen_set_libc_include_dir(g, buf_create_from_str(libc_include_dir)); | 738 | codegen_set_libc_include_dir(g, buf_create_from_str(libc_include_dir)); |
| 739 | if (msvc_lib_dir) | ||
| 740 | codegen_set_msvc_lib_dir(g, buf_create_from_str(msvc_lib_dir)); | ||
| 741 | if (kernel32_lib_dir) | ||
| 742 | codegen_set_kernel32_lib_dir(g, buf_create_from_str(kernel32_lib_dir)); | ||
| 731 | if (dynamic_linker) | 743 | if (dynamic_linker) |
| 732 | codegen_set_dynamic_linker(g, buf_create_from_str(dynamic_linker)); | 744 | codegen_set_dynamic_linker(g, buf_create_from_str(dynamic_linker)); |
| 733 | codegen_set_verbose(g, verbose); | 745 | codegen_set_verbose(g, verbose); |