• Kirill Smelkov's avatar
    pyx.build: Allow to combine C and C++ sources in one extension · 7ae8c4f3
    Kirill Smelkov authored
    The next patch will add `go` to Pyx API and correspondingly C, C++ and Pyx
    level tests for it that will go into _golang_test.pyx extension. For
    C-level test we'll use C source file - to verify that libgolang.h could
    be used by C projects with C compiler, while for C++ and Pyx-level tests
    the sources will be in C++. Thus _golang_test.so will be build from both
    C and C++ sources.
    
    This creates a problem: distutils / setuptools use the _same_ compiler
    to compile both C and C++ sources and only use C++ compiler at link
    stage. Thus, as it is not possible to tune compiler that is used only
    for C++ sources, and also as it is not possible to provide per-source
    flags, when compiling C-level test, the compiler will be invoked with
    `-std=c++11` option that we inject. Gcc tolerates that and only prints a
    warning, but Clang considers that an error and gives:
    
    	error: invalid argument '-std=c++11' not allowed with 'C'`
    
    A proper fix would be to change the build system from distutils to
    something more flexible that uses C++ compiler for C++ sources and C
    compiler for C sources and allows to tune per-unit flags. However it is
    not a small step at this stage.
    
    -> Use workaround and tweak options that are used when compiling sources
    depending on whether it is C or C++.
    7ae8c4f3
build.py 6.94 KB