blob: d5c69a72969b18ba4916a07a61b836f1ffa621ae [file] [log] [blame]
Tim Golden7d052362013-10-25 08:58:16 +01001Building Python using Microsoft Visual C++
2------------------------------------------
Christian Heimes57dddfb2008-01-02 18:30:52 +00003
Tim Golden7d052362013-10-25 08:58:16 +01004This directory is used to build CPython for Microsoft Windows NT version
55.1 or higher (Windows XP, Windows Server 2003, or later) on 32 and 64
6bit platforms. Using this directory requires an installation of
7Microsoft Visual C++ 2010 (MSVC 10.0) of any edition. The specific
8requirements are as follows:
9Visual C++ 2010 Express Edition
10 Required for building 32-bit Debug and Release configuration builds.
11 This edition does not support "solution folders", which pcbuild.sln
12 uses; this will not prevent building.
13Visual Studio 2010 Standard Edition
14 Required for building 64-bit Debug and Release configuration builds
15Visual Studio 2010 Professional Edition
16 Required for building Release configuration builds that make use of
17 Profile Guided Optimization (PGO), on either platform. The official
18 Python releases are built with Professional Edition using PGO.
Trent Nelson52037272008-04-02 15:06:49 +000019
Tim Golden7d052362013-10-25 08:58:16 +010020All you need to do to build is open the solution "pcbuild.sln" in Visual
21Studio, select the desired combination of configuration and platform,
22then build with "Build Solution" or the F7 keyboard shortcut. You can
23also build from the command line using the "build.bat" script in this
24directory. The solution is configured to build the projects in the
25correct order.
Guido van Rossum15b239f1998-05-26 14:16:23 +000026
Tim Golden7d052362013-10-25 08:58:16 +010027The solution currently supports two platforms. The Win32 platform is
28used to build standard x86-compatible 32-bit binaries, output into this
29directory. The x64 platform is used for building 64-bit AMD64 (aka
30x86_64 or EM64T) binaries, output into the amd64 sub-directory which
31will be created if it doesn't already exist. The Itanium (IA-64)
32platform is no longer supported. See the "Building for AMD64" section
33below for more information about 64-bit builds.
Guido van Rossum15b239f1998-05-26 14:16:23 +000034
Tim Golden7d052362013-10-25 08:58:16 +010035Four configuration options are supported by the solution:
36Debug
37 Used to build Python with extra debugging capabilities, equivalent
38 to using ./configure --with-pydebug on UNIX. All binaries built
39 using this configuration have "_d" added to their name:
40 python34_d.dll, python_d.exe, parser_d.pyd, and so on. Both the
41 build and rt (run test) batch files in this directory accept a -d
42 option for debug builds. If you are building Python to help with
43 development of CPython, you will most likely use this configuration.
44PGInstrument, PGUpdate
45 Used to build Python in Release configuration using PGO, which
46 requires Professional Edition of Visual Studio. See the "Profile
47 Guided Optimization" section below for more information. Build
48 output from each of these configurations lands in its own
49 sub-directory of this directory. The official Python releases are
50 built using these configurations.
51Release
52 Used to build Python as it is meant to be used in production
53 settings, though without PGO.
Guido van Rossum15b239f1998-05-26 14:16:23 +000054
Christian Heimes5b5e81c2007-12-31 16:14:33 +000055
Christian Heimes57dddfb2008-01-02 18:30:52 +000056Legacy support
57--------------
58
Tim Golden7d052362013-10-25 08:58:16 +010059You can find build directories for older versions of Visual Studio and
60Visual C++ in the PC directory. The legacy build directories are no
61longer actively maintained and may not work out of the box.
Christian Heimes57dddfb2008-01-02 18:30:52 +000062
Tim Golden7d052362013-10-25 08:58:16 +010063Currently, the only legacy build directory is PC\VS9.0, for Visual
64Studio 2008 (9.0).
Christian Heimes57dddfb2008-01-02 18:30:52 +000065
66
Tim Golden7d052362013-10-25 08:58:16 +010067C Runtime
Christian Heimes57dddfb2008-01-02 18:30:52 +000068---------
69
Tim Golden7d052362013-10-25 08:58:16 +010070Visual Studio 2010 uses version 10 of the C runtime (MSVCRT10). The
71executables no longer use the "Side by Side" assemblies used in previous
72versions of the compiler. This simplifies distribution of applications.
Christian Heimes57dddfb2008-01-02 18:30:52 +000073
Tim Golden7d052362013-10-25 08:58:16 +010074The run time libraries are available under the VC/Redist folder of your
75Visual Studio distribution. For more info, see the Readme in the
76VC/Redist folder.
Guido van Rossume79cf321998-07-07 22:35:03 +000077
Tim Golden7d052362013-10-25 08:58:16 +010078
79Sub-Projects
80------------
81
82The CPython project is split up into several smaller sub-projects which
83are managed by the pcbuild.sln solution file. Each sub-project is
84represented by a .vcxproj and a .vcxproj.filters file starting with the
85name of the sub-project. These sub-projects fall into a few general
86categories:
87
88The following sub-projects represent the bare minimum required to build
89a functioning CPython interpreter. If nothing else builds but these,
90you'll have a very limited but usable python.exe:
Tim Peters97c96402001-01-17 23:23:13 +000091pythoncore
Tim Peters4b5fb072000-07-01 00:03:43 +000092 .dll and .lib
93python
94 .exe
Tim Golden7d052362013-10-25 08:58:16 +010095kill_python
96 kill_python.exe, a small program designed to kill any instances of
97 python(_d).exe that are running and live in the build output
98 directory; this is meant to avoid build issues due to locked files
99make_buildinfo, make_versioninfo
100 helpers to provide necessary information to the build process
101
102These sub-projects provide extra executables that are useful for running
103CPython in different ways:
Tim Peters4b5fb072000-07-01 00:03:43 +0000104pythonw
Tim Golden7d052362013-10-25 08:58:16 +0100105 pythonw.exe, a variant of python.exe that doesn't open a Command
106 Prompt window
107pylauncher
108 py.exe, the Python Launcher for Windows, see
109 http://docs.python.org/3/using/windows.html#launcher
110pywlauncher
111 pyw.exe, a variant of py.exe that doesn't open a Command Prompt
112 window
Zachary Waree0881f42013-11-05 21:55:46 -0600113_testembed
114 _testembed.exe, a small program that embeds Python for testing
115 purposes, used by test_capi.py
Tim Golden7d052362013-10-25 08:58:16 +0100116
117These are miscellaneous sub-projects that don't really fit the other
118categories. By default, these projects do not build in Debug
119configuration:
120_freeze_importlib
121 _freeze_importlib.exe, used to regenerate Python\importlib.h after
122 changes have been made to Lib\importlib\_bootstrap.py
123bdist_wininst
124 ..\Lib\distutils\command\wininst-10.0[-amd64].exe, the base
125 executable used by the distutils bdist_wininst command
126python3dll
127 python3.dll, the PEP 384 Stable ABI dll
128xxlimited
129 builds an example module that makes use of the PEP 384 Stable ABI,
130 see Modules\xxlimited.c
131
132The following sub-projects are for individual modules of the standard
133library which are implemented in C; each one builds a DLL (renamed to
134.pyd) of the same name as the project:
135_ctypes
136_ctypes_test
137_decimal
138_elementtree
139_hashlib
140_msi
141_multiprocessing
142_overlapped
Tim Peters4b5fb072000-07-01 00:03:43 +0000143_socket
Tim Petersd66595f2001-02-04 03:09:53 +0000144_testcapi
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100145_testbuffer
Tim Golden7d052362013-10-25 08:58:16 +0100146_testimportmultiple
Tim Petersb012a152002-02-13 23:56:46 +0000147pyexpat
Tim Peters4b5fb072000-07-01 00:03:43 +0000148select
Tim Peters19f52c22001-01-24 10:07:22 +0000149unicodedata
Tim Peters4b5fb072000-07-01 00:03:43 +0000150winsound
Tim Peters4b5fb072000-07-01 00:03:43 +0000151
Tim Golden7d052362013-10-25 08:58:16 +0100152The following Python-controlled sub-projects wrap external projects.
153Note that these external libraries are not necessary for a working
154interpreter, but they do implement several major features. See the
155"Getting External Sources" section below for additional information
156about getting the source for building these libraries. The sub-projects
157are:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200158_bz2
Tim Golden7d052362013-10-25 08:58:16 +0100159 Python wrapper for version 1.0.6 of the libbzip2 compression library
160 Homepage:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200161 http://www.bzip.org/
Nadeem Vawda3ff069e2011-11-30 00:25:06 +0200162_lzma
Tim Golden7d052362013-10-25 08:58:16 +0100163 Python wrapper for the liblzma compression library, using pre-built
Martin v. Löwisbaacf4d2013-11-22 19:13:51 +0100164 binaries of XZ Utils version 5.0.5
Tim Golden7d052362013-10-25 08:58:16 +0100165 Homepage:
166 http://tukaani.org/xz/
Mark Hammondf229f9f2002-12-03 05:47:26 +0000167_ssl
Tim Golden7d052362013-10-25 08:58:16 +0100168 Python wrapper for version 1.0.1e of the OpenSSL secure sockets
169 library, which is built by ssl.vcxproj
170 Homepage:
171 http://www.openssl.org/
Tim Peters4b5fb072000-07-01 00:03:43 +0000172
Tim Golden7d052362013-10-25 08:58:16 +0100173 Building OpenSSL requires nasm.exe (the Netwide Assembler), version
174 2.10 or newer from
175 http://www.nasm.us/
176 to be somewhere on your PATH. More recent versions of OpenSSL may
177 need a later version of NASM. If OpenSSL's self tests don't pass,
178 you should first try to update NASM and do a full rebuild of
179 OpenSSL.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000180
Tim Golden7d052362013-10-25 08:58:16 +0100181 If you like to use the official sources instead of the files from
182 python.org's subversion repository, Perl is required to build the
183 necessary makefiles and assembly files. ActivePerl is available
184 from
Hirokazu Yamamoto7c3d7092010-10-28 17:57:25 +0000185 http://www.activestate.com/activeperl/
Tim Golden7d052362013-10-25 08:58:16 +0100186 The svn.python.org version contains pre-built makefiles and assembly
187 files.
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000188
Tim Golden7d052362013-10-25 08:58:16 +0100189 The build process makes sure that no patented algorithms are
190 included. For now RC5, MDC2 and IDEA are excluded from the build.
191 You may have to manually remove $(OBJ_D)\i_*.obj from ms\nt.mak if
192 using official sources; the svn.python.org-hosted version is already
193 fixed.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000194
Tim Golden7d052362013-10-25 08:58:16 +0100195 The ssl.vcxproj sub-project simply invokes PCbuild/build_ssl.py,
196 which locates and builds OpenSSL.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000197
198 build_ssl.py attempts to catch the most common errors (such as not
199 being able to find OpenSSL sources, or not being able to find a Perl
Tim Golden7d052362013-10-25 08:58:16 +0100200 that works with OpenSSL) and give a reasonable error message. If
201 you have a problem that doesn't seem to be handled correctly (e.g.,
202 you know you have ActivePerl but we can't find it), please take a
203 peek at build_ssl.py and suggest patches. Note that build_ssl.py
Mark Hammondf229f9f2002-12-03 05:47:26 +0000204 should be able to be run directly from the command-line.
205
Tim Golden7d052362013-10-25 08:58:16 +0100206 The ssl sub-project does not have the ability to clean the OpenSSL
207 build; if you need to rebuild, you'll have to clean it by hand.
208_sqlite3
Martin v. Löwisbc2f0ba2013-11-22 18:36:28 +0100209 Wraps SQLite 3.8.1, which is itself built by sqlite3.vcxproj
Tim Golden7d052362013-10-25 08:58:16 +0100210 Homepage:
211 http://www.sqlite.org/
212_tkinter
Martin v. Löwis8d0d3692013-11-23 23:05:27 +0100213 Wraps version 8.6.1 of the Tk windowing system.
Tim Golden7d052362013-10-25 08:58:16 +0100214 Homepage:
215 http://www.tcl.tk/
Tim Peters4b5fb072000-07-01 00:03:43 +0000216
Tim Golden7d052362013-10-25 08:58:16 +0100217 Unlike the other external libraries listed above, Tk must be built
218 separately before the _tkinter module can be built. This means that
219 a pre-built Tcl/Tk installation is expected in ..\..\tcltk (tcltk64
220 for 64-bit) relative to this directory. See "Getting External
221 Sources" below for the easiest method to ensure Tcl/Tk is built.
Trent Nelson52037272008-04-02 15:06:49 +0000222
Trent Nelson52037272008-04-02 15:06:49 +0000223
Tim Golden7d052362013-10-25 08:58:16 +0100224Getting External Sources
225------------------------
226
227The last category of sub-projects listed above wrap external projects
228Python doesn't control, and as such a little more work is required in
229order to download the relevant source files for each project before they
230can be built. The buildbots must ensure that all libraries are present
231before building, so the easiest approach is to run either external.bat
232or external-amd64.bat (depending on platform) in the ..\Tools\buildbot
233directory from ..\, i.e.:
234
235 C:\python\cpython\PCbuild>cd ..
236 C:\python\cpython>Tools\buildbot\external.bat
237
238This extracts all the external sub-projects from
239 http://svn.python.org/projects/external
240via Subversion (so you'll need an svn.exe on your PATH) and places them
241in ..\.. (relative to this directory).
242
243It is also possible to download sources from each project's homepage,
244though you may have to change the names of some folders in order to make
Martin v. Löwisbaacf4d2013-11-22 19:13:51 +0100245things work. For instance, if you were to download a version 5.0.7 of
246XZ Utils, you would need to extract the archive into ..\..\xz-5.0.5
Tim Golden7d052362013-10-25 08:58:16 +0100247anyway, since that is where the solution is set to look for xz. The
248same is true for all other external projects.
249
250The external(-amd64).bat scripts will also build a debug build of
251Tcl/Tk, but there aren't any equivalent batch files for building release
252versions of Tcl/Tk currently available. If you need to build a release
253version of Tcl/Tk, just take a look at the relevant external(-amd64).bat
254file and find the two nmake lines, then call each one without the
255'DEBUG=1' parameter, i.e.:
Trent Nelson52037272008-04-02 15:06:49 +0000256
257The external-amd64.bat file contains this for tcl:
Tim Golden7d052362013-10-25 08:58:16 +0100258 nmake -f makefile.vc DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
Trent Nelson52037272008-04-02 15:06:49 +0000259
260So for a release build, you'd call it as:
Tim Golden7d052362013-10-25 08:58:16 +0100261 nmake -f makefile.vc MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
Trent Nelson52037272008-04-02 15:06:49 +0000262
Martin v. Löwis8d0d3692013-11-23 23:05:27 +0100263Note that the above command is called from within ..\..\tcl-8.6.1.0\win
Tim Golden7d052362013-10-25 08:58:16 +0100264(relative to this directory); don't forget to build Tk as well as Tcl!
Trent Nelson52037272008-04-02 15:06:49 +0000265
Tim Golden7d052362013-10-25 08:58:16 +0100266This will be cleaned up in the future; http://bugs.python.org/issue15968
267tracks adding a new tcltk.vcxproj file that will build Tcl/Tk and Tix
268the same way the other external projects listed above are built.
Trent Nelson52037272008-04-02 15:06:49 +0000269
Martin v. Löwis13e50fe2004-07-20 14:37:48 +0000270
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000271Building for AMD64
272------------------
273
Tim Golden7d052362013-10-25 08:58:16 +0100274The build process for AMD64 / x64 is very similar to standard builds,
275you just have to set x64 as platform. In addition, the HOST_PYTHON
276environment variable must point to a Python interpreter (at least 2.4),
277to support cross-compilation from Win32. Note that Visual Studio
278requires either Standard Edition or better, or Express Edition with the
279Windows SDK 64-bit compilers to be available in order to build 64-bit
280binaries.
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000281
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000282
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000283Profile Guided Optimization
284---------------------------
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000285
Christian Heimes25bb7832008-01-11 16:17:00 +0000286The solution has two configurations for PGO. The PGInstrument
Tim Golden7d052362013-10-25 08:58:16 +0100287configuration must be built first. The PGInstrument binaries are linked
288against a profiling library and contain extra debug information. The
289PGUpdate configuration takes the profiling data and generates optimized
290binaries.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000291
Tim Golden7d052362013-10-25 08:58:16 +0100292The build_pgo.bat script automates the creation of optimized binaries.
293It creates the PGI files, runs the unit test suite or PyBench with the
294PGI python, and finally creates the optimized files.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000295
Tim Golden7d052362013-10-25 08:58:16 +0100296See
297 http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.100).aspx
298for more on this topic.
299
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000300
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000301Static library
302--------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000303
Tim Golden7d052362013-10-25 08:58:16 +0100304The solution has no configuration for static libraries. However it is
305easy to build a static library instead of a DLL. You simply have to set
306the "Configuration Type" to "Static Library (.lib)" and alter the
307preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may
308also have to change the "Runtime Library" from "Multi-threaded DLL
309(/MD)" to "Multi-threaded (/MT)".
310
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000311
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000312Visual Studio properties
313------------------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000314
Tim Golden7d052362013-10-25 08:58:16 +0100315The PCbuild solution makes heavy use of Visual Studio property files
316(*.props). The properties can be viewed and altered in the Property
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000317Manager (View -> Other Windows -> Property Manager).
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000318
Tim Golden7d052362013-10-25 08:58:16 +0100319The property files used are (+-- = "also imports"):
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000320 * debug (debug macro: _DEBUG)
321 * pginstrument (PGO)
322 * pgupdate (PGO)
323 +-- pginstrument
324 * pyd (python extension, release build)
325 +-- release
326 +-- pyproject
327 * pyd_d (python extension, debug build)
328 +-- debug
329 +-- pyproject
330 * pyproject (base settings for all projects, user macros like PyDllName)
331 * release (release macro: NDEBUG)
Tim Golden7d052362013-10-25 08:58:16 +0100332 * sqlite3 (used only by sqlite3.vcxproj)
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000333 * x64 (AMD64 / x64 platform specific settings)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000334
Tim Golden7d052362013-10-25 08:58:16 +0100335The pyproject property file defines _WIN32 and x64 defines _WIN64 and
336_M_X64 although the macros are set by the compiler, too. The GUI doesn't
337always know about the macros and confuse the user with false
338information.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000339
Tim Golden7d052362013-10-25 08:58:16 +0100340
341Your Own Extension DLLs
Tim Peters4b5fb072000-07-01 00:03:43 +0000342-----------------------
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000343
Tim Golden7d052362013-10-25 08:58:16 +0100344If you want to create your own extension module DLL (.pyd), there's an
345example with easy-to-follow instructions in ..\PC\example\; read the
346file readme.txt there first.