Skip to content

Commit bfd26a7

Browse files
committed
msvc compatibility
1 parent 302f2f6 commit bfd26a7

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

build/ninja/msvc.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def initialize(self, project, archs, configs, includepaths, dependlibs, libpaths
3131
self.linkcmd = '$toolchain$link $libpaths $configlibpaths $linkflags $linkarchflags $linkconfigflags /DEBUG /NOLOGO /SUBSYSTEM:CONSOLE /DYNAMICBASE /NXCOMPAT /MANIFEST /MANIFESTUAC:\"level=\'asInvoker\' uiAccess=\'false\'\" /TLBID:1 /PDB:$pdbpath /OUT:$out $in $libs $archlibs $oslibs'
3232
self.dllcmd = self.linkcmd + ' /DLL'
3333

34-
self.cflags = ['/D', '"' + project.upper() + '_COMPILE=1"', '/D', '"_UNICODE"', '/D', '"UNICODE"', '/Zi', '/Oi', '/Oy-', '/GS-', '/Gy-', '/Qpar-', '/fp:fast', '/fp:except-', '/Zc:forScope', '/Zc:wchar_t', '/GR-', '/openmp-']
35-
self.cwarnflags = ['/W4', '/WX']
34+
self.cflags = ['/D', '"' + project.upper() + '_COMPILE=1"', '/D', '"_UNICODE"', '/D', '"UNICODE"', '/std:c17', '/Zi', '/Oi', '/Oy-', '/GS-', '/Gy-', '/Qpar-', '/fp:fast', '/fp:except-', '/Zc:forScope', '/Zc:wchar_t', '/GR-', '/openmp-']
35+
self.cwarnflags = ['/W4', '/WX', '/wd4201'] #Ignore nameless union/struct which is allowed in C11
3636
self.cmoreflags = []
3737
self.arflags = ['/ignore:4221'] #Ignore empty object file warning]
3838
self.linkflags = ['/DEBUG']
@@ -138,10 +138,11 @@ def build_toolchain(self):
138138
tools_list.sort(key=StrictVersion)
139139
self.toolchain = os.path.join(tools_basepath, tools_list[-1])
140140
self.toolchain_version = major_version + ".0"
141+
break
141142

142143
if self.toolchain == '':
143144
toolchain = ''
144-
versions = ['16.0', '15.0', '14.0', '13.0', '12.0', '11.0', '10.0']
145+
versions = ['17.0', '16.0', '15.0']
145146
keys = [
146147
'HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VC7',
147148
'HKCU\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VC7',
@@ -161,12 +162,11 @@ def build_toolchain(self):
161162
except:
162163
continue
163164
if not toolchain == '':
164-
if version == '15.0' or version == '16.0':
165-
tools_basepath = os.path.join(toolchain, 'VC', 'Tools', 'MSVC')
166-
tools_list = [item for item in os.listdir(tools_basepath) if os.path.isdir(os.path.join(tools_basepath, item))]
167-
from distutils.version import StrictVersion
168-
tools_list.sort(key=StrictVersion)
169-
toolchain = os.path.join(tools_basepath, tools_list[-1])
165+
tools_basepath = os.path.join(toolchain, 'VC', 'Tools', 'MSVC')
166+
tools_list = [item for item in os.listdir(tools_basepath) if os.path.isdir(os.path.join(tools_basepath, item))]
167+
from distutils.version import StrictVersion
168+
tools_list.sort(key=StrictVersion)
169+
toolchain = os.path.join(tools_basepath, tools_list[-1])
170170
self.toolchain = toolchain
171171
self.toolchain_version = version
172172
break
@@ -239,13 +239,10 @@ def make_libpaths(self, libpaths):
239239
return []
240240

241241
def make_arch_toolchain_path(self, arch):
242-
if self.toolchain_version == '15.0' or self.toolchain_version == '16.0':
243-
if arch == 'x86-64':
244-
return os.path.join(self.toolchain, 'bin', 'HostX64', 'x64\\')
245-
elif arch == 'x86':
246-
return os.path.join(self.toolchain, 'bin', 'HostX64', 'x86\\')
247242
if arch == 'x86-64':
248-
return os.path.join(self.toolchain, 'bin', 'amd64\\')
243+
return os.path.join(self.toolchain, 'bin', 'HostX64', 'x64\\')
244+
elif arch == 'x86':
245+
return os.path.join(self.toolchain, 'bin', 'HostX64', 'x86\\')
249246
return os.path.join(self.toolchain, 'bin\\')
250247

251248
def make_carchflags(self, arch, targettype):
@@ -323,20 +320,14 @@ def make_configlibpaths(self, config, arch, extralibpaths):
323320
libpaths += [os.path.join(libpath, self.libpath, config, arch) for libpath in extralibpaths]
324321
if self.sdkpath != '':
325322
if arch == 'x86':
326-
if self.toolchain_version == '15.0' or self.toolchain_version == '16.0':
327-
libpaths += [os.path.join(self.toolchain, 'lib', 'x86')]
328-
else:
329-
libpaths += [os.path.join(self.toolchain, 'lib')]
323+
libpaths += [os.path.join(self.toolchain, 'lib', 'x86')]
330324
if self.sdkversion == 'v8.1':
331325
libpaths += [os.path.join( self.sdkpath, 'lib', 'winv6.3', 'um', 'x86')]
332326
if self.sdkversion == 'v10.0':
333327
libpaths += [os.path.join(self.sdkpath, 'lib', self.sdkversionpath, 'um', 'x86')]
334328
libpaths += [os.path.join(self.sdkpath, 'lib', self.sdkversionpath, 'ucrt', 'x86')]
335329
else:
336-
if self.toolchain_version == '15.0' or self.toolchain_version == '16.0':
337-
libpaths += [os.path.join( self.toolchain, 'lib', 'x64')]
338-
else:
339-
libpaths += [os.path.join( self.toolchain, 'lib', 'amd64')]
330+
libpaths += [os.path.join( self.toolchain, 'lib', 'x64')]
340331
if self.sdkversion == 'v8.1':
341332
libpaths += [os.path.join( self.sdkpath, 'lib', 'winv6.3', 'um', 'x64')]
342333
if self.sdkversion == 'v10.0':

build/ninja/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def generate_version_string(libname):
1515
if sys.platform.startswith('win'):
1616
gitcmd = 'git.exe'
1717
try:
18-
git_version = subprocess.check_output( [ gitcmd, 'describe', '--long' ], stderr = subprocess.STDOUT ).strip()
18+
git_version = subprocess.check_output( [ gitcmd, 'describe', '--tags', '--long' ], stderr = subprocess.STDOUT ).strip()
1919
tokens = git_version.decode().split( '-' )
2020
version_numbers = tokens[0].split( '.' )
2121
except Exception:

build/ninja/vslocate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class ISetupConfiguration(ctypes.Structure):
115115
enum_setup_instances = ctypes.POINTER(IEnumSetupInstances)()
116116
result = enum_instances(configuration, ctypes.byref(enum_setup_instances))
117117
if result != 0:
118-
#print("Failed to enum setup instances: " + str(result))
118+
#print("Failed to enum setup instances: " + str(result))
119119
return installations
120120

121121

rpmalloc/rpmalloc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110

111111
/// Platform and arch specifics
112112
#if defined(_MSC_VER) && !defined(__clang__)
113+
# pragma warning (disable: 5105)
113114
# ifndef FORCEINLINE
114115
# define FORCEINLINE inline __forceinline
115116
# endif

test/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
33
# define _CRT_SECURE_NO_WARNINGS
44
#endif
5+
#ifdef _MSC_VER
6+
# if !defined(__clang__)
7+
# pragma warning (disable: 5105)
8+
# endif
9+
#endif
510
#if defined(__clang__)
611
#pragma clang diagnostic ignored "-Wnonportable-system-include-path"
712
#endif

test/thread.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#include <errno.h>
44

55
#ifdef _MSC_VER
6+
# if !defined(__clang__)
7+
# pragma warning (disable: 5105)
8+
# endif
69
# define ATTRIBUTE_NORETURN
710
#else
811
# define ATTRIBUTE_NORETURN __attribute__((noreturn))

0 commit comments

Comments
 (0)