Skip to content

Commit c82f746

Browse files
authored
[python3] add features for readline and extensions (#41183)
1 parent d062724 commit c82f746

9 files changed

+125
-32
lines changed
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/configure.ac b/configure.ac
2+
index ef899b881d..9ed1836608 100644
3+
--- a/configure.ac
4+
+++ b/configure.ac
5+
@@ -6712,7 +6712,7 @@ done
6+
7+
# check if OpenSSL libraries work as expected
8+
WITH_SAVE_ENV([
9+
- LIBS="$LIBS $OPENSSL_LIBS"
10+
+ LIBS="$OPENSSL_LIBS $LIBS"
11+
CFLAGS="$CFLAGS $OPENSSL_INCLUDES"
12+
LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH"
13+
14+
@@ -6737,7 +6737,7 @@ WITH_SAVE_ENV([
15+
])
16+
17+
WITH_SAVE_ENV([
18+
- LIBS="$LIBS $LIBCRYPTO_LIBS"
19+
+ LIBS="$LIBCRYPTO_LIBS $LIBS"
20+
CFLAGS="$CFLAGS $OPENSSL_INCLUDES"
21+
LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS $OPENSSL_LDFLAGS_RPATH"
22+

ports/python3/portfile.cmake

+29-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic AND VCPKG_CRT_LINKAGE STREQUAL static
33
set(VCPKG_LIBRARY_LINKAGE static)
44
endif()
55

6+
if("extensions" IN_LIST FEATURES)
7+
if(VCPKG_TARGET_IS_WINDOWS)
8+
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)
9+
endif()
10+
set(PYTHON_HAS_EXTENSIONS ON)
11+
else()
12+
set(PYTHON_HAS_EXTENSIONS OFF)
13+
endif()
14+
615
if(NOT VCPKG_HOST_IS_WINDOWS)
716
message(WARNING "${PORT} currently requires the following programs from the system package manager:
817
autoconf automake autoconf-archive
@@ -35,6 +44,7 @@ set(PATCHES
3544
0015-dont-use-WINDOWS-def.patch
3645
0016-undup-ffi-symbols.patch # Required for lld-link.
3746
0018-fix-sysconfig-include.patch
47+
0019-fix-ssl-linkage.patch
3848
)
3949

4050
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
@@ -57,6 +67,10 @@ endif()
5767

5868
if(VCPKG_TARGET_IS_WINDOWS)
5969
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" PYTHON_ALLOW_EXTENSIONS)
70+
if(PYTHON_HAS_EXTENSIONS AND NOT PYTHON_ALLOW_EXTENSIONS)
71+
# This should never be reached due to vcpkg_check_linkage above
72+
message(FATAL_ERROR "Cannot build python extensions! Python extensions on windows can only be built if python is a dynamic library!")
73+
endif()
6074
# The Windows 11 SDK has a problem that causes it to error on the resource files, so we patch that.
6175
vcpkg_get_windows_sdk(WINSDK_VERSION)
6276
if("${WINSDK_VERSION}" VERSION_GREATER_EQUAL "10.0.22000")
@@ -102,7 +116,7 @@ endfunction()
102116
if(VCPKG_TARGET_IS_WINDOWS)
103117
# Due to the way Python handles C extension modules on Windows, a static python core cannot
104118
# load extension modules.
105-
if(PYTHON_ALLOW_EXTENSIONS)
119+
if(PYTHON_HAS_EXTENSIONS)
106120
find_library(BZ2_RELEASE NAMES bz2 PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH)
107121
find_library(BZ2_DEBUG NAMES bz2d PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH)
108122
find_library(CRYPTO_RELEASE NAMES libcrypto PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH)
@@ -120,7 +134,7 @@ if(VCPKG_TARGET_IS_WINDOWS)
120134
list(APPEND add_libs_rel "${BZ2_RELEASE};${EXPAT_RELEASE};${FFI_RELEASE};${LZMA_RELEASE};${SQLITE_RELEASE}")
121135
list(APPEND add_libs_dbg "${BZ2_DEBUG};${EXPAT_DEBUG};${FFI_DEBUG};${LZMA_DEBUG};${SQLITE_DEBUG}")
122136
else()
123-
message(STATUS "WARNING: Static builds of Python will not have C extension modules available.")
137+
message(STATUS "WARNING: Extensions have been disabled. No C extension modules will be available.")
124138
endif()
125139
find_library(ZLIB_RELEASE NAMES zlib PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH)
126140
find_library(ZLIB_DEBUG NAMES zlib zlibd PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH)
@@ -136,7 +150,7 @@ if(VCPKG_TARGET_IS_WINDOWS)
136150
)
137151

138152
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS "-DVCPKG_SET_CHARSET_FLAG=OFF")
139-
if(PYTHON_ALLOW_EXTENSIONS)
153+
if(PYTHON_HAS_EXTENSIONS)
140154
set(OPTIONS
141155
"/p:IncludeExtensions=true"
142156
"/p:IncludeExternals=true"
@@ -189,7 +203,7 @@ if(VCPKG_TARGET_IS_WINDOWS)
189203
endif()
190204

191205
# The extension modules must be placed in the DLLs directory, so we can't use vcpkg_copy_tools()
192-
if(PYTHON_ALLOW_EXTENSIONS)
206+
if(PYTHON_HAS_EXTENSIONS)
193207
file(GLOB_RECURSE PYTHON_EXTENSIONS_RELEASE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/*.pyd")
194208
file(COPY ${PYTHON_EXTENSIONS_RELEASE} DESTINATION "${CURRENT_PACKAGES_DIR}/bin")
195209
file(COPY ${PYTHON_EXTENSIONS_RELEASE} DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}/DLLs")
@@ -257,13 +271,18 @@ else()
257271
"--without-ensurepip"
258272
"--with-suffix="
259273
"--with-system-expat"
260-
"--without-readline"
261274
"--disable-test-modules"
262275
)
263276
if(VCPKG_TARGET_IS_OSX)
264277
list(APPEND OPTIONS "LIBS=-liconv -lintl")
265278
endif()
266279

280+
if("readline" IN_LIST FEATURES)
281+
list(APPEND OPTIONS "--with-readline")
282+
else()
283+
list(APPEND OPTIONS "--without-readline")
284+
endif()
285+
267286
# The version of the build Python must match the version of the cross compiled host Python.
268287
# https://docs.python.org/3/using/configure.html#cross-compiling-options
269288
if(VCPKG_CROSSCOMPILING)
@@ -329,7 +348,7 @@ vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
329348

330349
file(READ "${CMAKE_CURRENT_LIST_DIR}/usage" usage)
331350
if(VCPKG_TARGET_IS_WINDOWS)
332-
if(PYTHON_ALLOW_EXTENSIONS)
351+
if(PYTHON_HAS_EXTENSIONS)
333352
file(READ "${CMAKE_CURRENT_LIST_DIR}/usage.win" usage_extra)
334353
else()
335354
set(usage_extra "")
@@ -384,10 +403,12 @@ else()
384403
file(COPY_FILE "${CURRENT_PACKAGES_DIR}/tools/python3/python3.${PYTHON_VERSION_MINOR}" "${CURRENT_PACKAGES_DIR}/tools/python3/python3")
385404
endif()
386405

387-
configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake" "${CURRENT_PACKAGES_DIR}/share/python3/vcpkg-port-config.cmake" @ONLY)
406+
configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake" "${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-port-config.cmake" @ONLY)
388407

389408
# For testing
390409
block()
410+
include("${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-port-config.cmake")
391411
set(CURRENT_HOST_INSTALLED_DIR "${CURRENT_PACKAGES_DIR}")
412+
set(CURRENT_INSTALLED_DIR "${CURRENT_PACKAGES_DIR}")
392413
vcpkg_get_vcpkg_installed_python(VCPKG_PYTHON3)
393-
endblocK()
414+
endblock()

ports/python3/vcpkg-port-config.cmake

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
include_guard(GLOBAL)
12
set(PYTHON3_VERSION "@VERSION@")
23
set(PYTHON3_VERSION_MAJOR "@PYTHON_VERSION_MAJOR@")
34
set(PYTHON3_VERSION_MINOR "@PYTHON_VERSION_MINOR@")
45
set(PYTHON3_INCLUDE "include/python${PYTHON3_VERSION_MAJOR}.${PYTHON3_VERSION_MINOR}")
6+
set(PYTHON3_HAS_EXTENSIONS "@PYTHON_HAS_EXTENSIONS@")
57
set(site_base "")
68
if(VCPKG_TARGET_IS_WINDOWS)
79
set(site_base "tools/python${PYTHON3_VERSION_MAJOR}/Lib")

ports/python3/vcpkg.json

+48-21
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,35 @@
11
{
22
"name": "python3",
33
"version": "3.11.8",
4-
"port-version": 4,
4+
"port-version": 5,
55
"description": "The Python programming language",
66
"homepage": "https://github.com/python/cpython",
77
"license": "Python-2.0",
88
"supports": "!uwp & !mingw",
99
"dependencies": [
10-
{
11-
"name": "bzip2",
12-
"platform": "!(windows & static)"
13-
},
14-
"expat",
1510
{
1611
"name": "gettext",
1712
"platform": "osx"
1813
},
19-
{
20-
"name": "libffi",
21-
"platform": "!(windows & static)"
22-
},
2314
{
2415
"name": "libiconv",
2516
"platform": "osx"
2617
},
27-
{
28-
"name": "liblzma",
29-
"platform": "!(windows & static)"
30-
},
3118
{
3219
"name": "libuuid",
3320
"platform": "!osx & !windows"
3421
},
35-
{
36-
"name": "openssl",
37-
"platform": "!(windows & static)"
38-
},
3922
{
4023
"name": "python3",
41-
"host": true
24+
"host": true,
25+
"default-features": false
4226
},
4327
{
44-
"name": "sqlite3",
45-
"platform": "!(windows & static)"
28+
"name": "python3",
29+
"features": [
30+
"extensions"
31+
],
32+
"platform": "!windows"
4633
},
4734
{
4835
"name": "vcpkg-get-python",
@@ -55,9 +42,49 @@
5542
},
5643
"zlib"
5744
],
45+
"default-features": [
46+
{
47+
"name": "extensions",
48+
"platform": "!(staticcrt & windows)"
49+
}
50+
],
5851
"features": {
5952
"deprecated-win7-support": {
6053
"description": "Deprecated support for the Windows 7 platform -- may be removed at any time."
54+
},
55+
"extensions": {
56+
"description": "Allow the build and usage of python extensions. On windows this requires python to be a dynamic library!",
57+
"supports": "!(staticcrt & windows)",
58+
"dependencies": [
59+
{
60+
"name": "bzip2",
61+
"default-features": false
62+
},
63+
{
64+
"name": "expat",
65+
"default-features": false
66+
},
67+
{
68+
"name": "libffi",
69+
"default-features": false
70+
},
71+
{
72+
"name": "liblzma",
73+
"default-features": false
74+
},
75+
{
76+
"name": "openssl",
77+
"default-features": false
78+
},
79+
{
80+
"name": "sqlite3",
81+
"default-features": false
82+
}
83+
]
84+
},
85+
"readline": {
86+
"description": "Build with readline. Requires system readline to be installed",
87+
"supports": "!windows"
6188
}
6289
}
6390
}

ports/vcpkg-get-python/vcpkg-port-config.cmake

+11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
include_guard(GLOBAL)
2+
13
function(vcpkg_get_vcpkg_installed_python out_python)
24
if(NOT VCPKG_TARGET_IS_WINDOWS)
35
# vcpkg installed python on !windows works as normal python would work.
46
set(${out_python} "${CURRENT_HOST_INSTALLED_DIR}/tools/python3/python3" PARENT_SCOPE)
57
return()
68
endif()
9+
if(DEFINED CACHE{z_vcpkg_get_vcpkg_installed_python})
10+
set(${out_python} "${z_vcpkg_get_vcpkg_installed_python}" PARENT_SCOPE)
11+
return()
12+
endif()
713

814
# On windows python is unable to lookup DLLs, so a manual venv is created
915
set(python_home "${CURRENT_HOST_INSTALLED_DIR}/tools/python3")
@@ -42,5 +48,10 @@ if vcpkg_bin_path.is_dir():
4248
"
4349
)
4450

51+
file(COPY "${CURRENT_INSTALLED_DIR}/${PYTHON3_INCLUDE}/" DESTINATION "${python_base}/include")
52+
set(suffix "PCBuild/AMD64") # TODO: ask python for the correct suffix.
53+
file(COPY "${CURRENT_INSTALLED_DIR}/lib/python${PYTHON3_VERSION_MAJOR}${PYTHON3_VERSION_MINOR}.lib" DESTINATION "${python_base}/${suffix}")
54+
4555
set(${out_python} "${python_base}/Scripts/python.exe" PARENT_SCOPE)
56+
set(z_vcpkg_get_vcpkg_installed_python "${python_base}/Scripts/python.exe" CACHE INTERNAL "")
4657
endfunction()

ports/vcpkg-get-python/vcpkg.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vcpkg-get-python",
3-
"version-date": "2024-06-08",
3+
"version-date": "2024-06-22",
44
"license": "MIT",
55
"supports": "native"
66
}

versions/baseline.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7258,7 +7258,7 @@
72587258
},
72597259
"python3": {
72607260
"baseline": "3.11.8",
7261-
"port-version": 4
7261+
"port-version": 5
72627262
},
72637263
"qca": {
72647264
"baseline": "2.3.7",
@@ -9293,7 +9293,7 @@
92939293
"port-version": 0
92949294
},
92959295
"vcpkg-get-python": {
9296-
"baseline": "2024-06-08",
9296+
"baseline": "2024-06-22",
92979297
"port-version": 0
92989298
},
92999299
"vcpkg-get-python-packages": {

versions/p-/python3.json

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"versions": [
3+
{
4+
"git-tree": "cd869d19271e7b865248145bb3e14093faa1b687",
5+
"version": "3.11.8",
6+
"port-version": 5
7+
},
38
{
49
"git-tree": "42da794facada8d85273d1efcc53f1af7e8cb243",
510
"version": "3.11.8",

versions/v-/vcpkg-get-python.json

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
{
22
"versions": [
3+
{
4+
"git-tree": "e1993fbd0925b052b31f62967690a2634cb952a2",
5+
"version-date": "2024-06-22",
6+
"port-version": 0
7+
},
38
{
49
"git-tree": "829be9eea1ad30190a8bb66e4c8a46c9c6d5b0f5",
510
"version-date": "2024-06-08",

0 commit comments

Comments
 (0)