1# gh-91321: Build a basic C++ test extension to check that the Python C API is 2# compatible with C++ and does not emit C++ compiler warnings. 3import sys 4from test import support 5 6from setuptools import setup, Extension 7 8 9MS_WINDOWS = (sys.platform == 'win32') 10 11 12SOURCE = support.findfile('_testcppext.cpp') 13if not MS_WINDOWS: 14 # C++ compiler flags for GCC and clang 15 CPPFLAGS = [ 16 # gh-91321: The purpose of _testcppext extension is to check that building 17 # a C++ extension using the Python C API does not emit C++ compiler 18 # warnings 19 '-Werror', 20 ] 21else: 22 # Don't pass any compiler flag to MSVC 23 CPPFLAGS = [] 24 25 26def main(): 27 cppflags = list(CPPFLAGS) 28 if '-std=c++03' in sys.argv: 29 sys.argv.remove('-std=c++03') 30 std = 'c++03' 31 name = '_testcpp03ext' 32 else: 33 # Python currently targets C++11 34 std = 'c++11' 35 name = '_testcpp11ext' 36 37 cppflags = [*CPPFLAGS, f'-std={std}'] 38 39 cpp_ext = Extension( 40 name, 41 sources=[SOURCE], 42 language='c++', 43 extra_compile_args=cppflags) 44 setup(name='internal' + name, version='0.0', ext_modules=[cpp_ext]) 45 46 47if __name__ == "__main__": 48 main() 49