aboutsummaryrefslogtreecommitdiff
path: root/vcpkg/ports/python2
diff options
context:
space:
mode:
authorEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
committerEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
commit54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch)
treed915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/ports/python2
move to own git serverHEADmaster
Diffstat (limited to 'vcpkg/ports/python2')
-rw-r--r--vcpkg/ports/python2/001-build-msvc.patch199
-rw-r--r--vcpkg/ports/python2/002-build-msvc.patch228
-rw-r--r--vcpkg/ports/python2/003-build-msvc.patch234
-rw-r--r--vcpkg/ports/python2/004-static-library-msvc.patch39
-rw-r--r--vcpkg/ports/python2/005-static-crt-msvc.patch15
-rw-r--r--vcpkg/ports/python2/006-static-fix-headers.patch14
-rw-r--r--vcpkg/ports/python2/007-fix-build-path.patch14
-rw-r--r--vcpkg/ports/python2/008-bz2d.patch19
-rw-r--r--vcpkg/ports/python2/portfile.cmake155
-rw-r--r--vcpkg/ports/python2/vcpkg.json16
10 files changed, 933 insertions, 0 deletions
diff --git a/vcpkg/ports/python2/001-build-msvc.patch b/vcpkg/ports/python2/001-build-msvc.patch
new file mode 100644
index 0000000..c1749b7
--- /dev/null
+++ b/vcpkg/ports/python2/001-build-msvc.patch
@@ -0,0 +1,199 @@
+diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
+index 86a85c1..65a60b5 100644
+--- a/Lib/distutils/command/build_ext.py
++++ b/Lib/distutils/command/build_ext.py
+@@ -193,7 +193,7 @@ class build_ext (Command):
+ # Append the source distribution include and library directories,
+ # this allows distutils on windows to work in the source tree
+ self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
+- if MSVC_VERSION == 9:
++ if MSVC_VERSION >= 9:
+ # Use the .lib files for the correct architecture
+ if self.plat_name == 'win32':
+ suffix = ''
+diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py
+index 33d3e51..9fe6417 100644
+--- a/Lib/distutils/msvc9compiler.py
++++ b/Lib/distutils/msvc9compiler.py
+@@ -662,11 +662,12 @@ class MSVCCompiler(CCompiler) :
+ if mfinfo is not None:
+ mffilename, mfid = mfinfo
+ out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
+- try:
+- self.spawn(['mt.exe', '-nologo', '-manifest',
+- mffilename, out_arg])
+- except DistutilsExecError, msg:
+- raise LinkError(msg)
++ if self.__version < 10:
++ try:
++ self.spawn(['mt.exe', '-nologo', '-manifest',
++ mffilename, out_arg])
++ except DistutilsExecError, msg:
++ raise LinkError(msg)
+ else:
+ log.debug("skipping %s (up-to-date)", output_filename)
+
+diff --git a/PC/dl_nt.c b/PC/dl_nt.c
+index 3e58bac..cad9de5 100644
+--- a/PC/dl_nt.c
++++ b/PC/dl_nt.c
+@@ -18,6 +18,7 @@ char dllVersionBuffer[16] = ""; // a private buffer
+ HMODULE PyWin_DLLhModule = NULL;
+ const char *PyWin_DLLVersionString = dllVersionBuffer;
+
++#if HAVE_SXS
+ // Windows "Activation Context" work:
+ // Our .pyd extension modules are generally built without a manifest (ie,
+ // those included with Python and those built with a default distutils.
+@@ -29,6 +30,8 @@ const char *PyWin_DLLVersionString = dllVersionBuffer;
+ // As an added complication, this magic only works on XP or later - we simply
+ // use the existence (or not) of the relevant function pointers from kernel32.
+ // See bug 4566 (http://python.org/sf/4566) for more details.
++// In Visual Studio 2010, side by side assemblies are no longer used by
++// default.
+
+ typedef BOOL (WINAPI * PFN_GETCURRENTACTCTX)(HANDLE *);
+ typedef BOOL (WINAPI * PFN_ACTIVATEACTCTX)(HANDLE, ULONG_PTR *);
+@@ -75,6 +78,7 @@ void _Py_DeactivateActCtx(ULONG_PTR cookie)
+ if (!(*pfnDeactivateActCtx)(0, cookie))
+ OutputDebugString("Python failed to de-activate the activation context\n");
+ }
++#endif /* HAVE_SXS */
+
+ BOOL WINAPI DllMain (HANDLE hInst,
+ ULONG ul_reason_for_call,
+@@ -87,6 +91,7 @@ BOOL WINAPI DllMain (HANDLE hInst,
+ // 1000 is a magic number I picked out of the air. Could do with a #define, I spose...
+ LoadString(hInst, 1000, dllVersionBuffer, sizeof(dllVersionBuffer));
+
++#if HAVE_SXS
+ // and capture our activation context for use when loading extensions.
+ _LoadActCtxPointers();
+ if (pfnGetCurrentActCtx && pfnAddRefActCtx)
+@@ -98,12 +103,15 @@ BOOL WINAPI DllMain (HANDLE hInst,
+ "activation context\n");
+ return FALSE;
+ }
++#endif
+ break;
+
+ case DLL_PROCESS_DETACH:
++#if HAVE_SXS
+ if (pfnReleaseActCtx)
+ (*pfnReleaseActCtx)(PyWin_DLLhActivationContext);
++#endif
+ break;
+ }
+ return TRUE;
+ }
+diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c
+index 44c82e4..091957e 100644
+--- a/PC/msvcrtmodule.c
++++ b/PC/msvcrtmodule.c
+@@ -25,6 +25,8 @@
+ #ifdef _MSC_VER
+ #if _MSC_VER >= 1500 && _MSC_VER < 1600
+ #include <crtassem.h>
++#elif _MSC_VER >= 1600
++#include <crtversion.h>
+ #endif
+ #endif
+
+@@ -398,7 +400,7 @@ PyMODINIT_FUNC
+ initmsvcrt(void)
+ {
+ int st;
+- PyObject *d;
++ PyObject *d, *version;
+ PyObject *m = Py_InitModule("msvcrt", msvcrt_functions);
+ if (m == NULL)
+ return;
+@@ -412,6 +414,7 @@ initmsvcrt(void)
+ insertint(d, "LK_UNLCK", _LK_UNLCK);
+
+ /* constants for the crt versions */
++ (void)st;
+ #ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN
+ st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN",
+ _VC_ASSEMBLY_PUBLICKEYTOKEN);
+@@ -427,4 +430,13 @@ initmsvcrt(void)
+ __LIBRARIES_ASSEMBLY_NAME_PREFIX);
+ if (st < 0)return;
+ #endif
++/* constants for the 2010 crt versions */
++#if defined(_VC_CRT_MAJOR_VERSION) && defined (_VC_CRT_MINOR_VERSION) && defined(_VC_CRT_BUILD_VERSION) && defined(_VC_CRT_RBUILD_VERSION)
++ version = PyUnicode_FromFormat("%d.%d.%d.%d", _VC_CRT_MAJOR_VERSION,
++ _VC_CRT_MINOR_VERSION,
++ _VC_CRT_BUILD_VERSION,
++ _VC_CRT_RBUILD_VERSION);
++ st = PyModule_AddObject(m, "CRT_ASSEMBLY_VERSION", version);
++ if (st < 0) return NULL;
++#endif
+ }
+diff --git a/PC/pyconfig.h b/PC/pyconfig.h
+index 5fa6398..0cbd236 100644
+--- a/PC/pyconfig.h
++++ b/PC/pyconfig.h
+@@ -226,14 +226,19 @@ typedef int pid_t;
+ #define Py_IS_FINITE(X) _finite(X)
+ #define copysign _copysign
+
+-#endif /* _MSC_VER */
++/* Side by Side assemblies supported in VS 2005 and VS 2008 but not 2010*/
++#if _MSC_VER >= 1400 && _MSC_VER < 1600
++#define HAVE_SXS 1
++#endif
+
+ /* define some ANSI types that are not defined in earlier Win headers */
+-#if defined(_MSC_VER) && _MSC_VER >= 1200
++#if _MSC_VER >= 1200
+ /* This file only exists in VC 6.0 or higher */
+ #include <basetsd.h>
+ #endif
+
++#endif /* _MSC_VER */
++
+ /* ------------------------------------------------------------------------*/
+ /* The Borland compiler defines __BORLANDC__ */
+ /* XXX These defines are likely incomplete, but should be easy to fix. */
+diff --git a/Python/dynload_win.c b/Python/dynload_win.c
+index 4e5555e..8626642 100644
+--- a/Python/dynload_win.c
++++ b/Python/dynload_win.c
+@@ -12,8 +12,10 @@
+ #include <windows.h>
+
+ // "activation context" magic - see dl_nt.c...
++#if HAVE_SXS
+ extern ULONG_PTR _Py_ActivateActCtx();
+ void _Py_DeactivateActCtx(ULONG_PTR cookie);
++#endif
+
+ const struct filedescr _PyImport_DynLoadFiletab[] = {
+ #ifdef _DEBUG
+@@ -176,7 +178,9 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
+ char pathbuf[260];
+ LPTSTR dummy;
+ unsigned int old_mode;
++#if HAVE_SXS
+ ULONG_PTR cookie = 0;
++#endif
+ /* We use LoadLibraryEx so Windows looks for dependent DLLs
+ in directory of pathname first. However, Windows95
+ can sometimes not work correctly unless the absolute
+@@ -190,11 +194,15 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
+ sizeof(pathbuf),
+ pathbuf,
+ &dummy)) {
++#if HAVE_SXS
+ ULONG_PTR cookie = _Py_ActivateActCtx();
++#endif
+ /* XXX This call doesn't exist in Windows CE */
+ hDLL = LoadLibraryEx(pathname, NULL,
+ LOAD_WITH_ALTERED_SEARCH_PATH);
++#if HAVE_SXS
+ _Py_DeactivateActCtx(cookie);
++#endif
+ }
+
+ /* restore old error mode settings */
diff --git a/vcpkg/ports/python2/002-build-msvc.patch b/vcpkg/ports/python2/002-build-msvc.patch
new file mode 100644
index 0000000..c214ab2
--- /dev/null
+++ b/vcpkg/ports/python2/002-build-msvc.patch
@@ -0,0 +1,228 @@
+diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
+index ab10ec5..6c43d82 100644
+--- a/Lib/ctypes/util.py
++++ b/Lib/ctypes/util.py
+@@ -19,6 +19,8 @@ if os.name == "nt":
+ i = i + len(prefix)
+ s, rest = sys.version[i:].split(" ", 1)
+ majorVersion = int(s[:-2]) - 6
++ if majorVersion >= 13:
++ majorVersion += 1
+ minorVersion = int(s[2:3]) / 10.0
+ # I don't think paths are affected by minor version in version 6
+ if majorVersion == 6:
+@@ -36,8 +38,10 @@ if os.name == "nt":
+ return None
+ if version <= 6:
+ clibname = 'msvcrt'
+- else:
++ elif version <= 13:
+ clibname = 'msvcr%d' % (version * 10)
++ else:
++ clibname = 'appcrt%d' % (version * 10)
+
+ # If python was built with in debug mode
+ import imp
+diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
+index 65a60b5..b2ee260 100644
+--- a/Lib/distutils/command/build_ext.py
++++ b/Lib/distutils/command/build_ext.py
+@@ -196,7 +196,7 @@ class build_ext (Command):
+ if MSVC_VERSION >= 9:
+ # Use the .lib files for the correct architecture
+ if self.plat_name == 'win32':
+- suffix = ''
++ suffix = 'win32'
+ else:
+ # win-amd64 or win-ia64
+ suffix = self.plat_name[4:]
+diff --git a/Lib/distutils/msvc9compiler.py b/Lib/distutils/msvc9compiler.py
+index 9fe6417..57d42b7 100644
+--- a/Lib/distutils/msvc9compiler.py
++++ b/Lib/distutils/msvc9compiler.py
+@@ -182,6 +182,9 @@ def get_build_version():
+ i = i + len(prefix)
+ s, rest = sys.version[i:].split(" ", 1)
+ majorVersion = int(s[:-2]) - 6
++ if majorVersion >= 13:
++ # v13 was skipped and should be v14
++ majorVersion += 1
+ minorVersion = int(s[2:3]) / 10.0
+ # I don't think paths are affected by minor version in version 6
+ if majorVersion == 6:
+diff --git a/Lib/distutils/msvccompiler.py b/Lib/distutils/msvccompiler.py
+index 0e69fd3..77025c6 100644
+--- a/Lib/distutils/msvccompiler.py
++++ b/Lib/distutils/msvccompiler.py
+@@ -164,6 +164,9 @@ def get_build_version():
+ i = i + len(prefix)
+ s, rest = sys.version[i:].split(" ", 1)
+ majorVersion = int(s[:-2]) - 6
++ if majorVersion >= 13:
++ # v13 was skipped and should be v14
++ majorVersion += 1
+ minorVersion = int(s[2:3]) / 10.0
+ # I don't think paths are affected by minor version in version 6
+ if majorVersion == 6:
+diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
+index 7a1a694..7d07150 100644
+--- a/Modules/posixmodule.c
++++ b/Modules/posixmodule.c
+@@ -558,15 +558,33 @@ _PyInt_FromDev(PY_LONG_LONG v)
+ /* The actual size of the structure is determined at runtime.
+ * Only the first items must be present.
+ */
++
++#if _MSC_VER >= 1900
++
++typedef struct {
++ CRITICAL_SECTION lock;
++ intptr_t osfhnd;
++ __int64 startpos;
++ char osfile;
++} my_ioinfo;
++
++#define IOINFO_L2E 6
++#define IOINFO_ARRAYS 128
++
++#else
++
+ typedef struct {
+ intptr_t osfhnd;
+ char osfile;
+ } my_ioinfo;
+
+-extern __declspec(dllimport) char * __pioinfo[];
+ #define IOINFO_L2E 5
+-#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
+ #define IOINFO_ARRAYS 64
++
++#endif
++
++extern __declspec(dllimport) char * __pioinfo[];
++#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
+ #define _NHANDLE_ (IOINFO_ARRAYS * IOINFO_ARRAY_ELTS)
+ #define FOPEN 0x01
+ #define _NO_CONSOLE_FILENO (intptr_t)-2
+diff --git a/Modules/timemodule.c b/Modules/timemodule.c
+index 61b8d61..7678283 100644
+--- a/Modules/timemodule.c
++++ b/Modules/timemodule.c
+@@ -808,7 +808,7 @@ inittimezone(PyObject *m) {
+ #ifdef PYOS_OS2
+ PyModule_AddIntConstant(m, "timezone", _timezone);
+ #else /* !PYOS_OS2 */
+- PyModule_AddIntConstant(m, "timezone", timezone);
++ PyModule_AddIntConstant(m, "timezone", _timezone);
+ #endif /* PYOS_OS2 */
+ #ifdef HAVE_ALTZONE
+ PyModule_AddIntConstant(m, "altzone", altzone);
+@@ -816,7 +816,7 @@ inittimezone(PyObject *m) {
+ #ifdef PYOS_OS2
+ PyModule_AddIntConstant(m, "altzone", _timezone-3600);
+ #else /* !PYOS_OS2 */
+- PyModule_AddIntConstant(m, "altzone", timezone-3600);
++ PyModule_AddIntConstant(m, "altzone", _timezone-3600);
+ #endif /* PYOS_OS2 */
+ #endif
+ PyModule_AddIntConstant(m, "daylight", daylight);
+diff --git a/PC/bdist_wininst/install.c b/PC/bdist_wininst/install.c
+index e3b52a8..a7d1c2c 100644
+--- a/PC/bdist_wininst/install.c
++++ b/PC/bdist_wininst/install.c
+@@ -1185,7 +1185,7 @@ static void CenterWindow(HWND hwnd)
+
+ #include <prsht.h>
+
+-BOOL CALLBACK
++INT_PTR CALLBACK
+ IntroDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+ {
+ LPNMHDR lpnm;
+@@ -1534,7 +1534,7 @@ SCHEME *GetScheme(int major, int minor)
+ return old_scheme;
+ }
+
+-BOOL CALLBACK
++INT_PTR CALLBACK
+ SelectPythonDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+ {
+ LPNMHDR lpnm;
+@@ -1836,7 +1836,7 @@ static void CloseLogfile(void)
+ fclose(logfile);
+ }
+
+-BOOL CALLBACK
++INT_PTR CALLBACK
+ InstallFilesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+ {
+ LPNMHDR lpnm;
+@@ -1991,7 +1991,7 @@ InstallFilesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+ }
+
+
+-BOOL CALLBACK
++INT_PTR CALLBACK
+ FinishedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+ {
+ LPNMHDR lpnm;
+@@ -2167,23 +2167,6 @@ BOOL NeedAutoUAC()
+ return TRUE;
+ }
+
+-// Returns TRUE if the platform supports UAC.
+-BOOL PlatformSupportsUAC()
+-{
+- // Note that win2k does seem to support ShellExecute with 'runas',
+- // but does *not* support IsUserAnAdmin - so we just pretend things
+- // only work on XP and later.
+- BOOL bIsWindowsXPorLater;
+- OSVERSIONINFO winverinfo;
+- winverinfo.dwOSVersionInfoSize = sizeof(winverinfo);
+- if (!GetVersionEx(&winverinfo))
+- return FALSE; // something bad has gone wrong
+- bIsWindowsXPorLater =
+- ( (winverinfo.dwMajorVersion > 5) ||
+- ( (winverinfo.dwMajorVersion == 5) && (winverinfo.dwMinorVersion >= 1) ));
+- return bIsWindowsXPorLater;
+-}
+-
+ // Spawn ourself as an elevated application. On failure, a message is
+ // displayed to the user - but this app will always terminate, even
+ // on error.
+@@ -2239,7 +2222,7 @@ int DoInstall(void)
+
+ // See if we need to do the Vista UAC magic.
+ if (strcmp(user_access_control, "force")==0) {
+- if (PlatformSupportsUAC() && !MyIsUserAnAdmin()) {
++ if (!MyIsUserAnAdmin()) {
+ SpawnUAC();
+ return 0;
+ }
+@@ -2247,7 +2230,7 @@ int DoInstall(void)
+ } else if (strcmp(user_access_control, "auto")==0) {
+ // Check if it looks like we need UAC control, based
+ // on how Python itself was installed.
+- if (PlatformSupportsUAC() && !MyIsUserAnAdmin() && NeedAutoUAC()) {
++ if (!MyIsUserAnAdmin() && NeedAutoUAC()) {
+ SpawnUAC();
+ return 0;
+ }
+diff --git a/PC/pyconfig.h b/PC/pyconfig.h
+index 0cbd236..d896a38 100644
+--- a/PC/pyconfig.h
++++ b/PC/pyconfig.h
+@@ -226,6 +226,13 @@ typedef int pid_t;
+ #define Py_IS_FINITE(X) _finite(X)
+ #define copysign _copysign
+
++/* VS 2015 defines these names with a leading underscore */
++#if _MSC_VER >= 1900
++// #define timezone _timezone
++#define daylight _daylight
++#define tzname _tzname
++#endif
++
+ /* Side by Side assemblies supported in VS 2005 and VS 2008 but not 2010*/
+ #if _MSC_VER >= 1400 && _MSC_VER < 1600
+ #define HAVE_SXS 1
diff --git a/vcpkg/ports/python2/003-build-msvc.patch b/vcpkg/ports/python2/003-build-msvc.patch
new file mode 100644
index 0000000..71d5569
--- /dev/null
+++ b/vcpkg/ports/python2/003-build-msvc.patch
@@ -0,0 +1,234 @@
+From 00164b4a9821e82f513183035587bea9243a7d5e Mon Sep 17 00:00:00 2001
+From: Jean-Christophe Fillion-Robin <jchris.fillionr@kitware.com>
+Date: Tue, 1 Aug 2017 14:13:24 -0400
+Subject: [PATCH 3/3] VS2015 Support: Backport of "Issue #23524: Replace
+ _PyVerify_fd function with calling
+ _set_thread_local_invalid_parameter_handler on every thread."
+
+This commit is a partial backport of python/cpython@d81431f. It was
+originally designed to work with python-cmake-buildsystem.
+
+Implementation of "_PyVerify_fd" in "Python/fileutils.c" found only in
+Python 3.x has been copied into "Modules/posixmodule.c"
+
+The following modules have NOT been backported:
+
+* PCbuild
+---
+ Modules/posixmodule.c | 54 +++++++++++++++++++++++-------------------
+ PC/invalid_parameter_handler.c | 22 +++++++++++++++++
+ Python/pystate.c | 12 ++++++++++
+ PCbuild/pythoncore.vcxproj | 1 +
+ PCbuild/pythoncore.vcxproj.filters | 1 +
+ 5 files changed, 65 insertions(+), 26 deletions(-)
+ create mode 100644 PC/invalid_parameter_handler.c
+
+diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
+index 90d5318..6a180a0 100644
+--- a/Modules/posixmodule.c
++++ b/Modules/posixmodule.c
+@@ -277,6 +277,7 @@ extern int lstat(const char *, struct stat *);
+ #include "osdefs.h"
+ #include <malloc.h>
+ #include <windows.h>
++#include <malloc.h>
+ #include <shellapi.h> /* for ShellExecute() */
+ #define popen _popen
+ #define pclose _pclose
+@@ -535,8 +534,28 @@ _PyInt_FromDev(PY_LONG_LONG v)
+ # define _PyInt_FromDev PyInt_FromLong
+ #endif
+
++#ifdef _MSC_VER
++#if _MSC_VER >= 1900
++
++/* This function lets the Windows CRT validate the file handle without
++ terminating the process if it's invalid. */
++int
++_PyVerify_fd(int fd)
++{
++ intptr_t osh;
++ /* Fast check for the only condition we know */
++ if (fd < 0) {
++ _set_errno(EBADF);
++ return 0;
++ }
++ osh = _get_osfhandle(fd);
++ return osh != (intptr_t)-1;
++}
++
++#define _PyVerify_fd_dup2(fd1, fd2) (_PyVerify_fd(fd1) && (fd2) >= 0)
++
++#elif _MSC_VER >= 1400
+
+-#if defined _MSC_VER && _MSC_VER >= 1400
+ /* Microsoft CRT in VS2005 and higher will verify that a filehandle is
+ * valid and raise an assertion if it isn't.
+ * Normally, an invalid fd is likely to be a C program error and therefore
+@@ -601,35 +580,18 @@ _PyInt_FromDev(PY_LONG_LONG v)
+ * Only the first items must be present.
+ */
+
+-#if _MSC_VER >= 1900
+-
+-typedef struct {
+- CRITICAL_SECTION lock;
+- intptr_t osfhnd;
+- __int64 startpos;
+- char osfile;
+-} my_ioinfo;
+-
+-#define IOINFO_L2E 6
+-#define IOINFO_ARRAYS 128
+-
+-#else
+-
+ typedef struct {
+ intptr_t osfhnd;
+ char osfile;
+ } my_ioinfo;
+
+-#define IOINFO_L2E 5
+-#define IOINFO_ARRAYS 64
+-
+-#endif
+-
+ extern __declspec(dllimport) char * __pioinfo[];
+ #define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
+ #define _NHANDLE_ (IOINFO_ARRAYS * IOINFO_ARRAY_ELTS)
+ #define FOPEN 0x01
+ #define _NO_CONSOLE_FILENO (intptr_t)-2
++#define IOINFO_L2E 5
++#define IOINFO_ARRAYS 64
+
+ /* This function emulates what the windows CRT does to validate file handles */
+ int
+@@ -653,6 +649,8 @@ _PyVerify_fd_dup2(int fd1, int fd2)
+ #define _PyVerify_fd_dup2(A, B) (1)
+ #endif
+
++#endif /* defined _MSC_VER */
++
+ /* Return a dictionary corresponding to the POSIX environment table */
+ #if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED))
+ /* On Darwin/MacOSX a shared library or framework has no access to
+@@ -1260,14 +1254,10 @@ win32_fstat(int file_number, struct win32_stat *result)
+
+ h = (HANDLE)_get_osfhandle(file_number);
+
+- /* Protocol violation: we explicitly clear errno, instead of
+- setting it to a POSIX error. Callers should use GetLastError. */
+ errno = 0;
+
+ if (h == INVALID_HANDLE_VALUE) {
+- /* This is really a C library error (invalid file handle).
+- We set the Win32 error to the closes one matching. */
+- SetLastError(ERROR_INVALID_HANDLE);
++ errno = EBADF;
+ return -1;
+ }
+ memset(result, 0, sizeof(*result));
+@@ -1268,6 +1266,7 @@ win32_fstat(int file_number, struct win32_stat *result)
+ if (type == FILE_TYPE_UNKNOWN) {
+ DWORD error = GetLastError();
+ if (error != 0) {
++ errno = EINVAL;
+ return -1;
+ }
+ /* else: valid but unknown file */
+@@ -1284,6 +1281,7 @@ win32_fstat(int file_number, struct win32_stat *result)
+ }
+
+ if (!GetFileInformationByHandle(h, &info)) {
++ errno = EINVAL;
+ return -1;
+ }
+
+diff --git a/PC/invalid_parameter_handler.c b/PC/invalid_parameter_handler.c
+new file mode 100644
+index 0000000..3bc0104
+--- /dev/null
++++ b/PC/invalid_parameter_handler.c
+@@ -0,0 +1,22 @@
++#ifdef _MSC_VER
++
++#include <stdlib.h>
++
++#if _MSC_VER >= 1900
++/* pyconfig.h uses this function in the _Py_BEGIN/END_SUPPRESS_IPH
++ * macros. It does not need to be defined when building using MSVC
++ * earlier than 14.0 (_MSC_VER == 1900).
++ */
++
++static void __cdecl _silent_invalid_parameter_handler(
++ wchar_t const* expression,
++ wchar_t const* function,
++ wchar_t const* file,
++ unsigned int line,
++ uintptr_t pReserved) { }
++
++void *_Py_silent_invalid_parameter_handler =
++ (void*)_silent_invalid_parameter_handler;
++#endif
++
++#endif
+diff --git a/Python/pystate.c b/Python/pystate.c
+index eb992c1..1c0f970 100644
+--- a/Python/pystate.c
++++ b/Python/pystate.c
+@@ -22,6 +22,12 @@ the expense of doing their own locking).
+ #endif
+ #endif
+
++#if defined _MSC_VER && _MSC_VER >= 1900
++/* Issue #23524: Temporary fix to disable termination due to invalid parameters */
++PyAPI_DATA(void*) _Py_silent_invalid_parameter_handler;
++#include <stdlib.h>
++#endif
++
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+@@ -202,6 +208,12 @@ new_threadstate(PyInterpreterState *interp, int init)
+ tstate->next = interp->tstate_head;
+ interp->tstate_head = tstate;
+ HEAD_UNLOCK();
++
++#if defined _MSC_VER && _MSC_VER >= 1900
++ /* Issue #23524: Temporary fix to disable termination due to invalid parameters */
++ _set_thread_local_invalid_parameter_handler((_invalid_parameter_handler)_Py_silent_invalid_parameter_handler);
++#endif
++
+ }
+
+ return tstate;
+--
+2.5.0
+
+diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
+index 99291ea..af17762 100644
+--- a/PCbuild/pythoncore.vcxproj
++++ b/PCbuild/pythoncore.vcxproj
+@@ -333,6 +333,7 @@
+ <ClCompile Include="..\Parser\parser.c" />
+ <ClCompile Include="..\Parser\parsetok.c" />
+ <ClCompile Include="..\Parser\tokenizer.c" />
++ <ClCompile Include="..\PC\invalid_parameter_handler.c" />
+ <ClCompile Include="..\PC\_subprocess.c" />
+ <ClCompile Include="..\PC\_winreg.c" />
+ <ClCompile Include="..\PC\config.c" />
+
+diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters
+index 99291ea..af17762 100644
+--- a/PCbuild/pythoncore.vcxproj.filters
++++ b/PCbuild/pythoncore.vcxproj.filters
+@@ -794,6 +794,9 @@
+ <ClCompile Include="..\Parser\tokenizer.c">
+ <Filter>Parser</Filter>
+ </ClCompile>
++ <ClCompile Include="..\PC\invalid_parameter_handler.c">
++ <Filter>PC</Filter>
++ </ClCompile>
+ <ClCompile Include="..\PC\_subprocess.c">
+ <Filter>PC</Filter>
+ </ClCompile>
diff --git a/vcpkg/ports/python2/004-static-library-msvc.patch b/vcpkg/ports/python2/004-static-library-msvc.patch
new file mode 100644
index 0000000..a002de6
--- /dev/null
+++ b/vcpkg/ports/python2/004-static-library-msvc.patch
@@ -0,0 +1,39 @@
+diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
+index 92b32da..8dac984 100644
+--- a/PCbuild/pythoncore.vcxproj
++++ b/PCbuild/pythoncore.vcxproj
+@@ -41,7 +41,7 @@
+ <Import Project="python.props" />
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Label="Configuration">
+- <ConfigurationType>DynamicLibrary</ConfigurationType>
++ <ConfigurationType>StaticLibrary</ConfigurationType>
+ <UseOfMfc>false</UseOfMfc>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+@@ -70,12 +70,24 @@
+ <ClCompile>
+ <AdditionalOptions>/Zm200 %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalIncludeDirectories>$(PySourcePath)Python;$(PySourcePath)Modules\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+- <PreprocessorDefinitions>_USRDLL;Py_BUILD_CORE;Py_ENABLE_SHARED;_CRT_SECURE_NO_WARNINGS;MS_DLL_ID="$(SysWinVer)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
++ <PreprocessorDefinitions>_USRDLL;Py_BUILD_CORE;Py_NO_ENABLE_SHARED;_CRT_SECURE_NO_WARNINGS;MS_DLL_ID="$(SysWinVer)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ClCompile>
+ <Link>
+ <AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <BaseAddress>0x1e000000</BaseAddress>
+ </Link>
++ <Lib>
++ <TargetMachine Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">MachineX86</TargetMachine>
++ </Lib>
++ <Lib>
++ <TargetMachine Condition="'$(Configuration)|$(Platform)'=='PGInstrument|Win32'">MachineX86</TargetMachine>
++ </Lib>
++ <Lib>
++ <TargetMachine Condition="'$(Configuration)|$(Platform)'=='PGUpdate|Win32'">MachineX86</TargetMachine>
++ </Lib>
++ <Lib>
++ <TargetMachine Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MachineX86</TargetMachine>
++ </Lib>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="..\Include\abstract.h" />
diff --git a/vcpkg/ports/python2/005-static-crt-msvc.patch b/vcpkg/ports/python2/005-static-crt-msvc.patch
new file mode 100644
index 0000000..bd254f7
--- /dev/null
+++ b/vcpkg/ports/python2/005-static-crt-msvc.patch
@@ -0,0 +1,15 @@
+diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
+index 8dac984..c18ad1e 100644
+--- a/PCbuild/pythoncore.vcxproj
++++ b/PCbuild/pythoncore.vcxproj
+@@ -71,6 +71,10 @@
+ <AdditionalOptions>/Zm200 %(AdditionalOptions)</AdditionalOptions>
+ <AdditionalIncludeDirectories>$(PySourcePath)Python;$(PySourcePath)Modules\zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>_USRDLL;Py_BUILD_CORE;Py_NO_ENABLE_SHARED;_CRT_SECURE_NO_WARNINGS;MS_DLL_ID="$(SysWinVer)";%(PreprocessorDefinitions)</PreprocessorDefinitions>
++ <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">MultiThreadedDebug</RuntimeLibrary>
++ <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">MultiThreadedDebug</RuntimeLibrary>
++ <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MultiThreaded</RuntimeLibrary>
++ <RuntimeLibrary Condition="'$(Configuration)|$(Platform)'=='Release|x64'">MultiThreaded</RuntimeLibrary>
+ </ClCompile>
+ <Link>
+ <AdditionalDependencies>ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
diff --git a/vcpkg/ports/python2/006-static-fix-headers.patch b/vcpkg/ports/python2/006-static-fix-headers.patch
new file mode 100644
index 0000000..9e3030b
--- /dev/null
+++ b/vcpkg/ports/python2/006-static-fix-headers.patch
@@ -0,0 +1,14 @@
+diff --git a/PC/pyconfig.h b/PC/pyconfig.h
+index 64e7aec..aa36745 100644
+--- a/PC/pyconfig.h
++++ b/PC/pyconfig.h
+@@ -331,6 +331,7 @@ typedef int pid_t;
+
+ /* For Windows the Python core is in a DLL by default. Test
+ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
++#define Py_NO_ENABLE_SHARED
+ #if !defined(MS_NO_COREDLL) && !defined(Py_NO_ENABLE_SHARED)
+ # define Py_ENABLE_SHARED 1 /* standard symbol for shared library */
+ # define MS_COREDLL /* deprecated old symbol */
+--
+
diff --git a/vcpkg/ports/python2/007-fix-build-path.patch b/vcpkg/ports/python2/007-fix-build-path.patch
new file mode 100644
index 0000000..5dc4633
--- /dev/null
+++ b/vcpkg/ports/python2/007-fix-build-path.patch
@@ -0,0 +1,14 @@
+diff --git a/PCbuild/python.props b/PCbuild/python.props
+index d2b1991..a22c054 100644
+--- a/PCbuild/python.props
++++ b/PCbuild/python.props
+@@ -26,8 +26,7 @@
+ <PySourcePath Condition="!HasTrailingSlash($(PySourcePath))">$(PySourcePath)\</PySourcePath>
+
+ <!-- Directory where build outputs are put -->
+- <BuildPath Condition="'$(BuildPath)' == ''">$(PySourcePath)PCBuild\</BuildPath>
+- <BuildPath Condition="'$(ArchName)' != 'win32'">$(BuildPath)\$(ArchName)\</BuildPath>
++ <BuildPath Condition="'$(BuildPath)' == ''">$(PySourcePath)PCBuild\$(ArchName)\</BuildPath>
+ <BuildPath Condition="!HasTrailingSlash($(BuildPath))">$(BuildPath)\</BuildPath>
+
+ <!-- Directories of external projects. tcltk is handled in tcltk.props -->
diff --git a/vcpkg/ports/python2/008-bz2d.patch b/vcpkg/ports/python2/008-bz2d.patch
new file mode 100644
index 0000000..88ec740
--- /dev/null
+++ b/vcpkg/ports/python2/008-bz2d.patch
@@ -0,0 +1,19 @@
+diff --git a/setup.py b/setup.py
+index f764223..d6a58e4 100644
+--- a/setup.py
++++ b/setup.py
+@@ -1506,6 +1506,14 @@ class PyBuildExt(build_ext):
+ exts.append( Extension('bz2', ['bz2module.c'],
+ libraries = ['bz2'],
+ extra_link_args = bz2_extra_link_args) )
++ elif (self.compiler.find_library_file(lib_dirs, 'bz2d')):
++ if host_platform == "darwin":
++ bz2_extra_link_args = ('-Wl,-search_paths_first',)
++ else:
++ bz2_extra_link_args = ()
++ exts.append( Extension('bz2', ['bz2module.c'],
++ libraries=['bz2d'],
++ extra_link_args = bz2_extra_link_args) )
+ else:
+ missing.append('bz2')
+
diff --git a/vcpkg/ports/python2/portfile.cmake b/vcpkg/ports/python2/portfile.cmake
new file mode 100644
index 0000000..a822803
--- /dev/null
+++ b/vcpkg/ports/python2/portfile.cmake
@@ -0,0 +1,155 @@
+# Patches are from:
+# - https://github.com/python-cmake-buildsystem/python-cmake-buildsystem/tree/master/patches/2.7.13/Windows-MSVC/1900
+# - https://github.com/Microsoft/vcpkg/tree/master/ports/python3
+
+if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic AND VCPKG_CRT_LINKAGE STREQUAL static)
+ message(STATUS "Warning: Dynamic library with static CRT is not supported. Building static library.")
+ set(VCPKG_LIBRARY_LINKAGE static)
+endif()
+
+set(PYTHON_VERSION_MAJOR 2)
+set(PYTHON_VERSION_MINOR 7)
+set(PYTHON_VERSION_PATCH 18)
+set(PYTHON_VERSION ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH})
+
+set(_PYTHON_PATCHES "")
+if (VCPKG_TARGET_IS_WINDOWS)
+ list(APPEND _PYTHON_PATCHES
+ "${CMAKE_CURRENT_LIST_DIR}/001-build-msvc.patch"
+ "${CMAKE_CURRENT_LIST_DIR}/002-build-msvc.patch"
+ "${CMAKE_CURRENT_LIST_DIR}/003-build-msvc.patch"
+ )
+endif()
+
+if (VCPKG_LIBRARY_LINKAGE STREQUAL static)
+ list(APPEND _PYTHON_PATCHES
+ "${CMAKE_CURRENT_LIST_DIR}/004-static-library-msvc.patch"
+ "${CMAKE_CURRENT_LIST_DIR}/006-static-fix-headers.patch"
+ )
+endif()
+if (VCPKG_CRT_LINKAGE STREQUAL static)
+ list(APPEND _PYTHON_PATCHES "${CMAKE_CURRENT_LIST_DIR}/005-static-crt-msvc.patch")
+endif()
+
+if (VCPKG_TARGET_IS_WINDOWS)
+ list(APPEND _PYTHON_PATCHES
+ "${CMAKE_CURRENT_LIST_DIR}/007-fix-build-path.patch"
+ )
+else()
+ list(APPEND _PYTHON_PATCHES
+ "${CMAKE_CURRENT_LIST_DIR}/008-bz2d.patch"
+ )
+endif()
+
+
+vcpkg_download_distfile(ARCHIVE
+ URLS https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
+ FILENAME Python-${PYTHON_VERSION}.tar.xz
+ SHA512 a7bb62b51f48ff0b6df0b18f5b0312a523e3110f49c3237936bfe56ed0e26838c0274ff5401bda6fc21bf24337477ccac49e8026c5d651e4b4cafb5eb5086f6c
+)
+
+vcpkg_extract_source_archive(
+ SOURCE_PATH
+ ARCHIVE "${ARCHIVE}"
+ PATCHES ${_PYTHON_PATCHES}
+)
+
+vcpkg_replace_string("${SOURCE_PATH}/Makefile.pre.in" "$(INSTALL) -d -m $(DIRMODE)" "$(MKDIR_P)")
+
+if (VCPKG_TARGET_IS_WINDOWS)
+ if (VCPKG_TARGET_ARCHITECTURE MATCHES "x86")
+ set(BUILD_ARCH "Win32")
+ set(OUT_DIR "win32")
+ elseif (VCPKG_TARGET_ARCHITECTURE MATCHES "x64")
+ set(BUILD_ARCH "x64")
+ set(OUT_DIR "amd64")
+ else()
+ message(FATAL_ERROR "Unsupported architecture: ${VCPKG_TARGET_ARCHITECTURE}")
+ endif()
+
+ vcpkg_msbuild_install(
+ SOURCE_PATH "${SOURCE_PATH}"
+ PROJECT_SUBPATH "PCBuild/pythoncore.vcxproj"
+ PLATFORM ${BUILD_ARCH}
+ )
+
+ vcpkg_copy_pdbs()
+
+ file(GLOB HEADERS "${SOURCE_PATH}/Include/*.h")
+ file(COPY ${HEADERS} "${SOURCE_PATH}/PC/pyconfig.h" DESTINATION "${CURRENT_PACKAGES_DIR}/include/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
+
+ file(COPY "${SOURCE_PATH}/Lib" DESTINATION "${CURRENT_PACKAGES_DIR}/share/python${PYTHON_VERSION_MAJOR}")
+
+ file(COPY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/PCBuild/${OUT_DIR}/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}.lib" DESTINATION "${CURRENT_PACKAGES_DIR}/lib")
+ if(NOT VCPKG_BUILD_TYPE)
+ file(COPY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/PCBuild/${OUT_DIR}/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}_d.lib" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib")
+ endif()
+ if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
+ file(COPY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/PCBuild/${OUT_DIR}/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}.dll" DESTINATION "${CURRENT_PACKAGES_DIR}/bin")
+ if(NOT VCPKG_BUILD_TYPE)
+ file(COPY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/PCBuild/${OUT_DIR}/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}_d.dll" DESTINATION "${CURRENT_PACKAGES_DIR}/debug/bin")
+ endif()
+ endif()
+else()
+ vcpkg_configure_make(
+ SOURCE_PATH "${SOURCE_PATH}"
+ )
+
+ vcpkg_install_make()
+ vcpkg_fixup_pkgconfig()
+
+ file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share")
+endif()
+
+if (NOT VCPKG_TARGET_IS_WINDOWS)
+ foreach(lib_suffix IN ITEMS "" "/debug")
+ set(python_config_file "${CURRENT_PACKAGES_DIR}${lib_suffix}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/_sysconfigdata.py")
+ if(NOT EXISTS "${python_config_file}")
+ continue()
+ endif()
+
+ file(READ "${python_config_file}" contents)
+
+ string(PREPEND contents "import os\n_base = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))\n")
+ # make contents a list of lines
+ string(REPLACE ";" "\\;" old_contents "${contents}")
+ string(REGEX REPLACE "\r?\n" ";" old_contents "${contents}")
+
+ set(new_contents "")
+ foreach(line IN LISTS old_contents)
+ if(line MATCHES "\"")
+ string(REGEX REPLACE
+ "${CURRENT_PACKAGES_DIR}|${CURRENT_INSTALLED_DIR}"
+ "\" + _base + \""
+ line
+ "${line}"
+ )
+ string(REGEX REPLACE
+ "\"[^\"]*${CURRENT_BUILDTREES_DIR}[^\"]*\""
+ "''"
+ line
+ "${line}"
+ )
+ else()
+ string(REGEX REPLACE
+ "${CURRENT_PACKAGES_DIR}|${CURRENT_INSTALLED_DIR}"
+ "' + _base + '"
+ line
+ "${line}"
+ )
+ string(REGEX REPLACE
+ "'[^']*${CURRENT_BUILDTREES_DIR}[^']*'"
+ "''"
+ line
+ "${line}"
+ )
+ endif()
+ list(APPEND new_contents "${line}")
+ endforeach()
+
+ list(JOIN new_contents "\n" contents)
+ file(WRITE "${python_config_file}" "${contents}")
+ endforeach()
+endif()
+
+vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
diff --git a/vcpkg/ports/python2/vcpkg.json b/vcpkg/ports/python2/vcpkg.json
new file mode 100644
index 0000000..efd3c6d
--- /dev/null
+++ b/vcpkg/ports/python2/vcpkg.json
@@ -0,0 +1,16 @@
+{
+ "name": "python2",
+ "version": "2.7.18",
+ "port-version": 7,
+ "description": "The Python programming language as an embeddable library",
+ "homepage": "https://www.python.org",
+ "license": "Python-2.0",
+ "supports": "!(arm & osx) & !(arm & windows) & !uwp",
+ "dependencies": [
+ {
+ "name": "vcpkg-msbuild",
+ "host": true,
+ "platform": "windows"
+ }
+ ]
+}