From 97a7d7d93e7a61757dd261a32fe16830cdfc105b Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 1 Jun 2021 11:12:16 -0400 Subject: [PATCH 1/4] binary-extensions: update Windows instructions --- source/guides/packaging-binary-extensions.rst | 57 +++++++------------ 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/source/guides/packaging-binary-extensions.rst b/source/guides/packaging-binary-extensions.rst index 2a5a5ea87..00b317ce7 100644 --- a/source/guides/packaging-binary-extensions.rst +++ b/source/guides/packaging-binary-extensions.rst @@ -240,43 +240,26 @@ that you have a suitable compiler available. On Windows, Visual C is used to build the official CPython interpreter, and should be used to build compatible binary extensions. -Python 2.7 used Visual Studio 2008, Python 3.3 and 3.4 used Visual Studio 2010, -and Python 3.5+ uses Visual Studio 2015 or later. Unfortunately, older versions of -Visual Studio are no longer easily available from Microsoft, so for versions -of Python prior to 3.5, the compilers must be obtained differently if you do -not already have a copy of the relevant version of Visual Studio. - -To set up a build environment for binary extensions, the steps are as follows: - - For Python 2.7 - - 1. Install "Visual C++ Compiler Package for Python 2.7", - which is available from - `Microsoft's website `__. - 2. Use (a recent version of) setuptools in your setup.py (pip will - do this for you, in any case). - 3. Done. - - For Python 3.4 - - 1. Install "Windows SDK for Windows 7 and .NET Framework 4" (v7.1), - which is available from - `Microsoft's website `__. - 2. Work from an SDK command prompt (with the environment variables - set, and the SDK on PATH). - 3. Set DISTUTILS_USE_SDK=1 - 4. Done. - - For Python 3.5 - - 1. Install `Visual Studio 2015 Community Edition - `__ - (or any later version, when these are released). - 2. Done. - -Note that from Python 3.5 onwards, Visual Studio works in a backward -compatible way, which means that any future version of Visual Studio will -be able to build Python extensions for all Python versions from 3.5 onwards. +Python 2.7 used Visual Studio 2008, and Python 3.5+ uses Visual Studio 2015 or +later; since 2015 Microsoft has kept backward compatibility (with one exception, +listed below). Unfortunately, older versions of Visual Studio are no longer +available from Microsoft, so building for CPython < 3.5 is discouraged. If you do +need to build for older versions, you can set ``DISTUTILS_USE_SDK=1`` and +``MSSdk=1`` to force a the currently activated version of MSVC to be found, +and you should exercize care when designing your extension not to malloc/free +memory across different libraries, avoid relying on changed data structures, +and so on. Tools for generating extension modules usually avoid these things +for you. + +To set up a build environment for binary extensions, install +`Visual Studio Community Edition `__ - any +recent version is fine. + +One caveat; if you use MSVC 2019+, your extension will depend on an "extra" +file, `VCRUNTIME140_1.dll`, in addition to the `VCRUNTIME140.dll` all previous +verisions back to 2015 depend on. This will add an extra requirement to using +your extension on versions of CPython that do not include this extra file; you +can add the compile-time argument ``/d2FH4-`` to avoid this link on 2019+. Building with the recommended compiler on Windows ensures that a compatible C library is used throughout the Python process. From 9b728ac03b61726ae1dd19252ad9e0c25480e035 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 1 Jun 2021 11:18:54 -0400 Subject: [PATCH 2/4] fix: markdown syntax, oops! --- source/guides/packaging-binary-extensions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/guides/packaging-binary-extensions.rst b/source/guides/packaging-binary-extensions.rst index 00b317ce7..edf76253a 100644 --- a/source/guides/packaging-binary-extensions.rst +++ b/source/guides/packaging-binary-extensions.rst @@ -256,7 +256,7 @@ To set up a build environment for binary extensions, install recent version is fine. One caveat; if you use MSVC 2019+, your extension will depend on an "extra" -file, `VCRUNTIME140_1.dll`, in addition to the `VCRUNTIME140.dll` all previous +file, ``VCRUNTIME140_1.dll``, in addition to the ``VCRUNTIME140.dll`` all previous verisions back to 2015 depend on. This will add an extra requirement to using your extension on versions of CPython that do not include this extra file; you can add the compile-time argument ``/d2FH4-`` to avoid this link on 2019+. From 1e1f90d497bea0ad65346339c72064435f619f86 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 28 Jun 2021 09:31:29 -0400 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Brian Rutledge --- source/guides/packaging-binary-extensions.rst | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/source/guides/packaging-binary-extensions.rst b/source/guides/packaging-binary-extensions.rst index edf76253a..f033f9f63 100644 --- a/source/guides/packaging-binary-extensions.rst +++ b/source/guides/packaging-binary-extensions.rst @@ -240,13 +240,11 @@ that you have a suitable compiler available. On Windows, Visual C is used to build the official CPython interpreter, and should be used to build compatible binary extensions. -Python 2.7 used Visual Studio 2008, and Python 3.5+ uses Visual Studio 2015 or -later; since 2015 Microsoft has kept backward compatibility (with one exception, -listed below). Unfortunately, older versions of Visual Studio are no longer -available from Microsoft, so building for CPython < 3.5 is discouraged. If you do +Building for Python prior to 3.5 is discouraged, because older versions of +Visual Studio are no longer available from Microsoft. If you do need to build for older versions, you can set ``DISTUTILS_USE_SDK=1`` and ``MSSdk=1`` to force a the currently activated version of MSVC to be found, -and you should exercize care when designing your extension not to malloc/free +and you should exercise care when designing your extension not to malloc/free memory across different libraries, avoid relying on changed data structures, and so on. Tools for generating extension modules usually avoid these things for you. @@ -255,14 +253,12 @@ To set up a build environment for binary extensions, install `Visual Studio Community Edition `__ - any recent version is fine. -One caveat; if you use MSVC 2019+, your extension will depend on an "extra" -file, ``VCRUNTIME140_1.dll``, in addition to the ``VCRUNTIME140.dll`` all previous +One caveat: if you use Visual Studio 2019 or later, your extension will depend on an "extra" +file, ``VCRUNTIME140_1.dll``, in addition to the ``VCRUNTIME140.dll`` that all previous verisions back to 2015 depend on. This will add an extra requirement to using -your extension on versions of CPython that do not include this extra file; you -can add the compile-time argument ``/d2FH4-`` to avoid this link on 2019+. +your extension on versions of CPython that do not include this extra file. To +avoid this, you can add the compile-time argument ``/d2FH4-``. -Building with the recommended compiler on Windows ensures that a compatible C library -is used throughout the Python process. Binary extensions for Linux --------------------------- From 13943ccb2ab724a7662edf10d39564b21e19a465 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 28 Jun 2021 10:06:54 -0400 Subject: [PATCH 4/4] docs(compile): reorder a bit --- source/guides/packaging-binary-extensions.rst | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/source/guides/packaging-binary-extensions.rst b/source/guides/packaging-binary-extensions.rst index f033f9f63..7da258e3f 100644 --- a/source/guides/packaging-binary-extensions.rst +++ b/source/guides/packaging-binary-extensions.rst @@ -238,26 +238,26 @@ Binary extensions for Windows Before it is possible to build a binary extension, it is necessary to ensure that you have a suitable compiler available. On Windows, Visual C is used to build the official CPython interpreter, and should be used to build compatible -binary extensions. +binary extensions. To set up a build environment for binary extensions, install +`Visual Studio Community Edition `__ +- any recent version is fine. + +One caveat: if you use Visual Studio 2019 or later, your extension will depend +on an "extra" file, ``VCRUNTIME140_1.dll``, in addition to the +``VCRUNTIME140.dll`` that all previous versions back to 2015 depend on. This +will add an extra requirement to using your extension on versions of CPython +that do not include this extra file. To avoid this, you can add the +compile-time argument ``/d2FH4-``. Recent versions of Python may include this +file. Building for Python prior to 3.5 is discouraged, because older versions of -Visual Studio are no longer available from Microsoft. If you do -need to build for older versions, you can set ``DISTUTILS_USE_SDK=1`` and -``MSSdk=1`` to force a the currently activated version of MSVC to be found, -and you should exercise care when designing your extension not to malloc/free -memory across different libraries, avoid relying on changed data structures, -and so on. Tools for generating extension modules usually avoid these things -for you. - -To set up a build environment for binary extensions, install -`Visual Studio Community Edition `__ - any -recent version is fine. - -One caveat: if you use Visual Studio 2019 or later, your extension will depend on an "extra" -file, ``VCRUNTIME140_1.dll``, in addition to the ``VCRUNTIME140.dll`` that all previous -verisions back to 2015 depend on. This will add an extra requirement to using -your extension on versions of CPython that do not include this extra file. To -avoid this, you can add the compile-time argument ``/d2FH4-``. +Visual Studio are no longer available from Microsoft. If you do need to build +for older versions, you can set ``DISTUTILS_USE_SDK=1`` and ``MSSdk=1`` to +force a the currently activated version of MSVC to be found, and you should +exercise care when designing your extension not to malloc/free memory across +different libraries, avoid relying on changed data structures, and so on. Tools +for generating extension modules usually avoid these things for you. + Binary extensions for Linux