Store the target architecture for CL-like compilers

Store the MSVC compiler target architecture ('x86', 'x64' or 'ARM' (this
is ARM64, I believe)), rather than just if it's x64 or not.

The regex used for target architecture should be ok, based on this list
of [1] version outputs, but we assume x86 if no match, for safety's
sake.

[1] https://stackoverflow.com/a/1233332/1951600

Also detect arch even if cl outputs version to stdout.

Ditto for clang-cl

Future work: is_64 is now only used in get_instruction_set_args()
pull/4451/head
Jon Turney 6 years ago
parent 4db1b3a09f
commit a872b925ea
No known key found for this signature in database
GPG Key ID: C7C86F0370285C81
  1. 9
      mesonbuild/compilers/c.py
  2. 8
      mesonbuild/compilers/cpp.py
  3. 27
      mesonbuild/environment.py

@ -1290,7 +1290,7 @@ class VisualStudioCCompiler(CCompiler):
'mtd': ['/MTd'],
}
def __init__(self, exelist, version, is_cross, exe_wrap, is_64):
def __init__(self, exelist, version, is_cross, exe_wrap, target):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
self.id = 'msvc'
# /showIncludes is needed for build dependency tracking in Ninja
@ -1300,7 +1300,8 @@ class VisualStudioCCompiler(CCompiler):
'2': ['/W3'],
'3': ['/W4']}
self.base_options = ['b_pch', 'b_ndebug', 'b_vscrt'] # FIXME add lto, pgo and the like
self.is_64 = is_64
self.target = target
self.is_64 = ('x64' in target) or ('x86_64' in target)
# Override CCompiler.get_always_args
def get_always_args(self):
@ -1588,8 +1589,8 @@ class VisualStudioCCompiler(CCompiler):
class ClangClCCompiler(VisualStudioCCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap, is_64):
super().__init__(exelist, version, is_cross, exe_wrap, is_64)
def __init__(self, exelist, version, is_cross, exe_wrap, target):
super().__init__(exelist, version, is_cross, exe_wrap, target)
self.id = 'clang-cl'

@ -308,9 +308,9 @@ class IntelCPPCompiler(IntelCompiler, CPPCompiler):
class VisualStudioCPPCompiler(VisualStudioCCompiler, CPPCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap, is_64):
def __init__(self, exelist, version, is_cross, exe_wrap, target):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
VisualStudioCCompiler.__init__(self, exelist, version, is_cross, exe_wrap, is_64)
VisualStudioCCompiler.__init__(self, exelist, version, is_cross, exe_wrap, target)
self.base_options = ['b_pch', 'b_vscrt'] # FIXME add lto, pgo and the like
def get_options(self):
@ -387,8 +387,8 @@ class VisualStudioCPPCompiler(VisualStudioCCompiler, CPPCompiler):
return VisualStudioCCompiler.get_compiler_check_args(self)
class ClangClCPPCompiler(VisualStudioCPPCompiler, ClangClCCompiler):
def __init__(self, exelist, version, is_cross, exe_wrap, is_64):
VisualStudioCPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, is_64)
def __init__(self, exelist, version, is_cross, exe_wrap, target):
VisualStudioCPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, target)
self.id = 'clang-cl'
class ArmCPPCompiler(ArmCompiler, CPPCompiler):

@ -659,9 +659,13 @@ class Environment:
except OSError as e:
popen_exceptions[' '.join(compiler + [arg])] = e
version = search_version(out)
is_64 = 'Target: x86_64' in out
match = re.search('^Target: (.*?)-', out, re.MULTILINE)
if match:
target = match.group(1)
else:
target = 'unknown target'
cls = ClangClCCompiler if lang == 'c' else ClangClCPPCompiler
return cls(compiler, version, is_cross, exe_wrap, is_64)
return cls(compiler, version, is_cross, exe_wrap, target)
if 'clang' in out:
if 'Apple' in out or mesonlib.for_darwin(want_cross, self):
compiler_type = CompilerType.CLANG_OSX
@ -676,15 +680,20 @@ class Environment:
# number to stderr but earlier ones print version
# on stdout. Why? Lord only knows.
# Check both outputs to figure out version.
version = search_version(err)
if version == 'unknown version':
version = search_version(out)
if version == 'unknown version':
m = 'Failed to detect MSVC compiler arch: stderr was\n{!r}'
for lookat in [err, out]:
version = search_version(lookat)
if version != 'unknown version':
break
else:
m = 'Failed to detect MSVC compiler version: stderr was\n{!r}'
raise EnvironmentException(m.format(err))
is_64 = err.split('\n')[0].endswith(' x64')
match = re.search(' for (.*)$', lookat.split('\n')[0])
if match:
target = match.group(1)
else:
target = 'x86'
cls = VisualStudioCCompiler if lang == 'c' else VisualStudioCPPCompiler
return cls(compiler, version, is_cross, exe_wrap, is_64)
return cls(compiler, version, is_cross, exe_wrap, target)
if '(ICC)' in out:
if mesonlib.for_darwin(want_cross, self):
compiler_type = CompilerType.ICC_OSX

Loading…
Cancel
Save