I am programming a C++ extension for Python and I am using distutils to compile the project. As the project grows, rebuilding it takes longer and longer. Is there a way to speed up the build process?
I read that parallel builds (as with make -j) are not possible with distutils. Are there any good alternatives to distutils which might be faster?
I also noticed that it’s recompiling all object files every time I call python setup.py build, even when I only changed one source file. Should this be the case or might I be doing something wrong here?
In case it helps, here are some of the files which I try to compile: https://gist.github.com/2923577
Thanks!
Try building with environment variable
CC="ccache gcc", that will speed up build significantly when the source has not changed. (strangely, distutils usesCCalso for c++ source files). Install the ccache package, of course.Since you have a single extension which is assembled from multiple compiled object files, you can monkey-patch distutils to compile those in parallel (they are independent) – put this into your setup.py (adjust the
N=2as you wish):For the sake of completeness, if you have multiple extensions, you can use the following solution: