[Distutils] cross-compiling using distutils

Mark Hammond mhammond at skippinet.com.au
Wed Jul 18 07:29:23 CEST 2007


Hi all,
  I'm making good progress on using bdist_msi to package up x64 versions of
the pywin32 extensions.  On the way I've struck a number of issues.  In an
effort to try and keey the discussions focussed, I'll create new threads for
each of them, and the first cab off the rank is cross-compilation.

IIUC, the only way to build Python or Python extensions using VS2003 is to
cross-compile from a 32bit platform.  Although this requirement is only
short term, in the longer term we should support cross-compilation to
prevent a Windows developer needing access to all architectures just to
create a build.

Here are the problems I had:

* The dev box needs access to both a 32bit and a 64bit version of Python -
the 32bit one to execute Python itself, and the 64bit one to link against.
* PYTHONHOME had to be set to the x64 version of Python when running the
build, otherwise the link would fail as it tries to use the 32bit python.lib
* '/MACHINE:AMD64' or '/MACHINE:Itanium' manually needs to be added to the
link commandline.
* '/D_M_X64' had to be passed to the compiler (which seems unusual, but I
didn't dig too deep into this)

One way to approach this might be to add a "global" option to distutils.  It
might be possible to call it --python_bin_dir, which would point at the
libraries for the target system (and we could attempt to sniff the
architecture from them).  It would need to be a 'global' option as many
commands may need to know the target (eg, bdist_msi would also need to know)
and distutils.util.get_platform() would need to change to reflect the target
platform, not the platform being used to perform the build.
msvccompiler.get_build_architecture() could also change to take advantage of
this and grow support for /MACHINE etc.

Does anyone have any thoughts on this?  I'm happy to come up with a patch,
but I'm looking for direction (or even just encouragement <wink>)

Thanks,

Mark



More information about the Distutils-SIG mailing list