[New-bugs-announce] [issue13260] distutils and cross-compiling the extensions

Alexander Myodov report at bugs.python.org
Tue Oct 25 01:41:39 CEST 2011

New submission from Alexander Myodov <amyodov at gmail.com>:

I was recently trying to cross-compile several extensions (host: Linux, target: Win32) using mingw-gcc, and noticed that there is quite a little amount of changes needed to distutils code to at least make proper win32-compabible modules.

Some of them require pretty noticeable functionality changes to distutils (like, adding a new option) thus they are unlikely a target for 2.7 anymore (though with some luck, any person who wants to follow my way and do cross-compilation, may just subclass the existing code). But some others are obvious bugs, and their fixes may still be useful for users stuck at 2.7.

1. (This is dubious but still is related to the problem, and was required to build some of the modules). "--include-dirs" and "--library-dirs" options to build_ext command support multiple paths separated by os.pathsep. For some reason (which I may be unaware of) "--libraries" option doesn't. A tiny fix just adds this support.

2. (more obvious issue) get_msvcr() function in distutils/cygwincompiler.py tries to guess the C runtime library which the target extension should link to. To do that, it tests the Python where the setup.py is *running* for what library it was linked to. But when the compilation target is Win32 but the compilation host is Linux, the hosts's Python won't contain such information. In this case, this function will return None. The result then gets assigned to self.dll_libraries (in an instance of CygwinCCompiler or Mingw32CCompiler), and gets used in a context which implies it is always an iterable (libraries.extend(self.dll_libraries)).

These changes, together with altering or subclassing Mingw32CCompiler to use a different compiler name (like, "i586-mingw32msvc-gcc" instead of "gcc"), make it possible to cross-compile a number of extensions which were non-compileable before.

assignee: tarek
components: Distutils
files: distutils.patch
keywords: patch
messages: 146340
nosy: amyodov, eric.araujo, tarek
priority: normal
severity: normal
status: open
title: distutils and cross-compiling the extensions
versions: Python 2.7
Added file: http://bugs.python.org/file23514/distutils.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list