Skip to content

Commit

Permalink
Merge pull request #189 from t20100/fix-march-native
Browse files Browse the repository at this point in the history
Build: Added check of native flags availability
  • Loading branch information
vasole authored Oct 19, 2022
2 parents 6c7d82b + 59c7183 commit 5958162
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def get_tag(self):

# Probe host capabilities and manage build config

def check_compile_flag(compiler, flag, extension='.c'):
def check_compile_flags(compiler, *flags, extension='.c'):
"""Try to compile an empty file to check for compiler args
:param distutils.ccompiler.CCompiler compiler: The compiler to use
:param str flag: Flag argument to pass to compiler
:param flags: Flags argument to pass to compiler
:param str extension: Source file extension (default: '.c')
:returns: Whether or not compilation was successful
:rtype: bool
Expand All @@ -103,7 +103,7 @@ def check_compile_flag(compiler, flag, extension='.c'):
f.write('int main (int argc, char **argv) { return 0; }\n')

try:
compiler.compile([tmp_file], output_dir=tmp_dir, extra_postargs=[flag])
compiler.compile([tmp_file], output_dir=tmp_dir, extra_postargs=list(flags))
except errors.CompileError:
return False
else:
Expand Down Expand Up @@ -171,15 +171,15 @@ def has_cpp11(self) -> bool:
"""Check C++11 availability on host"""
if self.__compiler.compiler_type == 'msvc':
return sys.version_info[:2] >= (3, 5)
return check_compile_flag(self.__compiler, '-std=c++11', extension='.cc')
return check_compile_flags(self.__compiler, '-std=c++11', extension='.cc')

def has_sse2(self) -> bool:
"""Check SSE2 availability on host"""
if self.arch in ('X86_32', 'X86_64'):
if not has_cpu_flag('sse2'):
return False # SSE2 not available on host
return (self.__compiler.compiler_type == 'msvc' or
check_compile_flag(self.__compiler, '-msse2'))
check_compile_flags(self.__compiler, '-msse2'))
if self.machine == 'ppc64le':
return True
return False # Disabled by default
Expand All @@ -191,19 +191,21 @@ def has_avx2(self) -> bool:
return False # AVX2 not available on host
if self.__compiler.compiler_type == 'msvc':
return sys.version_info[:2] >= (3, 5)
return check_compile_flag(self.__compiler, '-mavx2')
return check_compile_flags(self.__compiler, '-mavx2')
return False # Disabled by default

def has_openmp(self) -> bool:
"""Check OpenMP availability on host"""
if sys.platform.startswith('darwin'):
return False
prefix = '/' if self.__compiler.compiler_type == 'msvc' else '-f'
return check_compile_flag(self.__compiler, prefix + 'openmp')
return check_compile_flags(self.__compiler, prefix + 'openmp')

def has_native(self) -> bool:
"""Returns native build option availability on host"""
return len(self.native_compile_args) > 0
if len(self.native_compile_args) > 0:
return check_compile_flags(self.__compiler, *self.native_compile_args)
return False


class BuildConfig:
Expand Down

0 comments on commit 5958162

Please sign in to comment.