Skip to content

Commit 191c537

Browse files
committed
windows: look for different pyport.h content
Python 3.8 changed the content slightly. So we need to handle a variant of the search string. With this change, we get most of the way through a Python 3.8 static build only to be stumped by missing symbols in libffi.
1 parent 6a29576 commit 191c537

File tree

1 file changed

+63
-2
lines changed

1 file changed

+63
-2
lines changed

cpython-windows/build.py

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,61 @@ def hack_project_files(
890890
)
891891

892892

893-
PYPORT_EXPORT_SEARCH = b"""
893+
PYPORT_EXPORT_SEARCH_NEW = b"""
894+
#if defined(__CYGWIN__)
895+
# define HAVE_DECLSPEC_DLL
896+
#endif
897+
898+
/* only get special linkage if built as shared or platform is Cygwin */
899+
#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
900+
# if defined(HAVE_DECLSPEC_DLL)
901+
# if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
902+
# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
903+
# define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
904+
/* module init functions inside the core need no external linkage */
905+
/* except for Cygwin to handle embedding */
906+
# if defined(__CYGWIN__)
907+
# define PyMODINIT_FUNC __declspec(dllexport) PyObject*
908+
# else /* __CYGWIN__ */
909+
# define PyMODINIT_FUNC PyObject*
910+
# endif /* __CYGWIN__ */
911+
# else /* Py_BUILD_CORE */
912+
/* Building an extension module, or an embedded situation */
913+
/* public Python functions and data are imported */
914+
/* Under Cygwin, auto-import functions to prevent compilation */
915+
/* failures similar to those described at the bottom of 4.1: */
916+
/* http://docs.python.org/extending/windows.html#a-cookbook-approach */
917+
# if !defined(__CYGWIN__)
918+
# define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
919+
# endif /* !__CYGWIN__ */
920+
# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
921+
/* module init functions outside the core must be exported */
922+
# if defined(__cplusplus)
923+
# define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject*
924+
# else /* __cplusplus */
925+
# define PyMODINIT_FUNC __declspec(dllexport) PyObject*
926+
# endif /* __cplusplus */
927+
# endif /* Py_BUILD_CORE */
928+
# endif /* HAVE_DECLSPEC_DLL */
929+
#endif /* Py_ENABLE_SHARED */
930+
931+
/* If no external linkage macros defined by now, create defaults */
932+
#ifndef PyAPI_FUNC
933+
# define PyAPI_FUNC(RTYPE) RTYPE
934+
#endif
935+
#ifndef PyAPI_DATA
936+
# define PyAPI_DATA(RTYPE) extern RTYPE
937+
#endif
938+
#ifndef PyMODINIT_FUNC
939+
# if defined(__cplusplus)
940+
# define PyMODINIT_FUNC extern "C" PyObject*
941+
# else /* __cplusplus */
942+
# define PyMODINIT_FUNC PyObject*
943+
# endif /* __cplusplus */
944+
#endif
945+
"""
946+
947+
PYPORT_EXPORT_SEARCH_OLD = b"""
894948
#if defined(__CYGWIN__)
895949
# define HAVE_DECLSPEC_DLL
896950
#endif
@@ -978,7 +1032,14 @@ def hack_source_files(source_path: pathlib.Path, static: bool):
9781032
# dynamically linked. This is a useful property to have.
9791033
if static:
9801034
pyport_h = source_path / "Include" / "pyport.h"
981-
static_replace_in_file(pyport_h, PYPORT_EXPORT_SEARCH, PYPORT_EXPORT_REPLACE)
1035+
try:
1036+
static_replace_in_file(
1037+
pyport_h, PYPORT_EXPORT_SEARCH_NEW, PYPORT_EXPORT_REPLACE
1038+
)
1039+
except NoSearchStringError:
1040+
static_replace_in_file(
1041+
pyport_h, PYPORT_EXPORT_SEARCH_OLD, PYPORT_EXPORT_REPLACE
1042+
)
9821043

9831044
# Modules/_winapi.c and Modules/overlapped.c both define an
9841045
# ``OverlappedType`` symbol. We rename one to make the symbol conflict

0 commit comments

Comments
 (0)