2

When one runs the following code:

git clone https://github.com/cython/cython.git
sudo python setup.py install

cython (Cython==0.24) is compiled with the default compilation arguments. Apparently, it used to be that one could add:

extra_compile_args=["-O3"]

to the setup.py file and control this. But I just tried it (by putting that line right below:

import platform
is_cpython = platform.python_implementation() == 'CPython'

) and when I do

sudo python setup.py install

all the files are still compiled with the dreaded -O2 flag. How to fix this?

(I'm using linux)

Community
  • 1
  • 1
user189035
  • 5,589
  • 13
  • 52
  • 112

1 Answers1

2

I'm pretty sure that using export CFLAGS="-O3" from the terminal before running setup.py (as I mentioned in the comment) generally does the trick, but, I just realized what you were trying to do.

You need to supply the extra_compile_args as an argument when creating the Extention object(s) for the file(s) that need to be compiled. extra_compile_args is a list containing a string for every argument you want to supply.

In the setup.py script for the Cython lib, that is performed in lines 163-166 if I am not mistaken.

In short, if you change those lines to:

    extensions.append(Extension(
        module, sources=[pyx_source_file],
        extra_compile_args=["-O3"],   # add the needed argument
        define_macros=defines_for_module,
        depends=dep_files))

It will make sure that every .pyx file that is compiled will have the -O3 argument specified.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253