@@ -30,25 +30,62 @@ var libMinGW = Library{
3030 sourceDir : func () string { return filepath .Join (goenv .Get ("TINYGOROOT" ), "lib/mingw-w64" ) },
3131 cflags : func (target , headerPath string ) []string {
3232 mingwDir := filepath .Join (goenv .Get ("TINYGOROOT" ), "lib/mingw-w64" )
33- return []string {
33+ flags := []string {
3434 "-nostdlibinc" ,
35+ "-isystem" , mingwDir + "/mingw-w64-crt/include" ,
3536 "-isystem" , mingwDir + "/mingw-w64-headers/crt" ,
37+ "-isystem" , mingwDir + "/mingw-w64-headers/include" ,
3638 "-I" , mingwDir + "/mingw-w64-headers/defaults/include" ,
3739 "-I" + headerPath ,
3840 }
41+ if strings .Split (target , "-" )[0 ] == "i386" {
42+ flags = append (flags ,
43+ "-D__MSVCRT_VERSION__=0x700" , // Microsoft Visual C++ .NET 2002
44+ "-D_WIN32_WINNT=0x0501" , // target Windows XP
45+ "-D_CRTBLD" ,
46+ "-Wno-pragma-pack" ,
47+ )
48+ }
49+ return flags
3950 },
4051 librarySources : func (target string ) ([]string , error ) {
4152 // These files are needed so that printf and the like are supported.
42- sources := []string {
43- "mingw-w64-crt/stdio/ucrt_fprintf.c" ,
44- "mingw-w64-crt/stdio/ucrt_fwprintf.c" ,
45- "mingw-w64-crt/stdio/ucrt_printf.c" ,
46- "mingw-w64-crt/stdio/ucrt_snprintf.c" ,
47- "mingw-w64-crt/stdio/ucrt_sprintf.c" ,
48- "mingw-w64-crt/stdio/ucrt_vfprintf.c" ,
49- "mingw-w64-crt/stdio/ucrt_vprintf.c" ,
50- "mingw-w64-crt/stdio/ucrt_vsnprintf.c" ,
51- "mingw-w64-crt/stdio/ucrt_vsprintf.c" ,
53+ var sources []string
54+ if strings .Split (target , "-" )[0 ] == "i386" {
55+ // Old 32-bit x86 systems use msvcrt.dll.
56+ sources = []string {
57+ "mingw-w64-crt/crt/pseudo-reloc.c" ,
58+ "mingw-w64-crt/gdtoa/dmisc.c" ,
59+ "mingw-w64-crt/gdtoa/gdtoa.c" ,
60+ "mingw-w64-crt/gdtoa/gmisc.c" ,
61+ "mingw-w64-crt/gdtoa/misc.c" ,
62+ "mingw-w64-crt/math/x86/exp2.S" ,
63+ "mingw-w64-crt/math/x86/trunc.S" ,
64+ "mingw-w64-crt/misc/___mb_cur_max_func.c" ,
65+ "mingw-w64-crt/misc/lc_locale_func.c" ,
66+ "mingw-w64-crt/misc/mbrtowc.c" ,
67+ "mingw-w64-crt/misc/strnlen.c" ,
68+ "mingw-w64-crt/misc/wcrtomb.c" ,
69+ "mingw-w64-crt/misc/wcsnlen.c" ,
70+ "mingw-w64-crt/stdio/acrt_iob_func.c" ,
71+ "mingw-w64-crt/stdio/mingw_lock.c" ,
72+ "mingw-w64-crt/stdio/mingw_pformat.c" ,
73+ "mingw-w64-crt/stdio/mingw_vfprintf.c" ,
74+ "mingw-w64-crt/stdio/mingw_vsnprintf.c" ,
75+ }
76+ } else {
77+ // Anything somewhat modern (amd64, arm64) uses UCRT.
78+ sources = []string {
79+ "mingw-w64-crt/stdio/ucrt_fprintf.c" ,
80+ "mingw-w64-crt/stdio/ucrt_fwprintf.c" ,
81+ "mingw-w64-crt/stdio/ucrt_printf.c" ,
82+ "mingw-w64-crt/stdio/ucrt_snprintf.c" ,
83+ "mingw-w64-crt/stdio/ucrt_sprintf.c" ,
84+ "mingw-w64-crt/stdio/ucrt_vfprintf.c" ,
85+ "mingw-w64-crt/stdio/ucrt_vprintf.c" ,
86+ "mingw-w64-crt/stdio/ucrt_vsnprintf.c" ,
87+ "mingw-w64-crt/stdio/ucrt_vsprintf.c" ,
88+ }
5289 }
5390 return sources , nil
5491 },
@@ -63,27 +100,41 @@ var libMinGW = Library{
63100func makeMinGWExtraLibs (tmpdir , goarch string ) []* compileJob {
64101 var jobs []* compileJob
65102 root := goenv .Get ("TINYGOROOT" )
66- // Normally all the api-ms-win-crt-*.def files are all compiled to a single
67- // .lib file. But to simplify things, we're going to leave them as separate
68- // files.
69- for _ , name := range []string {
70- "kernel32.def.in" ,
71- "api-ms-win-crt-conio-l1-1-0.def" ,
72- "api-ms-win-crt-convert-l1-1-0.def.in" ,
73- "api-ms-win-crt-environment-l1-1-0.def" ,
74- "api-ms-win-crt-filesystem-l1-1-0.def" ,
75- "api-ms-win-crt-heap-l1-1-0.def" ,
76- "api-ms-win-crt-locale-l1-1-0.def" ,
77- "api-ms-win-crt-math-l1-1-0.def.in" ,
78- "api-ms-win-crt-multibyte-l1-1-0.def" ,
79- "api-ms-win-crt-private-l1-1-0.def.in" ,
80- "api-ms-win-crt-process-l1-1-0.def" ,
81- "api-ms-win-crt-runtime-l1-1-0.def.in" ,
82- "api-ms-win-crt-stdio-l1-1-0.def" ,
83- "api-ms-win-crt-string-l1-1-0.def" ,
84- "api-ms-win-crt-time-l1-1-0.def" ,
85- "api-ms-win-crt-utility-l1-1-0.def" ,
86- } {
103+ var libs []string
104+ if goarch == "386" {
105+ libs = []string {
106+ // x86 uses msvcrt.dll instead of UCRT for compatibility with old
107+ // Windows versions.
108+ "advapi32.def.in" ,
109+ "kernel32.def.in" ,
110+ "msvcrt.def.in" ,
111+ }
112+ } else {
113+ // Use the modernized UCRT on new systems.
114+ // Normally all the api-ms-win-crt-*.def files are all compiled to a
115+ // single .lib file. But to simplify things, we're going to leave them
116+ // as separate files.
117+ libs = []string {
118+ "advapi32.def.in" ,
119+ "kernel32.def.in" ,
120+ "api-ms-win-crt-conio-l1-1-0.def" ,
121+ "api-ms-win-crt-convert-l1-1-0.def.in" ,
122+ "api-ms-win-crt-environment-l1-1-0.def" ,
123+ "api-ms-win-crt-filesystem-l1-1-0.def" ,
124+ "api-ms-win-crt-heap-l1-1-0.def" ,
125+ "api-ms-win-crt-locale-l1-1-0.def" ,
126+ "api-ms-win-crt-math-l1-1-0.def.in" ,
127+ "api-ms-win-crt-multibyte-l1-1-0.def" ,
128+ "api-ms-win-crt-private-l1-1-0.def.in" ,
129+ "api-ms-win-crt-process-l1-1-0.def" ,
130+ "api-ms-win-crt-runtime-l1-1-0.def.in" ,
131+ "api-ms-win-crt-stdio-l1-1-0.def" ,
132+ "api-ms-win-crt-string-l1-1-0.def" ,
133+ "api-ms-win-crt-time-l1-1-0.def" ,
134+ "api-ms-win-crt-utility-l1-1-0.def" ,
135+ }
136+ }
137+ for _ , name := range libs {
87138 outpath := filepath .Join (tmpdir , filepath .Base (name )+ ".lib" )
88139 inpath := filepath .Join (root , "lib/mingw-w64/mingw-w64-crt/lib-common/" + name )
89140 job := & compileJob {
0 commit comments