Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 785ad9d

Browse files
committed
Add compatibility scheme to allow binaries compiled for msvc versions < 18 to link against msvc 18 generated libraries
1 parent c16bde6 commit 785ad9d

8 files changed

Lines changed: 338 additions & 8 deletions

File tree

build-tool/BuildCommon.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262

6363
<include name="${toolchain}-toolchain.xml"/>
6464

65+
<section if="static_link" >
66+
<set name="MSVC_LIB_VERSION" value="-${MSVC_VER}" if="windows" />
67+
</section>
68+
69+
70+
6571

6672
<!-- Library files & targets -------------------------------------->
6773

build-tool/haxe/BuildTool.hx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,46 @@ class Linker
436436
args = args.concat(mFlags).concat(inTarget.mFlags);
437437

438438
var libs = inTarget.mLibs.concat(mLibs);
439+
var v18Added = false;
440+
for(i in 0...libs.length)
441+
{
442+
var lib = libs[i];
443+
var parts = lib.split("{MSVC_VER}");
444+
if (parts.length==2)
445+
{
446+
var ver = "";
447+
if (BuildTool.isWindows)
448+
{
449+
var current = parts[0] + "-" + BuildTool.getMsvcVer() + parts[1];
450+
if (FileSystem.exists(current))
451+
{
452+
BuildTool.log("Using current compiler library " + current);
453+
libs[i]=current;
454+
}
455+
else
456+
{
457+
var v18 = parts[0] + "-18" + parts[1];
458+
if (FileSystem.exists(v18))
459+
{
460+
BuildTool.log("Using msvc18 compatible library " + v18);
461+
libs[i]=v18;
462+
if (!v18Added)
463+
{
464+
v18Added=true;
465+
libs.push( BuildTool.HXCPP + "/lib/Windows/libmsvccompat-18.lib");
466+
}
467+
}
468+
else
469+
{
470+
throw "Could not find compatible library for " + lib;
471+
}
472+
}
473+
}
474+
else
475+
libs[i] = parts[0] + parts[1];
476+
}
477+
}
478+
439479
var objs = inObjs.copy();
440480

441481
if (mExpandArchives)
@@ -881,6 +921,7 @@ class BuildTool
881921
public static var compileCache:String;
882922
public static var targetKey:String;
883923
public static var helperThread = new Tls<Thread>();
924+
public static var instance:BuildTool;
884925
static var printMutex:Mutex;
885926

886927

@@ -895,6 +936,7 @@ class BuildTool
895936
mTargets = new Targets();
896937
mLinkers = new Linkers();
897938
mIncludePath = inIncludePath;
939+
instance = this;
898940
var make_contents = "";
899941
try {
900942
make_contents = sys.io.File.getContent(inMakefile);
@@ -956,6 +998,11 @@ class BuildTool
956998
buildTarget(target);
957999
}
9581000

