Last active
March 12, 2022 21:26
-
-
Save jonashaag/9f83c0325deb5ab4e9849cc27305a697 to your computer and use it in GitHub Desktop.
Python distutils/setup.py/pip compiler launcher (ccache/sccache)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CompilerLauncherMixin: | |
"""Add "compiler launchers" to distutils. | |
We use this to be able to run the Pandas build using "ccache". | |
A compiler launcher is a program that is invoked instead of invoking the | |
compiler directly. It is passed the full compiler invocation command line. | |
A similar feature exists in CMake, see | |
https://cmake.org/cmake/help/latest/prop_tgt/LANG_COMPILER_LAUNCHER.html. | |
""" | |
__is_set_up = False | |
def build_extensions(self): | |
# Integrate into "build_ext" | |
self.__setup() | |
super().build_extensions() | |
def build_libraries(self): | |
# Integrate into "build_clib" | |
self.__setup() | |
super().build_extensions() | |
def __setup(self): | |
if self.__is_set_up: | |
return | |
self.__is_set_up = True | |
compiler_launcher = os.getenv("DISTUTILS_C_COMPILER_LAUNCHER") | |
if compiler_launcher: | |
def spawn_with_compiler_launcher(cmd): | |
exclude_programs = ("link.exe",) | |
if not cmd[0].endswith(exclude_programs): | |
cmd = [compiler_launcher] + cmd | |
return original_spawn(cmd) | |
original_spawn = self.compiler.spawn | |
self.compiler.spawn = spawn_with_compiler_launcher |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment