blob: ee2d2a0ebc584b2470f5f48d774ba58f4e215db9 [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:
Zachary Ware5f3e3c32014-03-19 14:46:25 -05009
Tim Golden7d052362013-10-25 08:58:16 +010010Visual C++ 2010 Express Edition
11 Required for building 32-bit Debug and Release configuration builds.
12 This edition does not support "solution folders", which pcbuild.sln
13 uses; this will not prevent building.
Tim Golden7d052362013-10-25 08:58:16 +010014Visual Studio 2010 Professional Edition
Zachary Ware5f3e3c32014-03-19 14:46:25 -050015 Required for building 64-bit Debug and Release configuration builds
16Visual Studio 2010 Premium Edition
Tim Golden7d052362013-10-25 08:58:16 +010017 Required for building Release configuration builds that make use of
Zachary Ware5f3e3c32014-03-19 14:46:25 -050018 Profile Guided Optimization (PGO), on either platform.
19
20The official Python releases are built with PGO using Visual Studio 2010
21Ultimate Edition.
Trent Nelson52037272008-04-02 15:06:49 +000022
Tim Golden7d052362013-10-25 08:58:16 +010023All you need to do to build is open the solution "pcbuild.sln" in Visual
24Studio, select the desired combination of configuration and platform,
25then build with "Build Solution" or the F7 keyboard shortcut. You can
26also build from the command line using the "build.bat" script in this
27directory. The solution is configured to build the projects in the
28correct order.
Guido van Rossum15b239f1998-05-26 14:16:23 +000029
Tim Golden7d052362013-10-25 08:58:16 +010030The solution currently supports two platforms. The Win32 platform is
31used to build standard x86-compatible 32-bit binaries, output into this
32directory. The x64 platform is used for building 64-bit AMD64 (aka
33x86_64 or EM64T) binaries, output into the amd64 sub-directory which
34will be created if it doesn't already exist. The Itanium (IA-64)
35platform is no longer supported. See the "Building for AMD64" section
36below for more information about 64-bit builds.
Guido van Rossum15b239f1998-05-26 14:16:23 +000037
Tim Golden7d052362013-10-25 08:58:16 +010038Four configuration options are supported by the solution:
39Debug
40 Used to build Python with extra debugging capabilities, equivalent
41 to using ./configure --with-pydebug on UNIX. All binaries built
42 using this configuration have "_d" added to their name:
Zachary Ware6373ba52014-03-17 15:57:38 -050043 python35_d.dll, python_d.exe, parser_d.pyd, and so on. Both the
Tim Golden7d052362013-10-25 08:58:16 +010044 build and rt (run test) batch files in this directory accept a -d
45 option for debug builds. If you are building Python to help with
46 development of CPython, you will most likely use this configuration.
47PGInstrument, PGUpdate
48 Used to build Python in Release configuration using PGO, which
49 requires Professional Edition of Visual Studio. See the "Profile
50 Guided Optimization" section below for more information. Build
51 output from each of these configurations lands in its own
52 sub-directory of this directory. The official Python releases are
53 built using these configurations.
54Release
55 Used to build Python as it is meant to be used in production
56 settings, though without PGO.
Guido van Rossum15b239f1998-05-26 14:16:23 +000057
Christian Heimes5b5e81c2007-12-31 16:14:33 +000058
Christian Heimes57dddfb2008-01-02 18:30:52 +000059Legacy support
60--------------
61
Tim Golden7d052362013-10-25 08:58:16 +010062You can find build directories for older versions of Visual Studio and
63Visual C++ in the PC directory. The legacy build directories are no
64longer actively maintained and may not work out of the box.
Christian Heimes57dddfb2008-01-02 18:30:52 +000065
Tim Golden7d052362013-10-25 08:58:16 +010066Currently, the only legacy build directory is PC\VS9.0, for Visual
67Studio 2008 (9.0).
Christian Heimes57dddfb2008-01-02 18:30:52 +000068
69
Tim Golden7d052362013-10-25 08:58:16 +010070C Runtime
Christian Heimes57dddfb2008-01-02 18:30:52 +000071---------
72
Tim Golden7d052362013-10-25 08:58:16 +010073Visual Studio 2010 uses version 10 of the C runtime (MSVCRT10). The
74executables no longer use the "Side by Side" assemblies used in previous
75versions of the compiler. This simplifies distribution of applications.
Christian Heimes57dddfb2008-01-02 18:30:52 +000076
Tim Golden7d052362013-10-25 08:58:16 +010077The run time libraries are available under the VC/Redist folder of your
78Visual Studio distribution. For more info, see the Readme in the
79VC/Redist folder.
Guido van Rossume79cf321998-07-07 22:35:03 +000080
Tim Golden7d052362013-10-25 08:58:16 +010081
82Sub-Projects
83------------
84
85The CPython project is split up into several smaller sub-projects which
86are managed by the pcbuild.sln solution file. Each sub-project is
87represented by a .vcxproj and a .vcxproj.filters file starting with the
88name of the sub-project. These sub-projects fall into a few general
89categories:
90
91The following sub-projects represent the bare minimum required to build
92a functioning CPython interpreter. If nothing else builds but these,
93you'll have a very limited but usable python.exe:
Tim Peters97c96402001-01-17 23:23:13 +000094pythoncore
Tim Peters4b5fb072000-07-01 00:03:43 +000095 .dll and .lib
96python
97 .exe
Tim Golden7d052362013-10-25 08:58:16 +010098kill_python
99 kill_python.exe, a small program designed to kill any instances of
100 python(_d).exe that are running and live in the build output
101 directory; this is meant to avoid build issues due to locked files
102make_buildinfo, make_versioninfo
103 helpers to provide necessary information to the build process
104
105These sub-projects provide extra executables that are useful for running
106CPython in different ways:
Tim Peters4b5fb072000-07-01 00:03:43 +0000107pythonw
Tim Golden7d052362013-10-25 08:58:16 +0100108 pythonw.exe, a variant of python.exe that doesn't open a Command
109 Prompt window
110pylauncher
111 py.exe, the Python Launcher for Windows, see
112 http://docs.python.org/3/using/windows.html#launcher
113pywlauncher
114 pyw.exe, a variant of py.exe that doesn't open a Command Prompt
115 window
Zachary Waree0881f42013-11-05 21:55:46 -0600116_testembed
117 _testembed.exe, a small program that embeds Python for testing
118 purposes, used by test_capi.py
Tim Golden7d052362013-10-25 08:58:16 +0100119
120These are miscellaneous sub-projects that don't really fit the other
121categories. By default, these projects do not build in Debug
122configuration:
123_freeze_importlib
124 _freeze_importlib.exe, used to regenerate Python\importlib.h after
125 changes have been made to Lib\importlib\_bootstrap.py
126bdist_wininst
127 ..\Lib\distutils\command\wininst-10.0[-amd64].exe, the base
128 executable used by the distutils bdist_wininst command
129python3dll
130 python3.dll, the PEP 384 Stable ABI dll
131xxlimited
132 builds an example module that makes use of the PEP 384 Stable ABI,
133 see Modules\xxlimited.c
134
135The following sub-projects are for individual modules of the standard
136library which are implemented in C; each one builds a DLL (renamed to
137.pyd) of the same name as the project:
138_ctypes
139_ctypes_test
140_decimal
141_elementtree
142_hashlib
143_msi
144_multiprocessing
145_overlapped
Tim Peters4b5fb072000-07-01 00:03:43 +0000146_socket
Tim Petersd66595f2001-02-04 03:09:53 +0000147_testcapi
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100148_testbuffer
Tim Golden7d052362013-10-25 08:58:16 +0100149_testimportmultiple
Tim Petersb012a152002-02-13 23:56:46 +0000150pyexpat
Tim Peters4b5fb072000-07-01 00:03:43 +0000151select
Tim Peters19f52c22001-01-24 10:07:22 +0000152unicodedata
Tim Peters4b5fb072000-07-01 00:03:43 +0000153winsound
Tim Peters4b5fb072000-07-01 00:03:43 +0000154
Tim Golden7d052362013-10-25 08:58:16 +0100155The following Python-controlled sub-projects wrap external projects.
156Note that these external libraries are not necessary for a working
157interpreter, but they do implement several major features. See the
158"Getting External Sources" section below for additional information
159about getting the source for building these libraries. The sub-projects
160are:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200161_bz2
Tim Golden7d052362013-10-25 08:58:16 +0100162 Python wrapper for version 1.0.6 of the libbzip2 compression library
163 Homepage:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200164 http://www.bzip.org/
Nadeem Vawda3ff069e2011-11-30 00:25:06 +0200165_lzma
Tim Golden7d052362013-10-25 08:58:16 +0100166 Python wrapper for the liblzma compression library, using pre-built
Martin v. Löwisbaacf4d2013-11-22 19:13:51 +0100167 binaries of XZ Utils version 5.0.5
Tim Golden7d052362013-10-25 08:58:16 +0100168 Homepage:
169 http://tukaani.org/xz/
Mark Hammondf229f9f2002-12-03 05:47:26 +0000170_ssl
Tim Golden7d052362013-10-25 08:58:16 +0100171 Python wrapper for version 1.0.1e of the OpenSSL secure sockets
172 library, which is built by ssl.vcxproj
173 Homepage:
174 http://www.openssl.org/
Tim Peters4b5fb072000-07-01 00:03:43 +0000175
Tim Golden7d052362013-10-25 08:58:16 +0100176 Building OpenSSL requires nasm.exe (the Netwide Assembler), version
177 2.10 or newer from
178 http://www.nasm.us/
179 to be somewhere on your PATH. More recent versions of OpenSSL may
180 need a later version of NASM. If OpenSSL's self tests don't pass,
181 you should first try to update NASM and do a full rebuild of
182 OpenSSL.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000183
Tim Golden7d052362013-10-25 08:58:16 +0100184 If you like to use the official sources instead of the files from
185 python.org's subversion repository, Perl is required to build the
186 necessary makefiles and assembly files. ActivePerl is available
187 from
Hirokazu Yamamoto7c3d7092010-10-28 17:57:25 +0000188 http://www.activestate.com/activeperl/
Tim Golden7d052362013-10-25 08:58:16 +0100189 The svn.python.org version contains pre-built makefiles and assembly
190 files.
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000191
Tim Golden7d052362013-10-25 08:58:16 +0100192 The build process makes sure that no patented algorithms are
193 included. For now RC5, MDC2 and IDEA are excluded from the build.
194 You may have to manually remove $(OBJ_D)\i_*.obj from ms\nt.mak if
195 using official sources; the svn.python.org-hosted version is already
196 fixed.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000197
Tim Golden7d052362013-10-25 08:58:16 +0100198 The ssl.vcxproj sub-project simply invokes PCbuild/build_ssl.py,
199 which locates and builds OpenSSL.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000200
201 build_ssl.py attempts to catch the most common errors (such as not
202 being able to find OpenSSL sources, or not being able to find a Perl
Tim Golden7d052362013-10-25 08:58:16 +0100203 that works with OpenSSL) and give a reasonable error message. If
204 you have a problem that doesn't seem to be handled correctly (e.g.,
205 you know you have ActivePerl but we can't find it), please take a
206 peek at build_ssl.py and suggest patches. Note that build_ssl.py
Mark Hammondf229f9f2002-12-03 05:47:26 +0000207 should be able to be run directly from the command-line.
208
Tim Golden7d052362013-10-25 08:58:16 +0100209 The ssl sub-project does not have the ability to clean the OpenSSL
210 build; if you need to rebuild, you'll have to clean it by hand.
211_sqlite3
Martin v. Löwis09257f72014-03-02 19:42:50 +0100212 Wraps SQLite 3.8.3.1, which is itself built by sqlite3.vcxproj
Tim Golden7d052362013-10-25 08:58:16 +0100213 Homepage:
214 http://www.sqlite.org/
215_tkinter
Martin v. Löwis8d0d3692013-11-23 23:05:27 +0100216 Wraps version 8.6.1 of the Tk windowing system.
Tim Golden7d052362013-10-25 08:58:16 +0100217 Homepage:
218 http://www.tcl.tk/
Tim Peters4b5fb072000-07-01 00:03:43 +0000219
Zachary Warea191b912014-03-21 22:58:19 -0500220 Tkinter's dependencies are built by the tcl.vcxproj and tk.vcxproj
221 projects. The tix.vcxproj project also builds the Tix extended
222 widget set for use with Tkinter.
223
224 Those three projects install their respective components in a
225 directory alongside the source directories called "tcltk" on
226 Win32 and "tcltk64" on x64. They also copy the Tcl and Tk DLLs
227 into the current output directory, which should ensure that Tkinter
228 is able to load Tcl/Tk without having to change your PATH.
229
230 The tcl, tk, and tix sub-projects do not have the ability to clean
231 their builds; if you need to rebuild, you'll have to clean them by
232 hand.
Trent Nelson52037272008-04-02 15:06:49 +0000233
Trent Nelson52037272008-04-02 15:06:49 +0000234
Tim Golden7d052362013-10-25 08:58:16 +0100235Getting External Sources
236------------------------
237
238The last category of sub-projects listed above wrap external projects
239Python doesn't control, and as such a little more work is required in
240order to download the relevant source files for each project before they
241can be built. The buildbots must ensure that all libraries are present
242before building, so the easiest approach is to run either external.bat
243or external-amd64.bat (depending on platform) in the ..\Tools\buildbot
244directory from ..\, i.e.:
245
246 C:\python\cpython\PCbuild>cd ..
247 C:\python\cpython>Tools\buildbot\external.bat
248
249This extracts all the external sub-projects from
250 http://svn.python.org/projects/external
251via Subversion (so you'll need an svn.exe on your PATH) and places them
252in ..\.. (relative to this directory).
253
254It is also possible to download sources from each project's homepage,
255though you may have to change the names of some folders in order to make
Martin v. Löwisbaacf4d2013-11-22 19:13:51 +0100256things work. For instance, if you were to download a version 5.0.7 of
257XZ Utils, you would need to extract the archive into ..\..\xz-5.0.5
Tim Golden7d052362013-10-25 08:58:16 +0100258anyway, since that is where the solution is set to look for xz. The
259same is true for all other external projects.
260
Martin v. Löwis13e50fe2004-07-20 14:37:48 +0000261
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000262Building for AMD64
263------------------
264
Tim Golden7d052362013-10-25 08:58:16 +0100265The build process for AMD64 / x64 is very similar to standard builds,
266you just have to set x64 as platform. In addition, the HOST_PYTHON
267environment variable must point to a Python interpreter (at least 2.4),
268to support cross-compilation from Win32. Note that Visual Studio
Zachary Waree08f3762014-03-28 23:31:04 -0500269requires Professional Edition or better in order to build 64-bit
Tim Golden7d052362013-10-25 08:58:16 +0100270binaries.
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000271
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000272
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000273Profile Guided Optimization
274---------------------------
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000275
Christian Heimes25bb7832008-01-11 16:17:00 +0000276The solution has two configurations for PGO. The PGInstrument
Tim Golden7d052362013-10-25 08:58:16 +0100277configuration must be built first. The PGInstrument binaries are linked
278against a profiling library and contain extra debug information. The
279PGUpdate configuration takes the profiling data and generates optimized
280binaries.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000281
Tim Golden7d052362013-10-25 08:58:16 +0100282The build_pgo.bat script automates the creation of optimized binaries.
283It creates the PGI files, runs the unit test suite or PyBench with the
284PGI python, and finally creates the optimized files.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000285
Tim Golden7d052362013-10-25 08:58:16 +0100286See
287 http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.100).aspx
288for more on this topic.
289
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000290
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000291Static library
292--------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000293
Tim Golden7d052362013-10-25 08:58:16 +0100294The solution has no configuration for static libraries. However it is
295easy to build a static library instead of a DLL. You simply have to set
296the "Configuration Type" to "Static Library (.lib)" and alter the
297preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may
298also have to change the "Runtime Library" from "Multi-threaded DLL
299(/MD)" to "Multi-threaded (/MT)".
300
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000301
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000302Visual Studio properties
303------------------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000304
Tim Golden7d052362013-10-25 08:58:16 +0100305The PCbuild solution makes heavy use of Visual Studio property files
306(*.props). The properties can be viewed and altered in the Property
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000307Manager (View -> Other Windows -> Property Manager).
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000308
Tim Golden7d052362013-10-25 08:58:16 +0100309The property files used are (+-- = "also imports"):
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000310 * debug (debug macro: _DEBUG)
311 * pginstrument (PGO)
312 * pgupdate (PGO)
313 +-- pginstrument
314 * pyd (python extension, release build)
315 +-- release
316 +-- pyproject
317 * pyd_d (python extension, debug build)
318 +-- debug
319 +-- pyproject
320 * pyproject (base settings for all projects, user macros like PyDllName)
321 * release (release macro: NDEBUG)
Tim Golden7d052362013-10-25 08:58:16 +0100322 * sqlite3 (used only by sqlite3.vcxproj)
Zachary Ware4b87dc62014-03-28 23:36:43 -0500323 * tcltk (used by _tkinter, tcl, tk and tix projects)
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000324 * x64 (AMD64 / x64 platform specific settings)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000325
Tim Golden7d052362013-10-25 08:58:16 +0100326The pyproject property file defines _WIN32 and x64 defines _WIN64 and
327_M_X64 although the macros are set by the compiler, too. The GUI doesn't
328always know about the macros and confuse the user with false
329information.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000330
Tim Golden7d052362013-10-25 08:58:16 +0100331
332Your Own Extension DLLs
Tim Peters4b5fb072000-07-01 00:03:43 +0000333-----------------------
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000334
Tim Golden7d052362013-10-25 08:58:16 +0100335If you want to create your own extension module DLL (.pyd), there's an
336example with easy-to-follow instructions in ..\PC\example\; read the
337file readme.txt there first.