Skip to content

Commit 5b5b547

Browse files
authored
Fix setup.py when CC contains -std=c11 option (#70)
Fix setup.py when the C compiler command has the "-std=c11" option. Remove "-std=" options from the compiler command.
1 parent e4539d0 commit 5b5b547

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

tests/setup.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#!/usr/bin/env python3
22
import os.path
3+
import shlex
34
import sys
5+
try:
6+
from setuptools import setup, Extension
7+
except ImportError:
8+
from distutils.core import setup, Extension
9+
try:
10+
from distutils import sysconfig
11+
except ImportError:
12+
import sysconfig
413

514

615
# C++ is only supported on Python 3.6 and newer
@@ -43,10 +52,23 @@
4352

4453

4554
def main():
46-
try:
47-
from setuptools import setup, Extension
48-
except ImportError:
49-
from distutils.core import setup, Extension
55+
# gh-105776: When "gcc -std=11" is used as the C++ compiler, -std=c11
56+
# option emits a C++ compiler warning. Remove "-std11" option from the
57+
# CC command.
58+
cmd = (sysconfig.get_config_var('CC') or '')
59+
if cmd:
60+
cmd = shlex.split(cmd)
61+
cmd = [arg for arg in cmd if not arg.startswith('-std=')]
62+
if (sys.version_info >= (3, 8)):
63+
cmd = shlex.join(cmd)
64+
elif (sys.version_info >= (3, 3)):
65+
cmd = ' '.join(shlex.quote(arg) for arg in cmd)
66+
else:
67+
# Python 2.7
68+
import pipes
69+
cmd = ' '.join(pipes.quote(arg) for arg in cmd)
70+
# CC env var overrides sysconfig CC variable in setuptools
71+
os.environ['CC'] = cmd
5072

5173
cflags = ['-I' + SRC_DIR]
5274
cppflags = list(cflags)

0 commit comments

Comments
 (0)