This commit adds code changes, compatibility functions, stubs and a build script
to build urbit binaries on MingW64. Some functionality is limited or missing:
terminal input and daemon mode is not available, graceful exit does not work,
and the binaries are not completely static and use (portable) MingW dlls.
To build the binaries, install the MSYS2 environment, check out or copy the urbit
repo and pill binaries, open a MingW64 shell and `cd pkg/urbit && ./build-mingw`.
To avoid allocating a buffer on MingW, mdb_strerror uses a horrible
stack hack which explodes in vere. Source patch replaces it with mdb_logerror
on MingW. This change adds the default implementation for other platforms.
gcc 9 and earlier default to -fcommon, i.e. linker merges identical symbols. gcc 10 defaults
to -fno-common, and the build breaks because c3_global is not defined anywhere.
In some places, _ce_patch_delete is invoked before _ce_patch_free. This works on Unix,
where an open file can be unlinked, but on Windows one must open files with an extra
flag FILE_SHARE_DELETE for this to work, and there is no way to pass this flag to open().
Vere writes the embedded CA store to a tempfile and directs libcurl and libh2o to pick it up from there,
but on MingW this is inconvenient because temp paths are different and mkstemp(3) is not available.
Loading CA store certificates directly from memory is tidier.
Most C files have multiple #includes that are duplicated in include/c/portable.h.
Removing them helps keep include-related #ifdefs in include/c/portable.h.
#including library files after all.h avoids clashes on MingW and allows portable.h
to add compatibility #defines where necessary.
The C runtime MingW relies on, msvcrt.dll, has the notion of accessing files in text and binary mode.
In text mode, it does CRLF conversion and handles some control characters, which breaks binary files.
This change adds O_BINARY in every fopen/open call and #defines it to 0 on other platforms.