Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 1 | Quick Start Guide |
| 2 | ----------------- |
| 3 | |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 4 | 1. Install Microsoft Visual Studio 2017 with Python workload and |
| 5 | Python native development component. |
Zachary Ware | 51599e2 | 2017-06-15 22:08:51 -0500 | [diff] [blame] | 6 | 1a. Optionally install Python 3.6 or later. If not installed, |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 7 | get_externals.bat (via build.bat) will download and use Python via |
Zachary Ware | 51599e2 | 2017-06-15 22:08:51 -0500 | [diff] [blame] | 8 | NuGet. |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 9 | 2. Run "build.bat" to build Python in 32-bit Release configuration. |
Zachary Ware | 51599e2 | 2017-06-15 22:08:51 -0500 | [diff] [blame] | 10 | 3. (Optional, but recommended) Run the test suite with "rt.bat -q". |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 11 | |
| 12 | |
| 13 | Building Python using Microsoft Visual C++ |
| 14 | ------------------------------------------ |
| 15 | |
| 16 | This directory is used to build CPython for Microsoft Windows NT version |
| 17 | 6.0 or higher (Windows Vista, Windows Server 2008, or later) on 32 and 64 |
| 18 | bit platforms. Using this directory requires an installation of |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 19 | Microsoft Visual Studio 2017 (MSVC 14.1) with the *Python workload* and |
| 20 | its optional *Python native development* component selected. (For |
| 21 | command-line builds, Visual Studio 2015 may also be used.) |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 22 | |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 23 | Building from the command line is recommended in order to obtain any |
| 24 | external dependencies. To build, simply run the "build.bat" script without |
| 25 | any arguments. After this succeeds, you can open the "pcbuild.sln" |
| 26 | solution in Visual Studio to continue development. |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 27 | |
| 28 | The solution currently supports two platforms. The Win32 platform is |
| 29 | used to build standard x86-compatible 32-bit binaries, output into the |
| 30 | win32 sub-directory. The x64 platform is used for building 64-bit AMD64 |
| 31 | (aka x86_64 or EM64T) binaries, output into the amd64 sub-directory. |
| 32 | The Itanium (IA-64) platform is no longer supported. |
| 33 | |
| 34 | Four configuration options are supported by the solution: |
| 35 | Debug |
| 36 | Used to build Python with extra debugging capabilities, equivalent |
| 37 | to using ./configure --with-pydebug on UNIX. All binaries built |
| 38 | using this configuration have "_d" added to their name: |
| 39 | python37_d.dll, python_d.exe, parser_d.pyd, and so on. Both the |
| 40 | build and rt (run test) batch files in this directory accept a -d |
| 41 | option for debug builds. If you are building Python to help with |
| 42 | development of CPython, you will most likely use this configuration. |
| 43 | PGInstrument, PGUpdate |
| 44 | Used to build Python in Release configuration using PGO, which |
| 45 | requires Premium Edition of Visual Studio. See the "Profile |
| 46 | Guided Optimization" section below for more information. Build |
| 47 | output from each of these configurations lands in its own |
| 48 | sub-directory of this directory. The official Python releases may |
| 49 | be built using these configurations. |
| 50 | Release |
| 51 | Used to build Python as it is meant to be used in production |
| 52 | settings, though without PGO. |
| 53 | |
| 54 | |
| 55 | Building Python using the build.bat script |
| 56 | ---------------------------------------------- |
| 57 | |
| 58 | In this directory you can find build.bat, a script designed to make |
| 59 | building Python on Windows simpler. This script will use the env.bat |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 60 | script to detect either Visual Studio 2017 or 2015, either of |
| 61 | which may be used to build Python. Currently Visual Studio 2017 is |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 62 | officially supported. |
| 63 | |
| 64 | By default, build.bat will build Python in Release configuration for |
| 65 | the 32-bit Win32 platform. It accepts several arguments to change |
| 66 | this behavior, try `build.bat -h` to learn more. |
| 67 | |
| 68 | |
| 69 | C Runtime |
| 70 | --------- |
| 71 | |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 72 | Visual Studio 2017 uses version 14.0 of the C runtime (vcruntime140). |
| 73 | The executables no longer use the "Side by Side" assemblies used in |
| 74 | previous versions of the compiler. This simplifies distribution of |
| 75 | applications. |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 76 | |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 77 | The run time libraries are available under the redist folder of your |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 78 | Visual Studio distribution. For more info, see the Readme in the |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 79 | redist folder. |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 80 | |
| 81 | |
| 82 | Sub-Projects |
| 83 | ------------ |
| 84 | |
| 85 | The CPython project is split up into several smaller sub-projects which |
| 86 | are managed by the pcbuild.sln solution file. Each sub-project is |
| 87 | represented by a .vcxproj and a .vcxproj.filters file starting with the |
| 88 | name of the sub-project. These sub-projects fall into a few general |
| 89 | categories: |
| 90 | |
| 91 | The following sub-projects represent the bare minimum required to build |
| 92 | a functioning CPython interpreter. If nothing else builds but these, |
| 93 | you'll have a very limited but usable python.exe: |
| 94 | pythoncore |
| 95 | .dll and .lib |
| 96 | python |
| 97 | .exe |
| 98 | |
| 99 | These sub-projects provide extra executables that are useful for running |
| 100 | CPython in different ways: |
| 101 | pythonw |
| 102 | pythonw.exe, a variant of python.exe that doesn't open a Command |
| 103 | Prompt window |
| 104 | pylauncher |
| 105 | py.exe, the Python Launcher for Windows, see |
| 106 | http://docs.python.org/3/using/windows.html#launcher |
| 107 | pywlauncher |
| 108 | pyw.exe, a variant of py.exe that doesn't open a Command Prompt |
| 109 | window |
| 110 | _testembed |
| 111 | _testembed.exe, a small program that embeds Python for testing |
| 112 | purposes, used by test_capi.py |
| 113 | |
| 114 | These are miscellaneous sub-projects that don't really fit the other |
| 115 | categories: |
| 116 | _freeze_importlib |
| 117 | _freeze_importlib.exe, used to regenerate Python\importlib.h after |
| 118 | changes have been made to Lib\importlib\_bootstrap.py |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 119 | pyshellext |
| 120 | pyshellext.dll, the shell extension deployed with the launcher |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 121 | python3dll |
| 122 | python3.dll, the PEP 384 Stable ABI dll |
| 123 | xxlimited |
| 124 | builds an example module that makes use of the PEP 384 Stable ABI, |
| 125 | see Modules\xxlimited.c |
| 126 | |
| 127 | The following sub-projects are for individual modules of the standard |
| 128 | library which are implemented in C; each one builds a DLL (renamed to |
| 129 | .pyd) of the same name as the project: |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 130 | _asyncio |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 131 | _ctypes |
| 132 | _ctypes_test |
| 133 | _decimal |
| 134 | _elementtree |
| 135 | _hashlib |
| 136 | _msi |
| 137 | _multiprocessing |
| 138 | _overlapped |
| 139 | _socket |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 140 | _testbuffer |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 141 | _testcapi |
| 142 | _testconsole |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 143 | _testimportmultiple |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 144 | _testmultiphase |
| 145 | _tkinter |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 146 | pyexpat |
| 147 | select |
| 148 | unicodedata |
| 149 | winsound |
| 150 | |
| 151 | The following Python-controlled sub-projects wrap external projects. |
| 152 | Note that these external libraries are not necessary for a working |
| 153 | interpreter, but they do implement several major features. See the |
| 154 | "Getting External Sources" section below for additional information |
| 155 | about getting the source for building these libraries. The sub-projects |
| 156 | are: |
| 157 | _bz2 |
| 158 | Python wrapper for version 1.0.6 of the libbzip2 compression library |
| 159 | Homepage: |
| 160 | http://www.bzip.org/ |
| 161 | _lzma |
Zachary Ware | 51599e2 | 2017-06-15 22:08:51 -0500 | [diff] [blame] | 162 | Python wrapper for version 5.2.2 of the liblzma compression library |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 163 | Homepage: |
| 164 | http://tukaani.org/xz/ |
| 165 | _ssl |
| 166 | Python wrapper for version 1.0.2k of the OpenSSL secure sockets |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 167 | library, which is downloaded from our binaries repository at |
| 168 | https://github.com/python/cpython-bin-deps. |
| 169 | |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 170 | Homepage: |
| 171 | http://www.openssl.org/ |
| 172 | |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 173 | Building OpenSSL requires Perl on your path, and can be performed by |
| 174 | running PCbuild\prepare_ssl.bat. This will retrieve the version of |
| 175 | the sources matched to the current commit from the OpenSSL branch |
| 176 | in our source repository at |
| 177 | https://github.com/python/cpython-source-deps. |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 178 | |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 179 | To use an alternative build of OpenSSL completely, you should replace |
| 180 | the files in the externals/openssl-bin-<version> folder with your own. |
| 181 | As long as this folder exists, its contents will not be downloaded |
| 182 | again when building. |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 183 | |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 184 | _sqlite3 |
| 185 | Wraps SQLite 3.14.2.0, which is itself built by sqlite3.vcxproj |
| 186 | Homepage: |
| 187 | http://www.sqlite.org/ |
| 188 | _tkinter |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 189 | Wraps version 8.6.6 of the Tk windowing system, which is downloaded |
| 190 | from our binaries repository at |
| 191 | https://github.com/python/cpython-bin-deps. |
| 192 | |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 193 | Homepage: |
| 194 | http://www.tcl.tk/ |
| 195 | |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 196 | Building Tcl and Tk can be performed by running |
| 197 | PCbuild\prepare_tcltk.bat. This will retrieve the version of the |
| 198 | sources matched to the current commit from the Tcl and Tk branches |
| 199 | in our source repository at |
| 200 | https://github.com/python/cpython-source-deps. |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 201 | |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 202 | The two projects install their respective components in a |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 203 | directory alongside the source directories called "tcltk" on |
| 204 | Win32 and "tcltk64" on x64. They also copy the Tcl and Tk DLLs |
| 205 | into the current output directory, which should ensure that Tkinter |
| 206 | is able to load Tcl/Tk without having to change your PATH. |
| 207 | |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 208 | |
| 209 | Getting External Sources |
| 210 | ------------------------ |
| 211 | |
| 212 | The last category of sub-projects listed above wrap external projects |
| 213 | Python doesn't control, and as such a little more work is required in |
| 214 | order to download the relevant source files for each project before they |
| 215 | can be built. However, a simple script is provided to make this as |
| 216 | painless as possible, called "get_externals.bat" and located in this |
| 217 | directory. This script extracts all the external sub-projects from |
Zachary Ware | 51599e2 | 2017-06-15 22:08:51 -0500 | [diff] [blame] | 218 | https://github.com/python/cpython-source-deps |
| 219 | and |
| 220 | https://github.com/python/cpython-bin-deps |
| 221 | via a Python script called "get_external.py", located in this directory. |
| 222 | If Python 3.6 or later is not available via the "py.exe" launcher, the |
| 223 | path or command to use for Python can be provided in the PYTHON_FOR_BUILD |
| 224 | environment variable, or get_externals.bat will download the latest |
| 225 | version of NuGet and use it to download the latest "pythonx86" package |
| 226 | for use with get_external.py. Everything downloaded by these scripts is |
| 227 | stored in ..\externals (relative to this directory). |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 228 | |
| 229 | It is also possible to download sources from each project's homepage, |
| 230 | though you may have to change folder names or pass the names to MSBuild |
| 231 | as the values of certain properties in order for the build solution to |
| 232 | find them. This is an advanced topic and not necessarily fully |
| 233 | supported. |
| 234 | |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 235 | The get_externals.bat script is called automatically by build.bat |
| 236 | unless you pass the '-E' option. |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 237 | |
| 238 | |
| 239 | Profile Guided Optimization |
| 240 | --------------------------- |
| 241 | |
| 242 | The solution has two configurations for PGO. The PGInstrument |
| 243 | configuration must be built first. The PGInstrument binaries are linked |
| 244 | against a profiling library and contain extra debug information. The |
| 245 | PGUpdate configuration takes the profiling data and generates optimized |
| 246 | binaries. |
| 247 | |
| 248 | The build_pgo.bat script automates the creation of optimized binaries. |
| 249 | It creates the PGI files, runs the unit test suite or PyBench with the |
| 250 | PGI python, and finally creates the optimized files. |
| 251 | |
| 252 | See |
| 253 | http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.140).aspx |
| 254 | for more on this topic. |
| 255 | |
| 256 | |
| 257 | Static library |
| 258 | -------------- |
| 259 | |
| 260 | The solution has no configuration for static libraries. However it is |
| 261 | easy to build a static library instead of a DLL. You simply have to set |
| 262 | the "Configuration Type" to "Static Library (.lib)" and alter the |
| 263 | preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may |
| 264 | also have to change the "Runtime Library" from "Multi-threaded DLL |
| 265 | (/MD)" to "Multi-threaded (/MT)". |
| 266 | |
| 267 | |
| 268 | Visual Studio properties |
| 269 | ------------------------ |
| 270 | |
| 271 | The PCbuild solution makes use of Visual Studio property files (*.props) |
| 272 | to simplify each project. The properties can be viewed in the Property |
| 273 | Manager (View -> Other Windows -> Property Manager) but should be |
| 274 | carefully modified by hand. |
| 275 | |
| 276 | The property files used are: |
| 277 | * python (versions, directories and build names) |
| 278 | * pyproject (base settings for all projects) |
Steve Dower | bab21fa | 2017-09-07 20:10:29 -0700 | [diff] [blame] | 279 | * openssl (used by projects dependent upon OpenSSL) |
Zachary Ware | 6b6e687 | 2017-06-10 14:58:42 -0500 | [diff] [blame] | 280 | * tcltk (used by _tkinter, tcl, tk and tix projects) |
| 281 | |
| 282 | The pyproject property file defines all of the build settings for each |
| 283 | project, with some projects overriding certain specific values. The GUI |
| 284 | doesn't always reflect the correct settings and may confuse the user |
| 285 | with false information, especially for settings that automatically adapt |
| 286 | for diffirent configurations. |