Exemple #1
0
def sage_create_extension(template, kwds):
    """
    Create a distutils Extension given data from Cython

    This adjust the ``kwds`` in the following ways:

    - Make everything depend on *this* setup.py file

    - Add dependencies on header files for certain libraries

    - Ensure that C++ extensions link with -lstdc++

    - Sort the libraries according to the library order

    - Add some default compile/link args and directories

    - Drop -std=c99 and similar from C++ extensions

    - Ensure that each flag, library, ... is listed at most once
    """
    lang = kwds.get('language', 'c')

    # Libraries: add stdc++ if needed and sort them
    libs = kwds.get('libraries', [])
    if lang == 'c++':
        libs = libs + ['stdc++']
    kwds['libraries'] = sorted(set(libs),
            key=lambda lib: library_order.get(lib, 0))

    # Dependencies: add setup.py and lib_headers
    depends = kwds.get('depends', []) + [__file__]
    for lib, headers in lib_headers.items():
        if lib in libs:
            depends += headers
    kwds['depends'] = depends  # These are sorted and uniq'ed by Cython

    # Process extra_compile_args
    cflags = []
    for flag in kwds.get('extra_compile_args', []):
        if lang == "c++":
            if flag.startswith("-std=") and "++" not in flag:
                continue  # Skip -std=c99 and similar for C++
        cflags.append(flag)
    cflags = extra_compile_args + cflags
    kwds['extra_compile_args'] = stable_uniq(cflags)

    # Process extra_link_args
    ldflags = kwds.get('extra_link_args', []) + extra_link_args
    kwds['extra_link_args'] = stable_uniq(ldflags)

    # Process library_dirs
    lib_dirs = kwds.get('library_dirs', []) + library_dirs
    kwds['library_dirs'] = stable_uniq(lib_dirs)

    # Process include_dirs
    inc_dirs = kwds.get('include_dirs', []) + include_dirs
    kwds['include_dirs'] = stable_uniq(inc_dirs)

    return default_create_extension(template, kwds)
Exemple #2
0
def sage_create_extension(template, kwds):
    """
    Create a distutils Extension given data from Cython

    This adjust the ``kwds`` in the following ways:

    - Make everything depend on *this* setup.py file

    - Add dependencies on header files for certain libraries

    - Ensure that C++ extensions link with -lstdc++

    - Sort the libraries according to the library order

    - Add some default compile/link args and directories

    - Drop -std=c99 and similar from C++ extensions

    - Ensure that each flag, library, ... is listed at most once
    """
    lang = kwds.get('language', 'c')

    # Libraries: add stdc++ if needed and sort them
    libs = kwds.get('libraries', [])
    if lang == 'c++':
        libs = libs + ['stdc++']
    kwds['libraries'] = sorted(set(libs),
                               key=lambda lib: library_order.get(lib, 0))

    # Dependencies: add setup.py and lib_headers
    depends = kwds.get('depends', []) + [__file__]
    for lib, headers in lib_headers.items():
        if lib in libs:
            depends += headers
    kwds['depends'] = depends  # These are sorted and uniq'ed by Cython

    # Process extra_compile_args
    cflags = []
    for flag in kwds.get('extra_compile_args', []):
        if lang == "c++":
            if flag.startswith("-std=") and "++" not in flag:
                continue  # Skip -std=c99 and similar for C++
        cflags.append(flag)
    cflags = extra_compile_args + cflags
    kwds['extra_compile_args'] = stable_uniq(cflags)

    # Process extra_link_args
    ldflags = kwds.get('extra_link_args', []) + extra_link_args
    kwds['extra_link_args'] = stable_uniq(ldflags)

    # Process library_dirs
    lib_dirs = kwds.get('library_dirs', []) + library_dirs
    kwds['library_dirs'] = stable_uniq(lib_dirs)

    # Process include_dirs
    inc_dirs = kwds.get('include_dirs', []) + include_dirs
    kwds['include_dirs'] = stable_uniq(inc_dirs)

    return default_create_extension(template, kwds)
Exemple #3
0
def create_extension(template, kwds):
    from Cython.Build.Dependencies import default_create_extension
    from sage.env import sage_include_directories

    # Add numpy and source folder to the include search path used by the compiler
    # This is a workaround for https://github.com/cython/cython/issues/1480
    include_dirs = kwds.get('include_dirs',
                            []) + sage_include_directories(use_sources=True)
    kwds['include_dirs'] = include_dirs
    return default_create_extension(template, kwds)
Exemple #4
0
def my_create_extension(template, kwds):
    name = kwds['name']
    if RTFD_BUILD:
        kwds['library_dirs'] = LIB_PATH
        kwds['include_dirs'] = INCLUDE_PATH
        kwds['runtime_library_dirs'] = LIB_PATH
        print(kwds)
    if USE_CYTHON_TRACE:
        kwds['define_macros'] = [('CYTHON_TRACE_NOGIL', '1'), ('CYTHON_TRACE', '1')]

    return default_create_extension(template, kwds)
    def create_extension(self, template, kwds):
        """
        Create a distutils Extension given data from Cython.

        This adjust the ``kwds`` in the following ways:

        - Make everything depend on *this* setup.py file

        - Add dependencies on header files for certain libraries

        - Sort the libraries according to the library order

        - Add some default compile/link args and directories

        - Choose C99 standard for C code and C++11 for C++ code

        - Drop -std=c99 and similar from C++ extensions

        - Ensure that each flag, library, ... is listed at most once
        """
        lang = kwds.get('language', 'c')
        cplusplus = (lang == "c++")

        # Libraries: sort them
        libs = kwds.get('libraries', [])
        kwds['libraries'] = sorted(set(libs),
                                   key=lambda lib: library_order.get(lib, 0))

        # Dependencies: add setup.py and lib_headers
        depends = kwds.get('depends', []) + [self.distribution.script_name]
        for lib, headers in lib_headers.items():
            if lib in libs:
                depends += headers
        kwds['depends'] = depends  # These are sorted and uniq'ed by Cython

        # Process extra_compile_args
        cflags = []
        have_std_flag = False
        for flag in kwds.get('extra_compile_args', []):
            if flag.startswith("-std="):
                if cplusplus and "++" not in flag:
                    continue  # Skip -std=c99 and similar for C++
                have_std_flag = True
            cflags.append(flag)
        if not have_std_flag:  # See Trac #23919
            if sys.platform == 'cygwin':
                # Cygwin (particularly newlib, Cygwin's libc) has some bugs
                # with strict ANSI C/C++ in some headers; using the GNU
                # extensions typically fares better:
                # https://trac.sagemath.org/ticket/24192
                if cplusplus:
                    cflags.append("-std=gnu++11")
                else:
                    cflags.append("-std=gnu99")
            else:
                if cplusplus:
                    cflags.append("-std=c++11")
                else:
                    cflags.append("-std=c99")
        cflags = extra_compile_args + cflags
        kwds['extra_compile_args'] = stable_uniq(cflags)

        # Process extra_link_args
        ldflags = kwds.get('extra_link_args', []) + extra_link_args
        kwds['extra_link_args'] = stable_uniq(ldflags)

        # Process library_dirs
        lib_dirs = kwds.get('library_dirs', []) + library_dirs
        kwds['library_dirs'] = stable_uniq(lib_dirs)

        # Process include_dirs
        inc_dirs = kwds.get('include_dirs',
                            []) + include_dirs + [self.build_dir]
        kwds['include_dirs'] = stable_uniq(inc_dirs)

        return default_create_extension(template, kwds)
Exemple #6
0
def do_create_extension(template, kwds):
    libs = kwds.get('libraries', []) + ["datrie"]
    kwds['libraries'] = libs
    return default_create_extension(template, kwds)
Exemple #7
0
def create_extension(template, kwds):
    """"""
    kwds["cmake_options"] = template.cmake_options
    return default_create_extension(template, kwds)
Exemple #8
0
    def create_extension(self, template, kwds):
        """
        Create a distutils Extension given data from Cython.

        This adjust the ``kwds`` in the following ways:

        - Make everything depend on *this* setup.py file

        - Add dependencies on header files for certain libraries

        - Ensure that C++ extensions link with -lstdc++

        - Sort the libraries according to the library order

        - Add some default compile/link args and directories

        - Choose C99 standard for C code and C++11 for C++ code

        - Drop -std=c99 and similar from C++ extensions

        - Ensure that each flag, library, ... is listed at most once
        """
        lang = kwds.get('language', 'c')
        cplusplus = (lang == "c++")

        # Libraries: add stdc++ if needed and sort them
        libs = kwds.get('libraries', [])
        if cplusplus:
            libs = libs + ['stdc++']
        kwds['libraries'] = sorted(set(libs),
                key=lambda lib: library_order.get(lib, 0))

        # Dependencies: add setup.py and lib_headers
        depends = kwds.get('depends', []) + [__file__]
        for lib, headers in lib_headers.items():
            if lib in libs:
                depends += headers
        kwds['depends'] = depends  # These are sorted and uniq'ed by Cython

        # Process extra_compile_args
        cflags = []
        have_std_flag = False
        for flag in kwds.get('extra_compile_args', []):
            if flag.startswith("-std="):
                if cplusplus and "++" not in flag:
                    continue  # Skip -std=c99 and similar for C++
                have_std_flag = True
            cflags.append(flag)
        if not have_std_flag:  # See Trac #23919
            if sys.platform == 'cygwin':
                # Cygwin (particularly newlib, Cygwin's libc) has some bugs
                # with strict ANSI C/C++ in some headers; using the GNU
                # extensions typically fares better:
                # https://trac.sagemath.org/ticket/24192
                if cplusplus:
                    cflags.append("-std=gnu++11")
                else:
                    cflags.append("-std=gnu99")
            else:
                if cplusplus:
                    cflags.append("-std=c++11")
                else:
                    cflags.append("-std=c99")
        cflags = extra_compile_args + cflags
        kwds['extra_compile_args'] = stable_uniq(cflags)

        # Process extra_link_args
        ldflags = kwds.get('extra_link_args', []) + extra_link_args
        kwds['extra_link_args'] = stable_uniq(ldflags)

        # Process library_dirs
        lib_dirs = kwds.get('library_dirs', []) + library_dirs
        kwds['library_dirs'] = stable_uniq(lib_dirs)

        # Process include_dirs
        inc_dirs = kwds.get('include_dirs', []) + include_dirs + [self.build_dir]
        kwds['include_dirs'] = stable_uniq(inc_dirs)

        return default_create_extension(template, kwds)