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