Judging from a quick glance at the relevant modules, there seems to be no provision in Distutils to change the compiler options (specifically optimization and debug options) from the values used during Python installation. Is this true and if so, is this a temporary implementation restriction or an intentional design decision? Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais -------------------------------------------------------------------------------
Konrad Hinsen wrote:
Judging from a quick glance at the relevant modules, there seems to be no provision in Distutils to change the compiler options (specifically optimization and debug options) from the values used during Python installation. Is this true and if so, is this a temporary implementation restriction or an intentional design decision?
Funny, I stumbled into the same problem just a few days ago when I wrapped the 2.0.1 release of mxODBC. I found that the MS VC default options did not turn on optimization and that some important flags were missing. After looking at the distutils code, I found that there is no way to subclass the compiler class *and* hvae distutils use it, so I eventually ended up with a hack: # # mx MSVC Compiler extension # # We want some extra options for the MSVCCompiler, so we add them # here. This is an awful hack, but there seems to be no other way to # subclass a standard distutils C compiler class... from distutils.msvccompiler import MSVCCompiler # remember old __init__ old_MSVCCompiler__init__ = MSVCCompiler.__init__ def mx_msvccompiler__init__(self, *args, **kws): apply(old_MSVCCompiler__init__, (self,) + args, kws) self.compile_options.extend(['/O2','/Gf','/GB','/GD']) # "install" new __init__ MSVCCompiler.__init__ = mx_msvccompiler__init__ I think it would be worthwhile thinking about a more generic way to implement such compiler specific option changes... -- Marc-Andre Lemburg ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Pages: http://www.lemburg.com/python/
I think it would be worthwhile thinking about a more generic way to implement such compiler specific option changes...
Indeed. But that would still not solve my problem: I want to tell Distutils to compile some module with highest optimization level, lowest optimization level, or default optimization level, and perhaps also whether debugging info should be included. And this should of course work with any compiler. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais -------------------------------------------------------------------------------
On Mon, Apr 02, 2001 at 06:30:41PM +0200, Konrad Hinsen wrote:
Indeed. But that would still not solve my problem: I want to tell Distutils to compile some module with highest optimization level, lowest optimization level, or default optimization level, and perhaps also whether debugging info should be included. And this should of course work with any compiler.
One subtlety is that some compiler arguments are required, such as the -n32 switches on SGI, and can't be changed at the risk of error. Other arguments such as -g and -O can be varied safely, of course, but I don't know if Python distinguishes between the two types of switches on all platforms. For example, the SGI-related options are separated out as $(SGI_ABI), but is that true of all possible switches on all platforms? --amk
Konrad Hinsen wrote:
Judging from a quick glance at the relevant modules, there seems to be no provision in Distutils to change the compiler options (specifically optimization and debug options) from the values used during Python installation. Is this true and if so, is this a temporary implementation restriction or an intentional design decision?
I vaguely remember some code which is intended to pickup a CFLAGS environment var.
Marc-Andre:
Funny, I stumbled into the same problem just a few days ago when I wrapped the 2.0.1 release of mxODBC. I found that the MS VC default options did not turn on optimization and that some important flags were missing.
[...]
apply(old_MSVCCompiler__init__, (self,) + args, kws) self.compile_options.extend(['/O2','/Gf','/GB','/GD'])
Optimization is definitely turned on (distutils uses /Ox /MD /W3 /GX): /Ox - This option combines optimizing options to produce the fastest possible program. /GD is marked as 'for future use'. /GB favors the Pentium Processor (imo this makes sense). /Gf eliminates duplicate strings (imo also makes sense). Thomas
Thomas Heller wrote:
Konrad Hinsen wrote:
Judging from a quick glance at the relevant modules, there seems to be no provision in Distutils to change the compiler options (specifically optimization and debug options) from the values used during Python installation. Is this true and if so, is this a temporary implementation restriction or an intentional design decision?
I vaguely remember some code which is intended to pickup a CFLAGS environment var.
It's in there, but it really only makes sense on Unix platforms where this method is in common use. Still, I'd like to keep all distutils setup techniques in Python if possible.
Marc-Andre:
Funny, I stumbled into the same problem just a few days ago when I wrapped the 2.0.1 release of mxODBC. I found that the MS VC default options did not turn on optimization and that some important flags were missing.
[...]
apply(old_MSVCCompiler__init__, (self,) + args, kws) self.compile_options.extend(['/O2','/Gf','/GB','/GD'])
Optimization is definitely turned on (distutils uses /Ox /MD /W3 /GX):
/Ox - This option combines optimizing options to produce the fastest possible program.
Oh, I didn't know that... anyway, the code generated with the few extra options does run noticably faster on my machine.
/GD is marked as 'for future use'.
Running cl /? gives this explanation: /GD Optimieren fuer Windows-DLL (optimize for Windows DLL) IMO, makes sense too, since PYD files are really Windows DLLs.
/GB favors the Pentium Processor (imo this makes sense). /Gf eliminates duplicate strings (imo also makes sense).
BTW, I did see /Ob2 somewhere but can't find any docs for it (also it seems to be only available in the VC pro edition). /V<versionstring> might also be useful... -- Marc-Andre Lemburg ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Pages: http://www.lemburg.com/python/
I vaguely remember some code which is intended to pickup a CFLAGS environment var.
It's in there, but it really only makes sense on Unix platforms where this method is in common use. Still, I'd like to keep all distutils setup techniques in Python if possible. Yes. We need compiler and platform independent compiler flags.
Optimization is definitely turned on (distutils uses /Ox /MD /W3 /GX):
/Ox - This option combines optimizing options to produce the fastest possible program.
Oh, I didn't know that... anyway, the code generated with the few extra options does run noticably faster on my machine. Maybe there are differences in the pro and 'not pro' compilers, maybe also between VC5 and VC6?
/GD is marked as 'for future use'.
Running cl /? gives this explanation:
/GD Optimieren fuer Windows-DLL (optimize for Windows DLL)
My compiler (VC6 prof) gives the same info, 'future use' is mentioned in the MSDN docs. Maybe MS simply forgot to remove this flag and the corresponding /GA flag which generated different code in their 16-bit compiler? (Note that on win32, dlls and exes are very, very similar)
BTW, I did see /Ob2 somewhere but can't find any docs for it (also it seems to be only available in the VC pro edition). The /Ob flags specify how to inline functions.
/V<versionstring> might also be useful...
??? Thomas
Just for the record: The vc6 project file distributed with python2.1 uses the following flags to build the release version: '/MD /W3 /GX /Zi /O2' Thomas
participants (4)
-
Andrew Kuchling
-
Konrad Hinsen
-
M.-A. Lemburg
-
Thomas Heller