@@ -30,25 +30,61 @@ var libMinGW = Library{
30
30
sourceDir : func () string { return filepath .Join (goenv .Get ("TINYGOROOT" ), "lib/mingw-w64" ) },
31
31
cflags : func (target , headerPath string ) []string {
32
32
mingwDir := filepath .Join (goenv .Get ("TINYGOROOT" ), "lib/mingw-w64" )
33
- return []string {
33
+ flags := []string {
34
34
"-nostdlibinc" ,
35
+ "-isystem" , mingwDir + "/mingw-w64-crt/include" ,
35
36
"-isystem" , mingwDir + "/mingw-w64-headers/crt" ,
37
+ "-isystem" , mingwDir + "/mingw-w64-headers/include" ,
36
38
"-I" , mingwDir + "/mingw-w64-headers/defaults/include" ,
37
39
"-I" + headerPath ,
38
40
}
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
39
50
},
40
51
librarySources : func (target string ) ([]string , error ) {
41
52
// 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/stdio/acrt_iob_func.c" ,
70
+ "mingw-w64-crt/stdio/mingw_lock.c" ,
71
+ "mingw-w64-crt/stdio/mingw_pformat.c" ,
72
+ "mingw-w64-crt/stdio/mingw_vfprintf.c" ,
73
+ "mingw-w64-crt/stdio/mingw_vsnprintf.c" ,
74
+ }
75
+ } else {
76
+ // Anything somewhat modern (amd64, arm64) uses UCRT.
77
+ sources = []string {
78
+ "mingw-w64-crt/stdio/ucrt_fprintf.c" ,
79
+ "mingw-w64-crt/stdio/ucrt_fwprintf.c" ,
80
+ "mingw-w64-crt/stdio/ucrt_printf.c" ,
81
+ "mingw-w64-crt/stdio/ucrt_snprintf.c" ,
82
+ "mingw-w64-crt/stdio/ucrt_sprintf.c" ,
83
+ "mingw-w64-crt/stdio/ucrt_vfprintf.c" ,
84
+ "mingw-w64-crt/stdio/ucrt_vprintf.c" ,
85
+ "mingw-w64-crt/stdio/ucrt_vsnprintf.c" ,
86
+ "mingw-w64-crt/stdio/ucrt_vsprintf.c" ,
87
+ }
52
88
}
53
89
return sources , nil
54
90
},
@@ -63,27 +99,41 @@ var libMinGW = Library{
63
99
func makeMinGWExtraLibs (tmpdir , goarch string ) []* compileJob {
64
100
var jobs []* compileJob
65
101
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
- } {
102
+ var libs []string
103
+ if goarch == "386" {
104
+ libs = []string {
105
+ // x86 uses msvcrt.dll instead of UCRT for compatibility with old
106
+ // Windows versions.
107
+ "advapi32.def.in" ,
108
+ "kernel32.def.in" ,
109
+ "msvcrt.def.in" ,
110
+ }
111
+ } else {
112
+ // Use the modernized UCRT on new systems.
113
+ // Normally all the api-ms-win-crt-*.def files are all compiled to a
114
+ // single .lib file. But to simplify things, we're going to leave them
115
+ // as separate files.
116
+ libs = []string {
117
+ "advapi32.def.in" ,
118
+ "kernel32.def.in" ,
119
+ "api-ms-win-crt-conio-l1-1-0.def" ,
120
+ "api-ms-win-crt-convert-l1-1-0.def.in" ,
121
+ "api-ms-win-crt-environment-l1-1-0.def" ,
122
+ "api-ms-win-crt-filesystem-l1-1-0.def" ,
123
+ "api-ms-win-crt-heap-l1-1-0.def" ,
124
+ "api-ms-win-crt-locale-l1-1-0.def" ,
125
+ "api-ms-win-crt-math-l1-1-0.def.in" ,
126
+ "api-ms-win-crt-multibyte-l1-1-0.def" ,
127
+ "api-ms-win-crt-private-l1-1-0.def.in" ,
128
+ "api-ms-win-crt-process-l1-1-0.def" ,
129
+ "api-ms-win-crt-runtime-l1-1-0.def.in" ,
130
+ "api-ms-win-crt-stdio-l1-1-0.def" ,
131
+ "api-ms-win-crt-string-l1-1-0.def" ,
132
+ "api-ms-win-crt-time-l1-1-0.def" ,
133
+ "api-ms-win-crt-utility-l1-1-0.def" ,
134
+ }
135
+ }
136
+ for _ , name := range libs {
87
137
outpath := filepath .Join (tmpdir , filepath .Base (name )+ ".lib" )
88
138
inpath := filepath .Join (root , "lib/mingw-w64/mingw-w64-crt/lib-common/" + name )
89
139
job := & compileJob {
0 commit comments