Merge pull request #33177 from tchaikov/wip-clang-pybind

pybind: customize compiler before checking cflags

Reviewed-by: Mark Kogan <mkogan@redhat.com>
This commit is contained in:
Kefu Chai 2020-02-11 12:45:58 +08:00 committed by GitHub
commit ccb8d61ff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 39 deletions

View File

@ -9,20 +9,21 @@ import tempfile
import textwrap
from distutils.ccompiler import new_compiler
from distutils.errors import CompileError, LinkError
from itertools import filterfalse
from itertools import filterfalse, takewhile
import distutils.sysconfig
def filter_unsupported_flags(compiler, flags):
if 'clang' in compiler:
return filterfalse(lambda f:
f in ('-mcet',
'-fstack-clash-protection',
'-fno-var-tracking-assignments',
'-Wno-deprecated-register',
'-Wno-gnu-designator') or
f.startswith('-fcf-protection'),
flags)
args = takewhile(lambda argv: not argv.startswith('-'), [compiler] + flags)
if any('clang' in arg for arg in args):
return list(filterfalse(lambda f:
f in ('-mcet',
'-fstack-clash-protection',
'-fno-var-tracking-assignments',
'-Wno-deprecated-register',
'-Wno-gnu-designator') or
f.startswith('-fcf-protection'),
flags))
else:
return flags
@ -61,6 +62,7 @@ def get_python_flags(libs):
py_libs = sum((libs.split() for libs in
distutils.sysconfig.get_config_vars('LIBS', 'SYSLIBS')), [])
compiler = new_compiler()
distutils.sysconfig.customize_compiler(compiler)
return dict(
include_dirs=[distutils.sysconfig.get_python_inc()],
library_dirs=distutils.sysconfig.get_config_vars('LIBDIR', 'LIBPL'),

View File

@ -2,7 +2,7 @@ from __future__ import print_function
import distutils.sysconfig
from distutils.errors import CompileError, LinkError
from distutils.ccompiler import new_compiler
from itertools import filterfalse
from itertools import filterfalse, takewhile
import os
import pkgutil
@ -14,15 +14,16 @@ import textwrap
def filter_unsupported_flags(compiler, flags):
if 'clang' in compiler:
return filterfalse(lambda f:
f in ('-mcet',
'-fstack-clash-protection',
'-fno-var-tracking-assignments',
'-Wno-deprecated-register',
'-Wno-gnu-designator') or
f.startswith('-fcf-protection'),
flags)
args = takewhile(lambda argv: not argv.startswith('-'), [compiler] + flags)
if any('clang' in arg for arg in args):
return list(filterfalse(lambda f:
f in ('-mcet',
'-fstack-clash-protection',
'-fno-var-tracking-assignments',
'-Wno-deprecated-register',
'-Wno-gnu-designator') or
f.startswith('-fcf-protection'),
flags))
else:
return flags
@ -64,6 +65,7 @@ def get_python_flags(libs):
py_libs = sum((libs.split() for libs in
distutils.sysconfig.get_config_vars('LIBS', 'SYSLIBS')), [])
compiler = new_compiler()
distutils.sysconfig.customize_compiler(compiler)
return dict(
include_dirs=[distutils.sysconfig.get_python_inc()],
library_dirs=distutils.sysconfig.get_config_vars('LIBDIR', 'LIBPL'),

View File

@ -9,20 +9,21 @@ import tempfile
import textwrap
from distutils.ccompiler import new_compiler
from distutils.errors import CompileError, LinkError
from itertools import filterfalse
from itertools import filterfalse, takewhile
import distutils.sysconfig
def filter_unsupported_flags(compiler, flags):
if 'clang' in compiler:
return filterfalse(lambda f:
f in ('-mcet',
'-fstack-clash-protection',
'-fno-var-tracking-assignments',
'-Wno-deprecated-register',
'-Wno-gnu-designator') or
f.startswith('-fcf-protection'),
flags)
args = takewhile(lambda argv: not argv.startswith('-'), [compiler] + flags)
if any('clang' in arg for arg in args):
return list(filterfalse(lambda f:
f in ('-mcet',
'-fstack-clash-protection',
'-fno-var-tracking-assignments',
'-Wno-deprecated-register',
'-Wno-gnu-designator') or
f.startswith('-fcf-protection'),
flags))
else:
return flags
@ -61,6 +62,7 @@ def get_python_flags(libs):
py_libs = sum((libs.split() for libs in
distutils.sysconfig.get_config_vars('LIBS', 'SYSLIBS')), [])
compiler = new_compiler()
distutils.sysconfig.customize_compiler(compiler)
return dict(
include_dirs=[distutils.sysconfig.get_python_inc()],
library_dirs=distutils.sysconfig.get_config_vars('LIBDIR', 'LIBPL'),

View File

@ -10,19 +10,21 @@ import tempfile
import textwrap
from distutils.ccompiler import new_compiler
from distutils.errors import CompileError, LinkError
from itertools import filterfalse, takewhile
import distutils.sysconfig
def filter_unsupported_flags(compiler, flags):
if 'clang' in compiler:
return filterfalse(lambda f:
f in ('-mcet',
'-fstack-clash-protection',
'-fno-var-tracking-assignments',
'-Wno-deprecated-register',
'-Wno-gnu-designator') or
f.startswith('-fcf-protection'),
flags)
args = takewhile(lambda argv: not argv.startswith('-'), [compiler] + flags)
if any('clang' in arg for arg in args):
return list(filterfalse(lambda f:
f in ('-mcet',
'-fstack-clash-protection',
'-fno-var-tracking-assignments',
'-Wno-deprecated-register',
'-Wno-gnu-designator') or
f.startswith('-fcf-protection'),
flags))
else:
return flags
@ -61,6 +63,7 @@ def get_python_flags(libs):
py_libs = sum((libs.split() for libs in
distutils.sysconfig.get_config_vars('LIBS', 'SYSLIBS')), [])
compiler = new_compiler()
distutils.sysconfig.customize_compiler(compiler)
return dict(
include_dirs=[distutils.sysconfig.get_python_inc()],
library_dirs=distutils.sysconfig.get_config_vars('LIBDIR', 'LIBPL'),