mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
windows: use MSVCRT.DLL instead of UCRT on i386
This allows the binaries to run on Windows XP, without needing any extra DLLs. Tested in an x86 Windows XP SP3 virtual machine.
This commit is contained in:
committed by
Ron Evans
parent
f542717992
commit
aa63f26f36
@@ -3,6 +3,7 @@ package builder
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/tinygo-org/tinygo/compileopts"
|
||||
"github.com/tinygo-org/tinygo/goenv"
|
||||
@@ -201,6 +202,11 @@ var avrBuiltins = []string{
|
||||
"avr/udivmodqi4.S",
|
||||
}
|
||||
|
||||
// Builtins needed specifically for windows/386.
|
||||
var windowsI386Builtins = []string{
|
||||
"i386/chkstk.S", // also _alloca
|
||||
}
|
||||
|
||||
// libCompilerRT is a library with symbols required by programs compiled with
|
||||
// LLVM. These symbols are for operations that cannot be emitted with a single
|
||||
// instruction or a short sequence of instructions for that target.
|
||||
@@ -229,6 +235,10 @@ var libCompilerRT = Library{
|
||||
builtins = append(builtins, avrBuiltins...)
|
||||
case "x86_64", "aarch64", "riscv64": // any 64-bit arch
|
||||
builtins = append(builtins, genericBuiltins128...)
|
||||
case "i386":
|
||||
if strings.Split(target, "-")[2] == "windows" {
|
||||
builtins = append(builtins, windowsI386Builtins...)
|
||||
}
|
||||
}
|
||||
return builtins, nil
|
||||
},
|
||||
|
||||
+83
-32
@@ -30,25 +30,62 @@ var libMinGW = Library{
|
||||
sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/mingw-w64") },
|
||||
cflags: func(target, headerPath string) []string {
|
||||
mingwDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib/mingw-w64")
|
||||
return []string{
|
||||
flags := []string{
|
||||
"-nostdlibinc",
|
||||
"-isystem", mingwDir + "/mingw-w64-crt/include",
|
||||
"-isystem", mingwDir + "/mingw-w64-headers/crt",
|
||||
"-isystem", mingwDir + "/mingw-w64-headers/include",
|
||||
"-I", mingwDir + "/mingw-w64-headers/defaults/include",
|
||||
"-I" + headerPath,
|
||||
}
|
||||
if strings.Split(target, "-")[0] == "i386" {
|
||||
flags = append(flags,
|
||||
"-D__MSVCRT_VERSION__=0x700", // Microsoft Visual C++ .NET 2002
|
||||
"-D_WIN32_WINNT=0x0501", // target Windows XP
|
||||
"-D_CRTBLD",
|
||||
"-Wno-pragma-pack",
|
||||
)
|
||||
}
|
||||
return flags
|
||||
},
|
||||
librarySources: func(target string) ([]string, error) {
|
||||
// These files are needed so that printf and the like are supported.
|
||||
sources := []string{
|
||||
"mingw-w64-crt/stdio/ucrt_fprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_fwprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_printf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_snprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_sprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_vfprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_vprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_vsnprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_vsprintf.c",
|
||||
var sources []string
|
||||
if strings.Split(target, "-")[0] == "i386" {
|
||||
// Old 32-bit x86 systems use msvcrt.dll.
|
||||
sources = []string{
|
||||
"mingw-w64-crt/crt/pseudo-reloc.c",
|
||||
"mingw-w64-crt/gdtoa/dmisc.c",
|
||||
"mingw-w64-crt/gdtoa/gdtoa.c",
|
||||
"mingw-w64-crt/gdtoa/gmisc.c",
|
||||
"mingw-w64-crt/gdtoa/misc.c",
|
||||
"mingw-w64-crt/math/x86/exp2.S",
|
||||
"mingw-w64-crt/math/x86/trunc.S",
|
||||
"mingw-w64-crt/misc/___mb_cur_max_func.c",
|
||||
"mingw-w64-crt/misc/lc_locale_func.c",
|
||||
"mingw-w64-crt/misc/mbrtowc.c",
|
||||
"mingw-w64-crt/misc/strnlen.c",
|
||||
"mingw-w64-crt/misc/wcrtomb.c",
|
||||
"mingw-w64-crt/misc/wcsnlen.c",
|
||||
"mingw-w64-crt/stdio/acrt_iob_func.c",
|
||||
"mingw-w64-crt/stdio/mingw_lock.c",
|
||||
"mingw-w64-crt/stdio/mingw_pformat.c",
|
||||
"mingw-w64-crt/stdio/mingw_vfprintf.c",
|
||||
"mingw-w64-crt/stdio/mingw_vsnprintf.c",
|
||||
}
|
||||
} else {
|
||||
// Anything somewhat modern (amd64, arm64) uses UCRT.
|
||||
sources = []string{
|
||||
"mingw-w64-crt/stdio/ucrt_fprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_fwprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_printf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_snprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_sprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_vfprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_vprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_vsnprintf.c",
|
||||
"mingw-w64-crt/stdio/ucrt_vsprintf.c",
|
||||
}
|
||||
}
|
||||
return sources, nil
|
||||
},
|
||||
@@ -63,27 +100,41 @@ var libMinGW = Library{
|
||||
func makeMinGWExtraLibs(tmpdir, goarch string) []*compileJob {
|
||||
var jobs []*compileJob
|
||||
root := goenv.Get("TINYGOROOT")
|
||||
// Normally all the api-ms-win-crt-*.def files are all compiled to a single
|
||||
// .lib file. But to simplify things, we're going to leave them as separate
|
||||
// files.
|
||||
for _, name := range []string{
|
||||
"kernel32.def.in",
|
||||
"api-ms-win-crt-conio-l1-1-0.def",
|
||||
"api-ms-win-crt-convert-l1-1-0.def.in",
|
||||
"api-ms-win-crt-environment-l1-1-0.def",
|
||||
"api-ms-win-crt-filesystem-l1-1-0.def",
|
||||
"api-ms-win-crt-heap-l1-1-0.def",
|
||||
"api-ms-win-crt-locale-l1-1-0.def",
|
||||
"api-ms-win-crt-math-l1-1-0.def.in",
|
||||
"api-ms-win-crt-multibyte-l1-1-0.def",
|
||||
"api-ms-win-crt-private-l1-1-0.def.in",
|
||||
"api-ms-win-crt-process-l1-1-0.def",
|
||||
"api-ms-win-crt-runtime-l1-1-0.def.in",
|
||||
"api-ms-win-crt-stdio-l1-1-0.def",
|
||||
"api-ms-win-crt-string-l1-1-0.def",
|
||||
"api-ms-win-crt-time-l1-1-0.def",
|
||||
"api-ms-win-crt-utility-l1-1-0.def",
|
||||
} {
|
||||
var libs []string
|
||||
if goarch == "386" {
|
||||
libs = []string{
|
||||
// x86 uses msvcrt.dll instead of UCRT for compatibility with old
|
||||
// Windows versions.
|
||||
"advapi32.def.in",
|
||||
"kernel32.def.in",
|
||||
"msvcrt.def.in",
|
||||
}
|
||||
} else {
|
||||
// Use the modernized UCRT on new systems.
|
||||
// Normally all the api-ms-win-crt-*.def files are all compiled to a
|
||||
// single .lib file. But to simplify things, we're going to leave them
|
||||
// as separate files.
|
||||
libs = []string{
|
||||
"advapi32.def.in",
|
||||
"kernel32.def.in",
|
||||
"api-ms-win-crt-conio-l1-1-0.def",
|
||||
"api-ms-win-crt-convert-l1-1-0.def.in",
|
||||
"api-ms-win-crt-environment-l1-1-0.def",
|
||||
"api-ms-win-crt-filesystem-l1-1-0.def",
|
||||
"api-ms-win-crt-heap-l1-1-0.def",
|
||||
"api-ms-win-crt-locale-l1-1-0.def",
|
||||
"api-ms-win-crt-math-l1-1-0.def.in",
|
||||
"api-ms-win-crt-multibyte-l1-1-0.def",
|
||||
"api-ms-win-crt-private-l1-1-0.def.in",
|
||||
"api-ms-win-crt-process-l1-1-0.def",
|
||||
"api-ms-win-crt-runtime-l1-1-0.def.in",
|
||||
"api-ms-win-crt-stdio-l1-1-0.def",
|
||||
"api-ms-win-crt-string-l1-1-0.def",
|
||||
"api-ms-win-crt-time-l1-1-0.def",
|
||||
"api-ms-win-crt-utility-l1-1-0.def",
|
||||
}
|
||||
}
|
||||
for _, name := range libs {
|
||||
outpath := filepath.Join(tmpdir, filepath.Base(name)+".lib")
|
||||
inpath := filepath.Join(root, "lib/mingw-w64/mingw-w64-crt/lib-common/"+name)
|
||||
job := &compileJob{
|
||||
|
||||
Reference in New Issue
Block a user