authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-06 23:16:31-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-04-06 23:16:31-04:00
logab05766674b88dc7715d27f7d590d6832ee005ca
tree64ed2bd23f02c8b90e1b724e6dd99ddd032b6edc
parentafa24ccd993e38b56407c83160da567bc2b0ae8a
parentfc662ddd54df75bf21d1be74c9d720fb8f164591
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #4966 from ziglang/bootstrap-windows

cmake: improvements to cross-compiling for Windows

10 files changed, 71 insertions(+), 15 deletions(-)

CMakeLists.txt+1-7
...@@ -365,7 +365,7 @@ if(ZIG_STATIC)...@@ -365,7 +365,7 @@ if(ZIG_STATIC)
365 endif()365 endif()
366else()366else()
367 if(MINGW)367 if(MINGW)
368 set(EXE_LDFLAGS "${EXE_LDFLAGS} -lz3")368 set(EXE_LDFLAGS "${EXE_LDFLAGS}")
369 endif()369 endif()
370endif()370endif()
371371
...@@ -429,11 +429,6 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")...@@ -429,11 +429,6 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
429else()429else()
430 set(LIBSTAGE2_RELEASE_ARG --release-fast --strip)430 set(LIBSTAGE2_RELEASE_ARG --release-fast --strip)
431endif()431endif()
432if(WIN32)
433 set(LIBSTAGE2_WINDOWS_ARGS "-lntdll")
434else()
435 set(LIBSTAGE2_WINDOWS_ARGS "")
436endif()
437432
438set(BUILD_LIBSTAGE2_ARGS "build-lib"433set(BUILD_LIBSTAGE2_ARGS "build-lib"
439 "src-self-hosted/stage2.zig"434 "src-self-hosted/stage2.zig"
...@@ -447,7 +442,6 @@ set(BUILD_LIBSTAGE2_ARGS "build-lib"...@@ -447,7 +442,6 @@ set(BUILD_LIBSTAGE2_ARGS "build-lib"
447 --bundle-compiler-rt442 --bundle-compiler-rt
448 -fPIC443 -fPIC
449 -lc444 -lc
450 ${LIBSTAGE2_WINDOWS_ARGS}
451)445)
452446
453if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")447if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")
cmake/Findllvm.cmake+1-4
...@@ -144,9 +144,7 @@ else()...@@ -144,9 +144,7 @@ else()
144 /mingw64/lib144 /mingw64/lib
145 /c/msys64/mingw64/lib145 /c/msys64/mingw64/lib
146 c:\\msys64\\mingw64\\lib)146 c:\\msys64\\mingw64\\lib)
147 if(LLVM_${_prettylibname_}_LIB)147 set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_${_prettylibname_}_LIB})
148 set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_${_prettylibname_}_LIB})
149 endif()
150 endmacro(FIND_AND_ADD_LLVM_LIB)148 endmacro(FIND_AND_ADD_LLVM_LIB)
151149
152 # This list can be re-generated with `llvm-config --libfiles` and then150 # This list can be re-generated with `llvm-config --libfiles` and then
...@@ -154,7 +152,6 @@ else()...@@ -154,7 +152,6 @@ else()
154 # `llvm-config` here because we are cross compiling.152 # `llvm-config` here because we are cross compiling.
155 FIND_AND_ADD_LLVM_LIB(LLVMXRay)153 FIND_AND_ADD_LLVM_LIB(LLVMXRay)
156 FIND_AND_ADD_LLVM_LIB(LLVMWindowsManifest)154 FIND_AND_ADD_LLVM_LIB(LLVMWindowsManifest)
157 FIND_AND_ADD_LLVM_LIB(LLVMTableGen)
158 FIND_AND_ADD_LLVM_LIB(LLVMSymbolize)155 FIND_AND_ADD_LLVM_LIB(LLVMSymbolize)
159 FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)156 FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
160 FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)157 FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)
lib/libc/mingw/lib32/version.def created+16
...@@ -0,0 +1,16 @@
1LIBRARY "VERSION.dll"
2EXPORTS
3GetFileVersionInfoA@16
4GetFileVersionInfoSizeA@8
5GetFileVersionInfoSizeW@8
6GetFileVersionInfoW@16
7VerFindFileA@32
8VerFindFileW@32
9VerInstallFileA@32
10VerInstallFileW@32
11VerLanguageNameA@12
12VerLanguageNameW@12
13VerQueryValueA@16
14VerQueryValueIndexA@24
15VerQueryValueIndexW@24
16VerQueryValueW@16
lib/libc/mingw/misc/___mb_cur_max_func.c created+18
...@@ -0,0 +1,18 @@
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#include <_mingw.h>
8
9extern int* __MINGW_IMP_SYMBOL(__mb_cur_max);
10
11int __cdecl ___mb_cur_max_func(void);
12int __cdecl ___mb_cur_max_func(void)
13{
14 return *__MINGW_IMP_SYMBOL(__mb_cur_max);
15}
16
17typedef int __cdecl (*_f___mb_cur_max_func)(void);
18_f___mb_cur_max_func __MINGW_IMP_SYMBOL(___mb_cur_max_func) = ___mb_cur_max_func;
src/all_types.hpp+1
...@@ -2259,6 +2259,7 @@ struct CodeGen {...@@ -2259,6 +2259,7 @@ struct CodeGen {
2259 size_t version_minor;2259 size_t version_minor;
2260 size_t version_patch;2260 size_t version_patch;
2261 const char *linker_script;2261 const char *linker_script;
2262 size_t stack_size_override;
22622263
2263 BuildMode build_mode;2264 BuildMode build_mode;
2264 OutType out_type;2265 OutType out_type;
src/codegen.cpp+1
...@@ -10597,6 +10597,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {...@@ -10597,6 +10597,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
10597 cache_int(ch, g->linker_allow_shlib_undefined);10597 cache_int(ch, g->linker_allow_shlib_undefined);
10598 cache_bool(ch, g->linker_z_nodelete);10598 cache_bool(ch, g->linker_z_nodelete);
10599 cache_bool(ch, g->linker_z_defs);10599 cache_bool(ch, g->linker_z_defs);
10600 cache_usize(ch, g->stack_size_override);
1060010601
10601 // gen_c_objects appends objects to g->link_objects which we want to include in the hash10602 // gen_c_objects appends objects to g->link_objects which we want to include in the hash
10602 gen_c_objects(g);10603 gen_c_objects(g);
src/link.cpp+5-3
...@@ -72,7 +72,7 @@ static const char *msvcrt_common_src[] = {...@@ -72,7 +72,7 @@ static const char *msvcrt_common_src[] = {
7272
73static const char *msvcrt_i386_src[] = {73static const char *msvcrt_i386_src[] = {
74 "misc" OS_SEP "lc_locale_func.c",74 "misc" OS_SEP "lc_locale_func.c",
7575 "misc" OS_SEP "___mb_cur_max_func.c",
76};76};
7777
78static const char *msvcrt_other_src[] = {78static const char *msvcrt_other_src[] = {
...@@ -1840,7 +1840,8 @@ static void construct_linker_job_elf(LinkJob *lj) {...@@ -1840,7 +1840,8 @@ static void construct_linker_job_elf(LinkJob *lj) {
18401840
1841 if (g->out_type == OutTypeExe) {1841 if (g->out_type == OutTypeExe) {
1842 lj->args.append("-z");1842 lj->args.append("-z");
1843 lj->args.append("stack-size=16777216"); // default to 16 MiB1843 size_t stack_size = (g->stack_size_override == 0) ? 16777216 : g->stack_size_override;
1844 lj->args.append(buf_ptr(buf_sprintf("stack-size=%" ZIG_PRI_usize, stack_size)));
1844 }1845 }
18451846
1846 if (g->linker_script) {1847 if (g->linker_script) {
...@@ -2479,7 +2480,8 @@ static void construct_linker_job_coff(LinkJob *lj) {...@@ -2479,7 +2480,8 @@ static void construct_linker_job_coff(LinkJob *lj) {
24792480
2480 if (g->out_type == OutTypeExe) {2481 if (g->out_type == OutTypeExe) {
2481 // TODO compile time stack upper bound detection2482 // TODO compile time stack upper bound detection
2482 lj->args.append("-STACK:16777216");2483 size_t stack_size = (g->stack_size_override == 0) ? 16777216 : g->stack_size_override;
2484 lj->args.append(buf_ptr(buf_sprintf("-STACK:%" ZIG_PRI_usize, stack_size)));
2483 }2485 }
24842486
2485 coff_append_machine_arg(g, &lj->args);2487 coff_append_machine_arg(g, &lj->args);
src/main.cpp+23
...@@ -453,6 +453,7 @@ static int main0(int argc, char **argv) {...@@ -453,6 +453,7 @@ static int main0(int argc, char **argv) {
453 OptionalBool linker_allow_shlib_undefined = OptionalBoolNull;453 OptionalBool linker_allow_shlib_undefined = OptionalBoolNull;
454 bool linker_z_nodelete = false;454 bool linker_z_nodelete = false;
455 bool linker_z_defs = false;455 bool linker_z_defs = false;
456 size_t stack_size_override = 0;
456457
457 ZigList<const char *> llvm_argv = {0};458 ZigList<const char *> llvm_argv = {0};
458 llvm_argv.append("zig (LLVM option parsing)");459 llvm_argv.append("zig (LLVM option parsing)");
...@@ -848,6 +849,27 @@ static int main0(int argc, char **argv) {...@@ -848,6 +849,27 @@ static int main0(int argc, char **argv) {
848 } else {849 } else {
849 fprintf(stderr, "warning: unsupported linker arg: -z %s\n", buf_ptr(z_arg));850 fprintf(stderr, "warning: unsupported linker arg: -z %s\n", buf_ptr(z_arg));
850 }851 }
852 } else if (buf_eql_str(arg, "--major-image-version")) {
853 i += 1;
854 if (i >= linker_args.length) {
855 fprintf(stderr, "expected linker arg after '%s'\n", buf_ptr(arg));
856 return EXIT_FAILURE;
857 }
858 ver_major = atoi(buf_ptr(linker_args.at(i)));
859 } else if (buf_eql_str(arg, "--minor-image-version")) {
860 i += 1;
861 if (i >= linker_args.length) {
862 fprintf(stderr, "expected linker arg after '%s'\n", buf_ptr(arg));
863 return EXIT_FAILURE;
864 }
865 ver_minor = atoi(buf_ptr(linker_args.at(i)));
866 } else if (buf_eql_str(arg, "--stack")) {
867 i += 1;
868 if (i >= linker_args.length) {
869 fprintf(stderr, "expected linker arg after '%s'\n", buf_ptr(arg));
870 return EXIT_FAILURE;
871 }
872 stack_size_override = atoi(buf_ptr(linker_args.at(i)));
851 } else {873 } else {
852 fprintf(stderr, "warning: unsupported linker arg: %s\n", buf_ptr(arg));874 fprintf(stderr, "warning: unsupported linker arg: %s\n", buf_ptr(arg));
853 }875 }
...@@ -1573,6 +1595,7 @@ static int main0(int argc, char **argv) {...@@ -1573,6 +1595,7 @@ static int main0(int argc, char **argv) {
1573 g->linker_allow_shlib_undefined = linker_allow_shlib_undefined;1595 g->linker_allow_shlib_undefined = linker_allow_shlib_undefined;
1574 g->linker_z_nodelete = linker_z_nodelete;1596 g->linker_z_nodelete = linker_z_nodelete;
1575 g->linker_z_defs = linker_z_defs;1597 g->linker_z_defs = linker_z_defs;
1598 g->stack_size_override = stack_size_override;
15761599
1577 if (override_soname) {1600 if (override_soname) {
1578 g->override_soname = buf_create_from_str(override_soname);1601 g->override_soname = buf_create_from_str(override_soname);
src/os.cpp+2
...@@ -37,7 +37,9 @@...@@ -37,7 +37,9 @@
37#include <fcntl.h>37#include <fcntl.h>
38#include <ntsecapi.h>38#include <ntsecapi.h>
3939
40#if defined(_MSC_VER)
40typedef SSIZE_T ssize_t;41typedef SSIZE_T ssize_t;
42#endif
41#else43#else
42#define ZIG_OS_POSIX44#define ZIG_OS_POSIX
4345
src/zig_clang.h+3-1
...@@ -50,7 +50,9 @@ enum ZigClangAPValueKind {...@@ -50,7 +50,9 @@ enum ZigClangAPValueKind {
50struct ZigClangAPValue {50struct ZigClangAPValue {
51 enum ZigClangAPValueKind Kind;51 enum ZigClangAPValueKind Kind;
52 // experimentally-derived size of clang::APValue::DataType52 // experimentally-derived size of clang::APValue::DataType
53#if defined(_WIN32) && defined(_MSC_VER)53#if defined(_WIN32) && defined(__i386__)
54 char Data[68];
55#elif defined(_WIN32) && defined(_MSC_VER)
54 char Data[52];56 char Data[52];
55#elif defined(__i386__)57#elif defined(__i386__)
56 char Data[48];58 char Data[48];