From 47d39dc91e3c23b4a68be0973d72bf44ce5902e5 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 9 Sep 2025 14:17:52 -0500 Subject: [PATCH 1/9] Add support for Python_ARTIFACT_SUFFIX. --- ports/python3/portfile.cmake | 6 +-- ports/python3/vcpkg-cmake-wrapper.cmake | 70 ++++++++++++++----------- ports/python3/vcpkg.json | 2 +- 3 files changed, 43 insertions(+), 35 deletions(-) diff --git a/ports/python3/portfile.cmake b/ports/python3/portfile.cmake index 744e2541ba3cb7..4ab6c55ff81ecb 100644 --- a/ports/python3/portfile.cmake +++ b/ports/python3/portfile.cmake @@ -350,7 +350,7 @@ string(REPLACE "@PYTHON_VERSION_MINOR@" "${PYTHON_VERSION_MINOR}" usage_extra "$ file(WRITE "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" "${usage}\n${usage_extra}") function(_generate_finder) - cmake_parse_arguments(PythonFinder "NO_OVERRIDE" "DIRECTORY;PREFIX" "" ${ARGN}) + cmake_parse_arguments(PythonFinder "NO_OVERRIDE;SUPPORTS_ARTIFACTS_PREFIX" "DIRECTORY;PREFIX" "" ${ARGN}) configure_file( "${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" "${CURRENT_PACKAGES_DIR}/share/${PythonFinder_DIRECTORY}/vcpkg-cmake-wrapper.cmake" @@ -359,8 +359,8 @@ function(_generate_finder) endfunction() message(STATUS "Installing cmake wrappers") -_generate_finder(DIRECTORY "python" PREFIX "Python") -_generate_finder(DIRECTORY "python3" PREFIX "Python3") +_generate_finder(DIRECTORY "python" PREFIX "Python" SUPPORTS_ARTIFACTS_PREFIX) +_generate_finder(DIRECTORY "python3" PREFIX "Python3" SUPPORTS_ARTIFACTS_PREFIX) _generate_finder(DIRECTORY "pythoninterp" PREFIX "PYTHON" NO_OVERRIDE) if (NOT VCPKG_TARGET_IS_WINDOWS) diff --git a/ports/python3/vcpkg-cmake-wrapper.cmake b/ports/python3/vcpkg-cmake-wrapper.cmake index 5e73017bd2a8bb..3199657b2792e1 100644 --- a/ports/python3/vcpkg-cmake-wrapper.cmake +++ b/ports/python3/vcpkg-cmake-wrapper.cmake @@ -11,6 +11,13 @@ if(@PythonFinder_NO_OVERRIDE@) return() endif() +# CMake 4.0+ introduced Python_ARTIFACTS_PREFIX to add a suffix (yes, a suffix) +# to the results of find_package(Python), so we need to handle that here. +set(_PythonFinder_PREFIX "@PythonFinder_PREFIX@") +if(@PythonFinder_SUPPORTS_ARTIFACTS_PREFIX@ AND CMAKE_VERSION VERSION_GREATER_EQUAL 4.0) + string(APPEND _PythonFinder_PREFIX "${@PythonFinder_PREFIX@_ARTIFACTS_PREFIX}") +endif() + # CMake's FindPython's separation of concerns is very muddy. We only want to force vcpkg's Python # if the consumer is using the development component. What we don't want to do is break detection # of the system Python, which may have certain packages the user expects. But - if the user is @@ -33,7 +40,7 @@ endif() if(_PythonFinder_WantLibs) find_path( - _@PythonFinder_PREFIX@_INCLUDE_DIR + _${_PythonFinder_PREFIX}_INCLUDE_DIR NAMES "Python.h" PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include" PATH_SUFFIXES "python@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@" @@ -43,7 +50,7 @@ if(_PythonFinder_WantLibs) # Don't set the public facing hint or the finder will be unable to detect the debug library. # Internally, it uses the same value with an underscore prepended. find_library( - _@PythonFinder_PREFIX@_LIBRARY_RELEASE + _${_PythonFinder_PREFIX}_LIBRARY_RELEASE NAMES "python@PYTHON_VERSION_MAJOR@@PYTHON_VERSION_MINOR@" "python@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@" @@ -51,7 +58,7 @@ if(_PythonFinder_WantLibs) NO_DEFAULT_PATH ) find_library( - _@PythonFinder_PREFIX@_LIBRARY_DEBUG + _${_PythonFinder_PREFIX}_LIBRARY_DEBUG NAMES "python@PYTHON_VERSION_MAJOR@@PYTHON_VERSION_MINOR@_d" "python@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@d" @@ -61,7 +68,7 @@ if(_PythonFinder_WantLibs) if(_PythonFinder_WantInterp) find_program( - @PythonFinder_PREFIX@_EXECUTABLE + ${_PythonFinder_PREFIX}_EXECUTABLE NAMES "python" "python@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@" PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools/python3" NO_DEFAULT_PATH @@ -69,39 +76,39 @@ if(_PythonFinder_WantLibs) endif() # These are duplicated as normal variables to nullify FindPython's checksum verifications. - set(_@PythonFinder_PREFIX@_INCLUDE_DIR "${_@PythonFinder_PREFIX@_INCLUDE_DIR}") - set(_@PythonFinder_PREFIX@_LIBRARY_RELEASE "${_@PythonFinder_PREFIX@_LIBRARY_RELEASE}") - set(_@PythonFinder_PREFIX@_LIBRARY_DEBUG "${_@PythonFinder_PREFIX@_LIBRARY_DEBUG}") + set(_${_PythonFinder_PREFIX}_INCLUDE_DIR "${_@PythonFinder_PREFIX@_INCLUDE_DIR}") + set(_${_PythonFinder_PREFIX}_LIBRARY_RELEASE "${_@PythonFinder_PREFIX@_LIBRARY_RELEASE}") + set(_${_PythonFinder_PREFIX}_LIBRARY_DEBUG "${_@PythonFinder_PREFIX@_LIBRARY_DEBUG}") _find_package(${ARGS}) - get_directory_property(_@PythonFinder_PREFIX@_IMPORTED_TARGETS IMPORTED_TARGETS) - if(ANDROID AND @PythonFinder_PREFIX@::Module IN_LIST _@PythonFinder_PREFIX@_IMPORTED_TARGETS) - set_property(TARGET @PythonFinder_PREFIX@::Module APPEND PROPERTY INTERFACE_LINK_LIBRARIES $) + get_directory_property(_${_PythonFinder_PREFIX}_IMPORTED_TARGETS IMPORTED_TARGETS) + if(ANDROID AND ${_PythonFinder_PREFIX}::Module IN_LIST _${_PythonFinder_PREFIX}_IMPORTED_TARGETS) + set_property(TARGET ${_PythonFinder_PREFIX}::Module APPEND PROPERTY INTERFACE_LINK_LIBRARIES $) endif() - unset(_@PythonFinder_PREFIX@_IMPORTED_TARGETS) + unset(_${_PythonFinder_PREFIX}_IMPORTED_TARGETS) if(@VCPKG_LIBRARY_LINKAGE@ STREQUAL "static") # Python for Windows embeds the zlib module into the core, so we have to link against it. # This is a separate extension module on Unix-like platforms. if(WIN32) find_package(ZLIB) - if(TARGET @PythonFinder_PREFIX@::Python) - set_property(TARGET @PythonFinder_PREFIX@::Python APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) + if(TARGET ${_PythonFinder_PREFIX}::Python) + set_property(TARGET ${_PythonFinder_PREFIX}::Python APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) endif() - if(TARGET @PythonFinder_PREFIX@::Module) - set_property(TARGET @PythonFinder_PREFIX@::Module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) + if(TARGET ${_PythonFinder_PREFIX}::Module) + set_property(TARGET ${_PythonFinder_PREFIX}::Module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) endif() - if(DEFINED @PythonFinder_PREFIX@_LIBRARIES) - list(APPEND @PythonFinder_PREFIX@_LIBRARIES ${ZLIB_LIBRARIES}) + if(DEFINED ${_PythonFinder_PREFIX}_LIBRARIES) + list(APPEND ${_PythonFinder_PREFIX}_LIBRARIES ${ZLIB_LIBRARIES}) endif() endif() if(APPLE) find_package(Iconv) find_package(Intl) - if(TARGET @PythonFinder_PREFIX@::Python) - get_target_property(_PYTHON_INTERFACE_LIBS @PythonFinder_PREFIX@::Python INTERFACE_LINK_LIBRARIES) + if(TARGET ${_PythonFinder_PREFIX}::Python) + get_target_property(_PYTHON_INTERFACE_LIBS ${_PythonFinder_PREFIX}::Python INTERFACE_LINK_LIBRARIES) if(NOT _PYTHON_INTERFACE_LIBS) set(_PYTHON_INTERFACE_LIBS "") endif() @@ -110,11 +117,11 @@ if(_PythonFinder_WantLibs) Iconv::Iconv "$,${Intl_LIBRARY_DEBUG},${Intl_LIBRARY_RELEASE}>" ) - set_property(TARGET @PythonFinder_PREFIX@::Python PROPERTY INTERFACE_LINK_LIBRARIES ${_PYTHON_INTERFACE_LIBS}) + set_property(TARGET ${_PythonFinder_PREFIX}::Python PROPERTY INTERFACE_LINK_LIBRARIES ${_PYTHON_INTERFACE_LIBS}) unset(_PYTHON_INTERFACE_LIBS) endif() - if(TARGET @PythonFinder_PREFIX@::Module) - get_target_property(_PYTHON_INTERFACE_LIBS @PythonFinder_PREFIX@::Module INTERFACE_LINK_LIBRARIES) + if(TARGET ${_PythonFinder_PREFIX}::Module) + get_target_property(_PYTHON_INTERFACE_LIBS ${_PythonFinder_PREFIX}::Module INTERFACE_LINK_LIBRARIES) if(NOT _PYTHON_INTERFACE_LIBS) set(_PYTHON_INTERFACE_LIBS "") endif() @@ -123,11 +130,11 @@ if(_PythonFinder_WantLibs) Iconv::Iconv "$,${Intl_LIBRARY_DEBUG},${Intl_LIBRARY_RELEASE}>" ) - set_property(TARGET @PythonFinder_PREFIX@::Module PROPERTY INTERFACE_LINK_LIBRARIES ${_PYTHON_INTERFACE_LIBS}) + set_property(TARGET ${_PythonFinder_PREFIX}::Module PROPERTY INTERFACE_LINK_LIBRARIES ${_PYTHON_INTERFACE_LIBS}) unset(_PYTHON_INTERFACE_LIBS) endif() - if(DEFINED @PythonFinder_PREFIX@_LIBRARIES) - list(APPEND @PythonFinder_PREFIX@_LIBRARIES "-framework CoreFoundation" ${Iconv_LIBRARIES} ${Intl_LIBRARIES}) + if(DEFINED ${_PythonFinder_PREFIX}_LIBRARIES) + list(APPEND ${_PythonFinder_PREFIX}_LIBRARIES "-framework CoreFoundation" ${Iconv_LIBRARIES} ${Intl_LIBRARIES}) endif() endif() endif() @@ -135,15 +142,16 @@ else() _find_package(${ARGS}) endif() -if(TARGET @PythonFinder_PREFIX@::Python) - target_compile_definitions(@PythonFinder_PREFIX@::Python INTERFACE "Py_NO_LINK_LIB") +if(TARGET ${_PythonFinder_PREFIX}::Python) + target_compile_definitions(${_PythonFinder_PREFIX}::Python INTERFACE "Py_NO_LINK_LIB") endif() -if(TARGET @PythonFinder_PREFIX@::Module) - target_compile_definitions(@PythonFinder_PREFIX@::Module INTERFACE "Py_NO_LINK_LIB") +if(TARGET ${_PythonFinder_PREFIX}::Module) + target_compile_definitions(${_PythonFinder_PREFIX}::Module INTERFACE "Py_NO_LINK_LIB") endif() -if(TARGET @PythonFinder_PREFIX@::SABIModule) - target_compile_definitions(@PythonFinder_PREFIX@::SABIModule INTERFACE "Py_NO_LINK_LIB") +if(TARGET ${_PythonFinder_PREFIX}::SABIModule) + target_compile_definitions(${_PythonFinder_PREFIX}::SABIModule INTERFACE "Py_NO_LINK_LIB") endif() +unset(_PythonFinder_PREFIX) unset(_PythonFinder_WantInterp) unset(_PythonFinder_WantLibs) diff --git a/ports/python3/vcpkg.json b/ports/python3/vcpkg.json index aa65d0b39a36e2..45fa32b9b7f183 100644 --- a/ports/python3/vcpkg.json +++ b/ports/python3/vcpkg.json @@ -1,7 +1,7 @@ { "name": "python3", "version": "3.12.9", - "port-version": 3, + "port-version": 4, "description": "The Python programming language", "homepage": "https://github.com/python/cpython", "license": "Python-2.0", From bba576adc02899483e7a8c8aa45f8bd1baeeca19 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 9 Sep 2025 14:19:41 -0500 Subject: [PATCH 2/9] x-add-version --- versions/baseline.json | 2 +- versions/p-/python3.json | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/versions/baseline.json b/versions/baseline.json index 427301ecf33a5e..e94f51114df51c 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -7706,7 +7706,7 @@ }, "python3": { "baseline": "3.12.9", - "port-version": 3 + "port-version": 4 }, "qca": { "baseline": "2.3.7", diff --git a/versions/p-/python3.json b/versions/p-/python3.json index 2958a4f25c5f1e..171a43a7fe35f5 100644 --- a/versions/p-/python3.json +++ b/versions/p-/python3.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "48dbeaa89ff6981db263ac533f1d224c94d3ed8e", + "version": "3.12.9", + "port-version": 4 + }, { "git-tree": "477d229bf207c5a8544448c53da8f58ce2a7615b", "version": "3.12.9", From 01eca1119214619c6077ff034a3744ec4ee5d993 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 13 Sep 2025 11:42:54 -0500 Subject: [PATCH 3/9] Add test port --- .../vcpkg-ci-python3/portfile.cmake | 6 ++ .../vcpkg-ci-python3/project/CMakeLists.txt | 90 +++++++++++++++++++ .../vcpkg-ci-python3/project/main.c | 30 +++++++ .../test_ports/vcpkg-ci-python3/vcpkg.json | 18 ++++ 4 files changed, 144 insertions(+) create mode 100644 scripts/test_ports/vcpkg-ci-python3/portfile.cmake create mode 100644 scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt create mode 100644 scripts/test_ports/vcpkg-ci-python3/project/main.c create mode 100644 scripts/test_ports/vcpkg-ci-python3/vcpkg.json diff --git a/scripts/test_ports/vcpkg-ci-python3/portfile.cmake b/scripts/test_ports/vcpkg-ci-python3/portfile.cmake new file mode 100644 index 00000000000000..8c5cd4f01de1d5 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-python3/portfile.cmake @@ -0,0 +1,6 @@ +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) + +vcpkg_cmake_configure( + SOURCE_PATH "${CURRENT_PORT_DIR}/project" +) +vcpkg_cmake_build() diff --git a/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt new file mode 100644 index 00000000000000..58850f4ec3dda7 --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt @@ -0,0 +1,90 @@ +cmake_minimum_required(VERSION 3.12) +project(python3-test) + +set(Python_ARTIFACTS_PREFIX "_MEOW") + +# We need to opt-out of CMP0148 to be able to test the pre-CMake 3.12 Python +# find modules. The old policy is deprecated, so, at some point, this aspect +# of the test will have to go away. +if(POLICY CMP0148) + cmake_policy(SET CMP0148 OLD) +endif() + +# The purpose of this test is to ensure that we get the expected values +# from the finders, not crosscompiling. So, let's not even go there. +if(NOT CMAKE_CROSSCOMPILING) + find_package(PythonInterp REQUIRED) + + # The old find modules do not return the path to the Python standard + # library, so we will need to fetch that ourselves. + execute_process( + COMMAND ${PYTHON_EXECUTABLE} + -c "import sysconfig; print(sysconfig.get_path('stdlib'))" + OUTPUT_VARIABLE PYTHON_STDLIB + ) + string(STRIP "${PYTHON_STDLIB}" PYTHON_STDLIB) +endif() +find_package(PythonLibs REQUIRED) + +# The old find modules should NOT be prefixed. +if(DEFINED PYTHON_MEOW_LIBRARIES OR DEFINED PYTHON_MEOW_EXECUTABLE) + message(FATAL_ERROR "Old find module prefixed the result variables") +endif() + +function(test_result NAME TYPE EXPECTED UNEXPECTED) + if(NOT ${TYPE} ${EXPECTED}${NAME}) + message(FATAL_ERROR "${EXPECTED}${NAME} should be ${TYPE}") + endif() + if(${TYPE} ${UNEXPECTED}${NAME}) + message(FATAL_ERROR "${UNEXPECTED}${NAME} should not be ${TYPE}") + endif() +endfunction() + +function(test_new_finder EXPECTED UNEXPECTED) + test_result(::Python TARGET ${EXPECTED} ${UNEXPECTED}) + test_result(_LIBRARIES DEFINED ${EXPECTED} ${UNEXPECTED}) + + if(NOT CMAKE_CROSSCOMPILING) + test_result(_EXECUTABLE DEFINED ${EXPECTED} ${UNEXPECTED}) + test_result(_STDLIB DEFINED ${EXPECTED} ${UNEXPECTED}) + test_result(::Interpreter TARGET ${EXPECTED} ${UNEXPECTED}) + endif() +endfunction() + +if(NOT CMAKE_CROSSCOMPILING) + set(_INTERPRETER "Interpreter") +endif() + +# The new find modules should be prefixed if CMake is 4.0+ +find_package(Python REQUIRED COMPONENTS ${_INTERPRETER} Development) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 4.0) + set(EXPECTED_PYTHON Python_MEOW) + set(UNEXPECTED_PYTHON Python) +else() + set(EXPECTED_PYTHON Python) + set(UNEXPECTED_PYTHON Python_MEOW) +endif() +test_new_finder(${EXPECTED_PYTHON} ${UNEXPECTED_PYTHON}) + +# Also test non-prefixed. Use Python3:: to avoid conflicts with Python_MEOW:: +# The test against Python3_MEOW should never happen because the prefix variable +# should be Python3_ARTIFACT_PREFIX, but we set Python_ARTIFACT_PREFIX. +find_package(Python3 REQUIRED COMPONENTS ${_INTERPRETER} Development) +test_new_finder(Python3 Python3_MEOW) + +# Test embedding the libraries found. +function(add_test_executable TARGET LIBRARIES INCLUDES STDLIB) + add_executable(${TARGET} main.c) + target_link_libraries(${TARGET} PRIVATE ${LIBRARIES}) + if(INCLUDES) + target_include_directories(${TARGET} PRIVATE ${INCLUDES}) + endif() + if(NOT CMAKE_CROSSCOMPILING) + file(TO_CMAKE_PATH "${STDLIB}" _STDLIB) + target_compile_definitions(${TARGET} PRIVATE "-DBATTERIES=L\"${_STDLIB}\"") + endif() +endfunction() + +add_test_executable(old "${PYTHON_LIBRARIES}" "${PYTHON_INCLUDE_DIRS}" "${PYTHON_STDLIB}") +add_test_executable(new_with_prefix "${EXPECTED_PYTHON}::Python" "" "${${EXPECTED_PYTHON}_STDLIB}") +add_test_executable(new_without_prefix "${Python3_LIBRARIES}" "${Python3_INCLUDE_DIRS}" "${Python3_STDLIB}") diff --git a/scripts/test_ports/vcpkg-ci-python3/project/main.c b/scripts/test_ports/vcpkg-ci-python3/project/main.c new file mode 100644 index 00000000000000..0985636b10bc9d --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-python3/project/main.c @@ -0,0 +1,30 @@ +#include + +int main() +{ + PyConfig config; +#ifdef BATTERIES + PyConfig_InitIsolatedConfig(&config); +#else + PyConfig_InitPythonConfig(&config); +#endif + config.optimization_level = 2; + config.write_bytecode = 0; + config.user_site_directory = 0; + PyConfig_SetString(&config, &config.program_name, L"test"); + +#ifdef BATTERIES + PyWideStringList_Append(&config.module_search_paths, BATTERIES); + config.module_search_paths_set = 1; +#endif + + PyStatus status = Py_InitializeFromConfig(&config); + if (PyStatus_Exception(status)) { + PyConfig_Clear(&config); + Py_ExitStatusException(status); + } + + Py_FinalizeEx(); + PyConfig_Clear(&config); + return 0; +} diff --git a/scripts/test_ports/vcpkg-ci-python3/vcpkg.json b/scripts/test_ports/vcpkg-ci-python3/vcpkg.json new file mode 100644 index 00000000000000..1059da183c354e --- /dev/null +++ b/scripts/test_ports/vcpkg-ci-python3/vcpkg.json @@ -0,0 +1,18 @@ +{ + "name": "vcpkg-ci-python3", + "version-string": "ci", + "description": "Port to test python3 in CI", + "homepage": "https://github.com/microsoft/vcpkg", + "license": "MIT", + "dependencies": [ + "python3", + { + "name": "python3", + "host": true + }, + { + "name": "vcpkg-cmake", + "host": true + } + ] +} From 28cb9caabc34538465af28c76e202a4f4a76dce3 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 13 Sep 2025 13:23:19 -0500 Subject: [PATCH 4/9] Remove stdlib/isolation from test. --- .../vcpkg-ci-python3/project/CMakeLists.txt | 21 ++++--------------- .../vcpkg-ci-python3/project/main.c | 11 ---------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt index 58850f4ec3dda7..73be9ccae28c7c 100644 --- a/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt +++ b/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt @@ -14,15 +14,6 @@ endif() # from the finders, not crosscompiling. So, let's not even go there. if(NOT CMAKE_CROSSCOMPILING) find_package(PythonInterp REQUIRED) - - # The old find modules do not return the path to the Python standard - # library, so we will need to fetch that ourselves. - execute_process( - COMMAND ${PYTHON_EXECUTABLE} - -c "import sysconfig; print(sysconfig.get_path('stdlib'))" - OUTPUT_VARIABLE PYTHON_STDLIB - ) - string(STRIP "${PYTHON_STDLIB}" PYTHON_STDLIB) endif() find_package(PythonLibs REQUIRED) @@ -73,18 +64,14 @@ find_package(Python3 REQUIRED COMPONENTS ${_INTERPRETER} Development) test_new_finder(Python3 Python3_MEOW) # Test embedding the libraries found. -function(add_test_executable TARGET LIBRARIES INCLUDES STDLIB) +function(add_test_executable TARGET LIBRARIES INCLUDES) add_executable(${TARGET} main.c) target_link_libraries(${TARGET} PRIVATE ${LIBRARIES}) if(INCLUDES) target_include_directories(${TARGET} PRIVATE ${INCLUDES}) endif() - if(NOT CMAKE_CROSSCOMPILING) - file(TO_CMAKE_PATH "${STDLIB}" _STDLIB) - target_compile_definitions(${TARGET} PRIVATE "-DBATTERIES=L\"${_STDLIB}\"") - endif() endfunction() -add_test_executable(old "${PYTHON_LIBRARIES}" "${PYTHON_INCLUDE_DIRS}" "${PYTHON_STDLIB}") -add_test_executable(new_with_prefix "${EXPECTED_PYTHON}::Python" "" "${${EXPECTED_PYTHON}_STDLIB}") -add_test_executable(new_without_prefix "${Python3_LIBRARIES}" "${Python3_INCLUDE_DIRS}" "${Python3_STDLIB}") +add_test_executable(old "${PYTHON_LIBRARIES}" "${PYTHON_INCLUDE_DIRS}") +add_test_executable(new_with_prefix "${EXPECTED_PYTHON}::Python" "") +add_test_executable(new_without_prefix "${Python3_LIBRARIES}" "${Python3_INCLUDE_DIRS}") diff --git a/scripts/test_ports/vcpkg-ci-python3/project/main.c b/scripts/test_ports/vcpkg-ci-python3/project/main.c index 0985636b10bc9d..cdd5cbebb5759d 100644 --- a/scripts/test_ports/vcpkg-ci-python3/project/main.c +++ b/scripts/test_ports/vcpkg-ci-python3/project/main.c @@ -3,21 +3,10 @@ int main() { PyConfig config; -#ifdef BATTERIES - PyConfig_InitIsolatedConfig(&config); -#else PyConfig_InitPythonConfig(&config); -#endif - config.optimization_level = 2; config.write_bytecode = 0; - config.user_site_directory = 0; PyConfig_SetString(&config, &config.program_name, L"test"); -#ifdef BATTERIES - PyWideStringList_Append(&config.module_search_paths, BATTERIES); - config.module_search_paths_set = 1; -#endif - PyStatus status = Py_InitializeFromConfig(&config); if (PyStatus_Exception(status)) { PyConfig_Clear(&config); From c7f694a08096042a31a6d4dd987a636094441c68 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 14 Sep 2025 14:36:42 -0500 Subject: [PATCH 5/9] Remove host python3 dependency. --- scripts/test_ports/vcpkg-ci-python3/vcpkg.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/test_ports/vcpkg-ci-python3/vcpkg.json b/scripts/test_ports/vcpkg-ci-python3/vcpkg.json index 1059da183c354e..73942d0f28750d 100644 --- a/scripts/test_ports/vcpkg-ci-python3/vcpkg.json +++ b/scripts/test_ports/vcpkg-ci-python3/vcpkg.json @@ -6,10 +6,6 @@ "license": "MIT", "dependencies": [ "python3", - { - "name": "python3", - "host": true - }, { "name": "vcpkg-cmake", "host": true From 442f046589ad971a900438c8f9fe832f83e9ad92 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 14 Sep 2025 16:31:02 -0500 Subject: [PATCH 6/9] Cope with FindPythonInterp not returning a result. --- .../vcpkg-ci-python3/project/CMakeLists.txt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt index 73be9ccae28c7c..5cfbe91c493968 100644 --- a/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt +++ b/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt @@ -12,14 +12,21 @@ endif() # The purpose of this test is to ensure that we get the expected values # from the finders, not crosscompiling. So, let's not even go there. +# These find_package() calls aren't required because FindPythonInterp +# seems to not return a result in CI. Probably because FindPythonInterp +# prefers the system Python instead of the executable from the python3 +# port. if(NOT CMAKE_CROSSCOMPILING) - find_package(PythonInterp REQUIRED) + find_package(PythonInterp) endif() -find_package(PythonLibs REQUIRED) +find_package(PythonLibs) # The old find modules should NOT be prefixed. -if(DEFINED PYTHON_MEOW_LIBRARIES OR DEFINED PYTHON_MEOW_EXECUTABLE) - message(FATAL_ERROR "Old find module prefixed the result variables") +if(DEFINED PythonInterp_MEOW_FOUND OR DEFINED PYTHON_MEOW_EXECUTABLE) + message(FATAL_ERROR "FindPythonInterp prefixed the result variables") +endif() +if(DEFINED PythonLibs_MEOW_FOUND OR DEFINED PYTHON_MEOW_LIBRARIES) + message(FATAL_ERROR "FindPythonLibs prefixed the result variables") endif() function(test_result NAME TYPE EXPECTED UNEXPECTED) From 12098ec473a3b80bf983e3e839a88c6dd4ebb653 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 14 Sep 2025 16:53:32 -0500 Subject: [PATCH 7/9] Add libm as an interface library. This problem was exposed by the ci test on x64-linux. --- ports/python3/vcpkg-cmake-wrapper.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ports/python3/vcpkg-cmake-wrapper.cmake b/ports/python3/vcpkg-cmake-wrapper.cmake index 3199657b2792e1..395252989c712b 100644 --- a/ports/python3/vcpkg-cmake-wrapper.cmake +++ b/ports/python3/vcpkg-cmake-wrapper.cmake @@ -104,6 +104,18 @@ if(_PythonFinder_WantLibs) endif() endif() + if(UNIX AND NOT APPLE) + if(TARGET ${_PythonFinder_PREFIX}::Python) + set_property(TARGET ${_PythonFinder_PREFIX}::Python APPEND PROPERTY INTERFACE_LINK_LIBRARIES m) + endif() + if(TARGET ${_PythonFinder_PREFIX}::Module) + set_property(TARGET ${_PythonFinder_PREFIX}::Module APPEND PROPERTY INTERFACE_LINK_LIBRARIES m) + endif() + if(DEFINED ${_PythonFinder_PREFIX}_LIBRARIES) + list(APPEND ${_PythonFinder_PREFIX}_LIBRARIES m) + endif() + endif() + if(APPLE) find_package(Iconv) find_package(Intl) From 7b3942d78707978c38a63938a828aca2062543e4 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 14 Sep 2025 16:54:19 -0500 Subject: [PATCH 8/9] x-add-version --- versions/p-/python3.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions/p-/python3.json b/versions/p-/python3.json index 171a43a7fe35f5..99aae3e913a0f6 100644 --- a/versions/p-/python3.json +++ b/versions/p-/python3.json @@ -1,7 +1,7 @@ { "versions": [ { - "git-tree": "48dbeaa89ff6981db263ac533f1d224c94d3ed8e", + "git-tree": "df599d27a7b29b37e98297ed124445bf40b25728", "version": "3.12.9", "port-version": 4 }, From e0226cad7524a401b3a11c215389ae403af3a504 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 14 Sep 2025 20:42:57 -0500 Subject: [PATCH 9/9] Don't test building with the old finders. --- scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt b/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt index 5cfbe91c493968..6339bfa0529558 100644 --- a/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt +++ b/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt @@ -79,6 +79,9 @@ function(add_test_executable TARGET LIBRARIES INCLUDES) endif() endfunction() -add_test_executable(old "${PYTHON_LIBRARIES}" "${PYTHON_INCLUDE_DIRS}") +# We're purposefully not testing the result of the old finders. +# The python3 port never added a vcpkg-cmake-wrapper for FindPythonLibs, +# and it seems like a poor use of time to do so at this point - the +# old finders are soft removed as of CMake 3.27. add_test_executable(new_with_prefix "${EXPECTED_PYTHON}::Python" "") add_test_executable(new_without_prefix "${Python3_LIBRARIES}" "${Python3_INCLUDE_DIRS}")