authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-10-09 22:08:49+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-10-09 22:44:36+02:00
logb96fa894625fc1aeb5f381dd52d291a6fc170fd1
tree81cceec273c2526b14d08a6fe1755322555a76de
parent9ae293ae3bda918280a9ee254685ec9468e7d141

Compile the architecture-specific mingw sources


1 files changed, 62 insertions(+), 37 deletions(-)

src/link.cpp+62-37
......@@ -552,28 +552,22 @@ static const char *mingwex_arm64_src[] = {
552552
553553struct MinGWDef {
554554 const char *name;
555 const char *path;
556555 bool always_link;
557556};
558557static 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},
577571};
578572
579573struct LinkJob {
......@@ -1955,7 +1949,7 @@ static void print_zig_cc_cmd(ZigList<const char *> *args) {
19551949 fprintf(stderr, "\n");
19561950}
19571951
1958static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_rel_path) {
1952static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_file) {
19591953 Error err;
19601954
19611955 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
19731967 Buf *o_dir = buf_sprintf("%s" OS_SEP CACHE_OUT_SUBDIR, buf_ptr(cache_dir));
19741968 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(cache_dir));
19751969
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));
19781970 Buf *def_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "def-include",
19791971 buf_ptr(parent->zig_lib_dir));
19801972
......@@ -2122,24 +2114,57 @@ static void add_mingw_link_args(LinkJob *lj, bool is_library) {
21222114
21232115 for (size_t def_i = 0; def_i < array_length(mingw_def_list); def_i += 1) {
21242116 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";
21302126 } 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));
21352149 }
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);
21402150 }
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));
21432168 }
21442169 }
21452170}