1001+
static public function getMsvcVer()
1002+
{
1003+
return instance.mDefines.get("MSVC_VER");
1004+
}
1005+
9591006
inline public static function log(s:String)
9601007
{
9611008
if (verbose)

build-tool/msvc-toolchain.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
<flag value="-I${HXCPP}/include"/>
6262
<include name="common-defines.xml" />
6363
<flag value="-D_CRT_SECURE_NO_DEPRECATE"/>
64+
<flag value="-D_ALLOW_MSC_VER_MISMATCH"/>
65+
<flag value="-D_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH"/>
6466
<flag value="-DHX_WIN_MAIN" if="SUBSYSTEMWINDOWS" />
6567
<flag value="-wd4996"/>
6668
<outflag value="-Fo"/>

run.n

447 Bytes
Binary file not shown.

runtime/BuildLibs.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@
144144

145145

146146

147+
<files id="msvccompat" >
148+
<file name="StlLink.cpp"/>
149+
</files>
150+
151+
152+
<target id="msvccompat" output="${LIBPREFIX}msvccompat${DBG}-${MSVC_VER}${LIBEXTRA}" tool="linker" toolid="${STD_MODULE_LINK}">
153+
<files id="msvccompat"/>
154+
<builddir name="libs/msvccompat"/>
155+
<outdir name="../../../${DESTDIR}/${BINDIR}"/>
156+
</target>
157+
158+
159+
147160

148161
<files id="nekoapi" >
149162
<depend name="libs/nekoapi/neko.h"/>
@@ -177,6 +190,9 @@
177190
<target id="zlib"/>
178191
<target id="mysql"/>
179192
<target id="sqlite"/>
193+
<section if="static_link">
194+
<target id="msvccompat" if="windows" />
195+
</section>
180196
<section unless="static_link">
181197
<target id="nekoapi" if="windows" unless="HXCPP_M64"/>
182198
<target id="nekoapi" if="macos" />
Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
#ifdef _MSC_VER
2+
3+
4+
5+
#if _MSC_VER>=1800 && _MSC_VER<1900
6+
7+
#include <stdexcept>
8+
#include <cstdlib>
9+
#include <system_error>
10+
#pragma warning(disable: 4005)
11+
#include <windows.h>
12+
13+
namespace std
14+
{
15+
16+
_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xbad_alloc())
17+
{ // report a bad_alloc error
18+
_THROW_NCEE(_XSTD bad_alloc, _EMPTY_ARGUMENT);
19+
20+
}
21+
22+
_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xinvalid_argument(_In_z_ const char *_Message))
23+
{ // report an invalid_argument error
24+
_THROW_NCEE(invalid_argument, _Message);
25+
}
26+
27+
_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xlength_error(_In_z_ const char *_Message))
28+
{ // report a length_error
29+
_THROW_NCEE(length_error, _Message);
30+
}
31+
32+
_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xout_of_range(_In_z_ const char *_Message))
33+
{ // report an out_of_range error
34+
_THROW_NCEE(out_of_range, _Message);
35+
}
36+
37+
_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xoverflow_error(_In_z_ const char *_Message))
38+
{ // report an overflow error
39+
_THROW_NCEE(overflow_error, _Message);
40+
}
41+
42+
_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xruntime_error(_In_z_ const char *_Message))
43+
{ // report a runtime_error
44+
_THROW_NCEE(runtime_error, _Message);
45+
}
46+
47+
48+
49+
50+
struct _Win_errtab_t
51+
{ // maps Windows error_code to NTBS
52+
int _Errcode;
53+
const char *_Name;
54+
};
55+
56+
static const _Win_errtab_t _Win_errtab[] =
57+
{ // table of Windows code/name pairs
58+
ERROR_ACCESS_DENIED, "permission denied",
59+
ERROR_ALREADY_EXISTS, "file exists",
60+
ERROR_BAD_UNIT, "no such device",
61+
ERROR_BUFFER_OVERFLOW, "filename too long",
62+
ERROR_BUSY, "device or resource busy",
63+
ERROR_BUSY_DRIVE, "device or resource busy",
64+
ERROR_CANNOT_MAKE, "permission denied",
65+
ERROR_CANTOPEN, "io error",
66+
ERROR_CANTREAD, "io error",
67+
ERROR_CANTWRITE, "io error",
68+
ERROR_CURRENT_DIRECTORY, "permission denied",
69+
ERROR_DEV_NOT_EXIST, "no such device",
70+
ERROR_DEVICE_IN_USE, "device or resource busy",
71+
ERROR_DIR_NOT_EMPTY, "directory not empty",
72+
ERROR_DIRECTORY, "invalid argument",
73+
ERROR_DISK_FULL, "no space on device",
74+
ERROR_FILE_EXISTS, "file exists",
75+
ERROR_FILE_NOT_FOUND, "no such file or directory",
76+
ERROR_HANDLE_DISK_FULL, "no space on device",
77+
ERROR_INVALID_ACCESS, "permission denied",
78+
ERROR_INVALID_DRIVE, "no such device",
79+
ERROR_INVALID_FUNCTION, "function not supported",
80+
ERROR_INVALID_HANDLE, "invalid argument",
81+
ERROR_INVALID_NAME, "invalid argument",
82+
ERROR_LOCK_VIOLATION, "no lock available",
83+
ERROR_LOCKED, "no lock available",
84+
ERROR_NEGATIVE_SEEK, "invalid argument",
85+
ERROR_NOACCESS, "permission denied",
86+
ERROR_NOT_ENOUGH_MEMORY, "not enough memory",
87+
ERROR_NOT_READY, "resource unavailable try again",
88+
ERROR_NOT_SAME_DEVICE, "cross device link",
89+
ERROR_OPEN_FAILED, "io error",
90+
ERROR_OPEN_FILES, "device or resource busy",
91+
ERROR_OPERATION_ABORTED, "operation canceled",
92+
ERROR_OUTOFMEMORY, "not enough memory",
93+
ERROR_PATH_NOT_FOUND, "no such file or directory",
94+
ERROR_READ_FAULT, "io error",
95+
ERROR_RETRY, "resource unavailable try again",
96+
ERROR_SEEK, "io error",
97+
ERROR_SHARING_VIOLATION, "permission denied",
98+
ERROR_TOO_MANY_OPEN_FILES, "too many files open",
99+
ERROR_WRITE_FAULT, "io error",
100+
ERROR_WRITE_PROTECT, "permission denied",
101+
WSAEACCES, "permission_denied",
102+
WSAEADDRINUSE, "address_in_use",
103+
WSAEADDRNOTAVAIL, "address_not_available",
104+
WSAEAFNOSUPPORT, "address_family_not_supported",
105+
WSAEALREADY, "connection_already_in_progress",
106+
WSAEBADF, "bad_file_descriptor",
107+
WSAECONNABORTED, "connection_aborted",
108+
WSAECONNREFUSED, "connection_refused",
109+
WSAECONNRESET, "connection_reset",
110+
WSAEDESTADDRREQ, "destination_address_required",
111+
WSAEFAULT, "bad_address",
112+
WSAEHOSTUNREACH, "host_unreachable",
113+
WSAEINPROGRESS, "operation_in_progress",
114+
WSAEINTR, "interrupted",
115+
WSAEINVAL, "invalid_argument",
116+
WSAEISCONN, "already_connected",
117+
WSAEMFILE, "too_many_files_open",
118+
WSAEMSGSIZE, "message_size",
119+
WSAENAMETOOLONG, "filename_too_long",
120+
WSAENETDOWN, "network_down",
121+
WSAENETRESET, "network_reset",
122+
WSAENETUNREACH, "network_unreachable",
123+
WSAENOBUFS, "no_buffer_space",
124+
WSAENOPROTOOPT, "no_protocol_option",
125+
WSAENOTCONN, "not_connected",
126+
WSAENOTSOCK, "not_a_socket",
127+
WSAEOPNOTSUPP, "operation_not_supported",
128+
WSAEPROTONOSUPPORT, "protocol_not_supported",
129+
WSAEPROTOTYPE, "wrong_protocol_type",
130+
WSAETIMEDOUT, "timed_out",
131+
WSAEWOULDBLOCK, "operation_would_block",
132+
0, 0
133+
};
134+
135+
const char *_Winerror_map(int _Errcode)
136+
{ // convert to name of Windows error
137+
const _Win_errtab_t *_Ptr = &_Win_errtab[0];
138+
for (; _Ptr->_Name != 0; ++_Ptr)
139+
if ((int)_Ptr->_Errcode == _Errcode)
140+
return (_Ptr->_Name);
141+
return (0);
142+
}
143+
144+
struct _Sys_errtab_t
145+
{ // maps error_code to NTBS
146+
generic_errno _Errcode;
147+
const char *_Name;
148+
};
149+
150+
static const _Sys_errtab_t _Sys_errtab[] =
151+
{ // table of Posix code/name pairs
152+
errc::address_family_not_supported, "address family not supported",
153+
errc::address_in_use, "address in use",
154+
errc::address_not_available, "address not available",
155+
errc::already_connected, "already connected",
156+
errc::argument_list_too_long, "argument list too long",
157+
errc::argument_out_of_domain, "argument out of domain",
158+
errc::bad_address, "bad address",
159+
errc::bad_file_descriptor, "bad file descriptor",
160+
errc::bad_message, "bad message",
161+
errc::broken_pipe, "broken pipe",
162+
errc::connection_aborted, "connection aborted",
163+
errc::connection_already_in_progress, "connection already in progress",
164+
errc::connection_refused, "connection refused",
165+
errc::connection_reset, "connection reset",
166+
errc::cross_device_link, "cross device link",
167+
errc::destination_address_required, "destination address required",
168+
errc::device_or_resource_busy, "device or resource busy",
169+
errc::directory_not_empty, "directory not empty",
170+
errc::executable_format_error, "executable format error",
171+
errc::file_exists, "file exists",
172+
errc::file_too_large, "file too large",
173+
errc::filename_too_long, "filename too long",
174+
errc::function_not_supported, "function not supported",
175+
errc::host_unreachable, "host unreachable",
176+
errc::identifier_removed, "identifier removed",
177+
errc::illegal_byte_sequence, "illegal byte sequence",
178+
errc::inappropriate_io_control_operation,
179+
"inappropriate io control operation",
180+
errc::interrupted, "interrupted",
181+
errc::invalid_argument, "invalid argument",
182+
errc::invalid_seek, "invalid seek",
183+
errc::io_error, "io error",
184+
errc::is_a_directory, "is a directory",
185+
errc::message_size, "message size",
186+
errc::network_down, "network down",
187+
errc::network_reset, "network reset",
188+
errc::network_unreachable, "network unreachable",
189+
errc::no_buffer_space, "no buffer space",
190+
errc::no_child_process, "no child process",
191+
errc::no_link, "no link",
192+
errc::no_lock_available, "no lock available",
193+
errc::no_message_available, "no message available",
194+
errc::no_message, "no message",
195+
errc::no_protocol_option, "no protocol option",
196+
errc::no_space_on_device, "no space on device",
197+
errc::no_stream_resources, "no stream resources",
198+
errc::no_such_device_or_address, "no such device or address",
199+
errc::no_such_device, "no such device",
200+
errc::no_such_file_or_directory, "no such file or directory",
201+
errc::no_such_process, "no such process",
202+
errc::not_a_directory, "not a directory",
203+
errc::not_a_socket, "not a socket",
204+
errc::not_a_stream, "not a stream",
205+
errc::not_connected, "not connected",
206+
errc::not_enough_memory, "not enough memory",
207+
errc::not_supported, "not supported",
208+
errc::operation_canceled, "operation canceled",
209+
errc::operation_in_progress, "operation in progress",
210+
errc::operation_not_permitted, "operation not permitted",
211+
errc::operation_not_supported, "operation not supported",
212+
errc::operation_would_block, "operation would block",
213+
errc::owner_dead, "owner dead",
214+
errc::permission_denied, "permission denied",
215+
errc::protocol_error, "protocol error",
216+
errc::protocol_not_supported, "protocol not supported",
217+
errc::read_only_file_system, "read only file system",
218+
errc::resource_deadlock_would_occur, "resource deadlock would occur",
219+
errc::resource_unavailable_try_again, "resource unavailable try again",
220+
errc::result_out_of_range, "result out of range",
221+
errc::state_not_recoverable, "state not recoverable",
222+
errc::stream_timeout, "stream timeout",
223+
errc::text_file_busy, "text file busy",
224+
errc::timed_out, "timed out",
225+
errc::too_many_files_open_in_system, "too many files open in system",
226+
errc::too_many_files_open, "too many files open",
227+
errc::too_many_links, "too many links",
228+
errc::too_many_symbolic_link_levels, "too many symbolic link levels",
229+
errc::value_too_large, "value too large",
230+
errc::wrong_protocol_type, "wrong protocol type",
231+
(generic_errno)0, 0
232+
};
233+
234+
const char *__cdecl _Syserror_map(int _Errcode)
235+
{ // convert to name of generic error
236+
const _Sys_errtab_t *_Ptr = &_Sys_errtab[0];
237+
for (; _Ptr->_Name != 0; ++_Ptr)
238+
if ((int)_Ptr->_Errcode == _Errcode)
239+
return (_Ptr->_Name);
240+
return (0);
241+
}
242+
}
243+
#endif
244+
245+
246+
#endif

0 commit comments

Comments
 (0)