for M2Crypto I use swig to generate C bindings for OpenSSL. For debugging purposes it would be often useful to have the generated C code available for inspection (and gdb would be also more happy). However, whatever I am trying (-n, various -C options for setuptools) I cannot stop both python3 -mbuild and python3 -mpip from removing that generated C code.
Is it possible to protect that file, or is this limitation actually a bug in setuptools (or build and pip)?
You’ll need to disable pip build isolation, otherwise the build directory will be removed after it finishes.
With setuptools generally I use an editable install along with disabling build isolation so the build happens in-place, then the C code ends up in your source tree, and the source tree is the “active” installation.
There are probably other ways to get setuptools and pip to preserve the build directory, this is just how I do it.
With meson and meson-python this is all a little nicer, you can tell meson explicitly where to put the build and install directories.