0

I am trying to compile a simple test.pyx file. To do this I made setup.py as follows:

from setuptools import setup
from Cython.Build import cythonize

setup(
    compiler_directives={'language_level' : "3"},
    extra_compile_args=['-Ofast', '-march=native'],
    ext_modules = cythonize("test.pyx")
)

I get the warnings:

UserWarning: Unknown distribution option: 'compiler_directives'
  warnings.warn(msg)
Unknown distribution option: 'extra_compile_args'
  warnings.warn(msg)

How should I have done this?

I am using Cython version 0.29.35 .

Simd
  • 19,447
  • 42
  • 136
  • 271
  • I can't vote to close because of the bounty, but https://stackoverflow.com/questions/37511506/compile-cython-with-specific-compiler-args may answer your question for `extra_compile_args`, i.e., use them inside of `Extension()`, and for `compiler_directives` see https://cython.readthedocs.io/en/stable/src/userguide/source_files_and_compilation.html?highlight=compiler_directives#in-setup-py, i.e., use them inside of `cythonize()`. – Marijn Jun 03 '23 at 14:09

1 Answers1

1

Thanks to Marijn this compiles without warnings:

from setuptools import setup
from Cython.Build import cythonize
from setuptools.extension import Extension

ext_modules = [
    Extension(
        'test_sum',
        language='c',
        sources=['test.pyx'],  # list of source files
        extra_compile_args=['-Ofast', '-march=native'],  # example extra compiler arguments
    )
]

setup(
    name = "test module",
    ext_modules = cythonize(ext_modules, compiler_directives={'language_level' : "3"})
    
)
Simd
  • 19,447
  • 42
  • 136
  • 271