| ... | @@ -1904,8 +1904,7 @@ static void add_uefi_link_args(LinkJob *lj) { | ... | @@ -1904,8 +1904,7 @@ static void add_uefi_link_args(LinkJob *lj) { |
| 1904 | static void add_msvc_link_args(LinkJob *lj, bool is_library) { | 1904 | static void add_msvc_link_args(LinkJob *lj, bool is_library) { |
| 1905 | CodeGen *g = lj->codegen; | 1905 | CodeGen *g = lj->codegen; |
| 1906 | | 1906 | |
| 1907 | // TODO: https://github.com/ziglang/zig/issues/2064 | 1907 | bool is_dynamic = g->is_dynamic; |
| 1908 | bool is_dynamic = true; // g->is_dynamic; | | |
| 1909 | const char *lib_str = is_dynamic ? "" : "lib"; | 1908 | const char *lib_str = is_dynamic ? "" : "lib"; |
| 1910 | const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : ""; | 1909 | const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : ""; |
| 1911 | | 1910 | |
| ... | @@ -2151,7 +2150,7 @@ static void add_win_link_args(LinkJob *lj, bool is_library, bool *have_windows_d | ... | @@ -2151,7 +2150,7 @@ static void add_win_link_args(LinkJob *lj, bool is_library, bool *have_windows_d |
| 2151 | | 2150 | |
| 2152 | static bool is_mingw_link_lib(Buf *name) { | 2151 | static bool is_mingw_link_lib(Buf *name) { |
| 2153 | for (size_t def_i = 0; def_i < array_length(mingw_def_list); def_i += 1) { | 2152 | for (size_t def_i = 0; def_i < array_length(mingw_def_list); def_i += 1) { |
| 2154 | if (buf_eql_str(name, mingw_def_list[def_i].name)) { | 2153 | if (buf_eql_str_ignore_case(name, mingw_def_list[def_i].name)) { |
| 2155 | return true; | 2154 | return true; |
| 2156 | } | 2155 | } |
| 2157 | } | 2156 | } |
| ... | @@ -2265,50 +2264,54 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -2265,50 +2264,54 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 2265 | if (buf_eql_str(link_lib->name, "c")) { | 2264 | if (buf_eql_str(link_lib->name, "c")) { |
| 2266 | continue; | 2265 | continue; |
| 2267 | } | 2266 | } |
| 2268 | if (have_windows_dll_import_libs && is_mingw_link_lib(link_lib->name)) { | 2267 | bool is_sys_lib = is_mingw_link_lib(link_lib->name); |
| | 2268 | if (have_windows_dll_import_libs && is_sys_lib) { |
| 2269 | continue; | 2269 | continue; |
| 2270 | } | 2270 | } |
| 2271 | if (link_lib->provided_explicitly) { | 2271 | // If we're linking in the CRT or the libs are provided explictly we don't want to generate def/libs |
| | 2272 | if ((lj->link_in_crt && is_sys_lib) || link_lib->provided_explicitly) { |
| 2272 | if (target_abi_is_gnu(lj->codegen->zig_target->abi)) { | 2273 | if (target_abi_is_gnu(lj->codegen->zig_target->abi)) { |
| 2273 | Buf *lib_name = buf_sprintf("lib%s.a", buf_ptr(link_lib->name)); | 2274 | Buf* lib_name = buf_sprintf("lib%s.a", buf_ptr(link_lib->name)); |
| 2274 | lj->args.append(buf_ptr(lib_name)); | 2275 | lj->args.append(buf_ptr(lib_name)); |
| 2275 | } else { | | |
| 2276 | lj->args.append(buf_ptr(link_lib->name)); | | |
| 2277 | } | 2276 | } |
| 2278 | } else { | 2277 | else { |
| 2279 | buf_resize(def_contents, 0); | 2278 | Buf* lib_name = buf_sprintf("%s.lib", buf_ptr(link_lib->name)); |
| 2280 | buf_appendf(def_contents, "LIBRARY %s\nEXPORTS\n", buf_ptr(link_lib->name)); | 2279 | lj->args.append(buf_ptr(lib_name)); |
| 2281 | for (size_t exp_i = 0; exp_i < link_lib->symbols.length; exp_i += 1) { | | |
| 2282 | Buf *symbol_name = link_lib->symbols.at(exp_i); | | |
| 2283 | buf_appendf(def_contents, "%s\n", buf_ptr(symbol_name)); | | |
| 2284 | } | 2280 | } |
| 2285 | buf_appendf(def_contents, "\n"); | 2281 | continue; |
| | 2282 | } |
| 2286 | | 2283 | |
| 2287 | Buf *def_path = buf_alloc(); | 2284 | buf_resize(def_contents, 0); |
| 2288 | os_path_join(g->output_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path); | 2285 | buf_appendf(def_contents, "LIBRARY %s\nEXPORTS\n", buf_ptr(link_lib->name)); |
| 2289 | if ((err = os_write_file(def_path, def_contents))) { | 2286 | for (size_t exp_i = 0; exp_i < link_lib->symbols.length; exp_i += 1) { |
| 2290 | zig_panic("error writing def file: %s", err_str(err)); | 2287 | Buf *symbol_name = link_lib->symbols.at(exp_i); |
| 2291 | } | 2288 | buf_appendf(def_contents, "%s\n", buf_ptr(symbol_name)); |
| | 2289 | } |
| | 2290 | buf_appendf(def_contents, "\n"); |
| 2292 | | 2291 | |
| 2293 | Buf *generated_lib_path = buf_alloc(); | 2292 | Buf *def_path = buf_alloc(); |
| 2294 | os_path_join(g->output_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path); | 2293 | os_path_join(g->output_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path); |
| | 2294 | if ((err = os_write_file(def_path, def_contents))) { |
| | 2295 | zig_panic("error writing def file: %s", err_str(err)); |
| | 2296 | } |
| 2295 | | 2297 | |
| 2296 | gen_lib_args.resize(0); | 2298 | Buf *generated_lib_path = buf_alloc(); |
| 2297 | gen_lib_args.append("link"); | 2299 | os_path_join(g->output_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path); |
| 2298 | | 2300 | |
| 2299 | coff_append_machine_arg(g, &gen_lib_args); | 2301 | gen_lib_args.resize(0); |
| 2300 | gen_lib_args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path)))); | 2302 | gen_lib_args.append("link"); |
| 2301 | gen_lib_args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(generated_lib_path)))); | 2303 | |
| 2302 | Buf diag = BUF_INIT; | 2304 | coff_append_machine_arg(g, &gen_lib_args); |
| 2303 | ZigLLVM_ObjectFormatType target_ofmt = target_object_format(g->zig_target); | 2305 | gen_lib_args.append(buf_ptr(buf_sprintf("-DEF:%s", buf_ptr(def_path)))); |
| 2304 | if (!zig_lld_link(target_ofmt, gen_lib_args.items, gen_lib_args.length, &diag)) { | 2306 | gen_lib_args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(generated_lib_path)))); |
| 2305 | fprintf(stderr, "%s\n", buf_ptr(&diag)); | 2307 | Buf diag = BUF_INIT; |
| 2306 | exit(1); | 2308 | ZigLLVM_ObjectFormatType target_ofmt = target_object_format(g->zig_target); |
| 2307 | } | 2309 | if (!zig_lld_link(target_ofmt, gen_lib_args.items, gen_lib_args.length, &diag)) { |
| 2308 | lj->args.append(buf_ptr(generated_lib_path)); | 2310 | fprintf(stderr, "%s\n", buf_ptr(&diag)); |
| | 2311 | exit(1); |
| 2309 | } | 2312 | } |
| | 2313 | lj->args.append(buf_ptr(generated_lib_path)); |
| 2310 | } | 2314 | } |
| 2311 | | | |
| 2312 | } | 2315 | } |
| 2313 | | 2316 | |
| 2314 | | 2317 | |