| ... | ... | @@ -552,28 +552,22 @@ static const char *mingwex_arm64_src[] = { |
| 552 | 552 | |
| 553 | 553 | struct MinGWDef { |
| 554 | 554 | const char *name; |
| 555 | | const char *path; |
| 556 | 555 | bool always_link; |
| 557 | 556 | }; |
| 558 | 557 | static const MinGWDef mingw_def_list[] = { |
| 559 | | {"msvcrt", "lib-common" OS_SEP "msvcrt.def.in", true}, |
| 560 | | {"setupapi", "libarm32" OS_SEP "setupapi.def", false}, |
| 561 | | {"setupapi", "libarm64" OS_SEP "setupapi.def", false}, |
| 562 | | {"setupapi", "lib32" OS_SEP "setupapi.def", false}, |
| 563 | | {"setupapi", "lib64" OS_SEP "setupapi.def", false}, |
| 564 | | {"winmm", "lib-common" OS_SEP "winmm.def", false}, |
| 565 | | {"gdi32", "lib-common" OS_SEP "gdi32.def", false}, |
| 566 | | {"imm32", "lib-common" OS_SEP "imm32.def", false}, |
| 567 | | {"version", "lib-common" OS_SEP "version.def", false}, |
| 568 | | {"advapi32", "lib-common" OS_SEP "advapi32.def.in", true}, |
| 569 | | {"oleaut32", "lib-common" OS_SEP "oleaut32.def.in", false}, |
| 570 | | {"ole32", "lib-common" OS_SEP "ole32.def.in", false}, |
| 571 | | {"shell32", "lib-common" OS_SEP "shell32.def", true}, |
| 572 | | {"user32", "lib-common" OS_SEP "user32.def.in", true}, |
| 573 | | {"kernel32", "lib-common" OS_SEP "kernel32.def.in", true}, |
| 574 | | {"ntdll", "libarm32" OS_SEP "ntdll.def", true}, |
| 575 | | {"ntdll", "lib32" OS_SEP "ntdll.def", true}, |
| 576 | | {"ntdll", "lib64" OS_SEP "ntdll.def", true}, |
| 558 | {"advapi32",true}, |
| 559 | {"gdi32", false}, |
| 560 | {"imm32", false}, |
| 561 | {"kernel32",true}, |
| 562 | {"msvcrt", true}, |
| 563 | {"ntdll", true}, |
| 564 | {"ole32", false}, |
| 565 | {"oleaut32",false}, |
| 566 | {"setupapi",false}, |
| 567 | {"shell32", true}, |
| 568 | {"user32", true}, |
| 569 | {"version", false}, |
| 570 | {"winmm", false}, |
| 577 | 571 | }; |
| 578 | 572 | |
| 579 | 573 | struct LinkJob { |
| ... | ... | @@ -1955,7 +1949,7 @@ static void print_zig_cc_cmd(ZigList<const char *> *args) { |
| 1955 | 1949 | fprintf(stderr, "\n"); |
| 1956 | 1950 | } |
| 1957 | 1951 | |
| 1958 | | static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_rel_path) { |
| 1952 | static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_file) { |
| 1959 | 1953 | Error err; |
| 1960 | 1954 | |
| 1961 | 1955 | Buf *self_exe_path = buf_alloc(); |
| ... | ... | @@ -1973,8 +1967,6 @@ static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_re |
| 1973 | 1967 | Buf *o_dir = buf_sprintf("%s" OS_SEP CACHE_OUT_SUBDIR, buf_ptr(cache_dir)); |
| 1974 | 1968 | Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(cache_dir)); |
| 1975 | 1969 | |
| 1976 | | Buf *def_in_file = buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s", |
| 1977 | | buf_ptr(parent->zig_lib_dir), buf_ptr(def_in_rel_path)); |
| 1978 | 1970 | Buf *def_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "def-include", |
| 1979 | 1971 | buf_ptr(parent->zig_lib_dir)); |
| 1980 | 1972 | |
| ... | ... | @@ -2122,24 +2114,57 @@ static void add_mingw_link_args(LinkJob *lj, bool is_library) { |
| 2122 | 2114 | |
| 2123 | 2115 | for (size_t def_i = 0; def_i < array_length(mingw_def_list); def_i += 1) { |
| 2124 | 2116 | const char *name = mingw_def_list[def_i].name; |
| 2125 | | Buf *path = buf_create_from_str(mingw_def_list[def_i].path); |
| 2126 | | bool always_link = mingw_def_list[def_i].always_link; |
| 2127 | | bool is_this_arch = false; |
| 2128 | | if (buf_starts_with_str(path, "lib-common" OS_SEP)) { |
| 2129 | | is_this_arch = true; |
| 2117 | const bool always_link = mingw_def_list[def_i].always_link; |
| 2118 | |
| 2119 | Buf override_path = BUF_INIT; |
| 2120 | |
| 2121 | char const *lib_path = nullptr; |
| 2122 | if (g->zig_target->arch == ZigLLVM_x86) { |
| 2123 | lib_path = "lib32"; |
| 2124 | } else if (g->zig_target->arch == ZigLLVM_x86_64) { |
| 2125 | lib_path = "lib64"; |
| 2130 | 2126 | } else if (target_is_arm(g->zig_target)) { |
| 2131 | | if (target_arch_pointer_bit_width(g->zig_target->arch) == 32) { |
| 2132 | | is_this_arch = buf_starts_with_str(path, "libarm32" OS_SEP); |
| 2133 | | } else { |
| 2134 | | is_this_arch = buf_starts_with_str(path, "libarm64" OS_SEP); |
| 2127 | const bool is_32 = target_arch_pointer_bit_width(g->zig_target->arch) == 32; |
| 2128 | lib_path = is_32 ? "libarm32" : "libarm64"; |
| 2129 | } else { |
| 2130 | zig_unreachable(); |
| 2131 | } |
| 2132 | |
| 2133 | // Try the archtecture-specific path first |
| 2134 | buf_resize(&override_path, 0); |
| 2135 | buf_appendf(&override_path, "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s" OS_SEP "%s.def", buf_ptr(g->zig_lib_dir), lib_path, name); |
| 2136 | |
| 2137 | bool does_exist; |
| 2138 | if (os_file_exists(&override_path, &does_exist) != ErrorNone) { |
| 2139 | zig_panic("link: unable to check if file exists: %s", buf_ptr(&override_path)); |
| 2140 | } |
| 2141 | |
| 2142 | if (!does_exist) { |
| 2143 | // Try the generic version |
| 2144 | buf_resize(&override_path, 0); |
| 2145 | buf_appendf(&override_path, "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "lib-common" OS_SEP "%s.def", buf_ptr(g->zig_lib_dir), name); |
| 2146 | |
| 2147 | if (os_file_exists(&override_path, &does_exist) != ErrorNone) { |
| 2148 | zig_panic("link: unable to check if file exists: %s", buf_ptr(&override_path)); |
| 2135 | 2149 | } |
| 2136 | | } else if (g->zig_target->arch == ZigLLVM_x86) { |
| 2137 | | is_this_arch = buf_starts_with_str(path, "lib32" OS_SEP); |
| 2138 | | } else if (g->zig_target->arch == ZigLLVM_x86_64) { |
| 2139 | | is_this_arch = buf_starts_with_str(path, "lib64" OS_SEP); |
| 2140 | 2150 | } |
| 2141 | | if (is_this_arch && (always_link || is_linking_system_lib(g, name))) { |
| 2142 | | lj->args.append(get_def_lib(g, name, path)); |
| 2151 | |
| 2152 | if (!does_exist) { |
| 2153 | // Try the generic version and preprocess it |
| 2154 | buf_resize(&override_path, 0); |
| 2155 | buf_appendf(&override_path, "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "lib-common" OS_SEP "%s.def.in", buf_ptr(g->zig_lib_dir), name); |
| 2156 | |
| 2157 | if (os_file_exists(&override_path, &does_exist) != ErrorNone) { |
| 2158 | zig_panic("link: unable to check if file exists: %s", buf_ptr(&override_path)); |
| 2159 | } |
| 2160 | } |
| 2161 | |
| 2162 | if (!does_exist) { |
| 2163 | zig_panic("link: could not find .def file to build %s\n", name); |
| 2164 | } |
| 2165 | |
| 2166 | if (always_link || is_linking_system_lib(g, name)) { |
| 2167 | lj->args.append(get_def_lib(g, name, &override_path)); |
| 2143 | 2168 | } |
| 2144 | 2169 | } |
| 2145 | 2170 | } |