From 1cd14b1c8b5c50a7b0c57fd0367cf57998faa8d8 Mon Sep 17 00:00:00 2001 From: Morgan Funtowicz Date: Wed, 1 Oct 2025 09:15:53 +0200 Subject: [PATCH 1/3] misc(cmake): rely on the more robust Python3 module to handle Python --- build2cmake/src/templates/cuda/preamble.cmake | 8 ++++---- build2cmake/src/templates/metal/preamble.cmake | 8 ++++---- build2cmake/src/templates/utils.cmake | 16 ++++++++-------- build2cmake/src/templates/xpu/preamble.cmake | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/build2cmake/src/templates/cuda/preamble.cmake b/build2cmake/src/templates/cuda/preamble.cmake index 62f547c6..4abea735 100644 --- a/build2cmake/src/templates/cuda/preamble.cmake +++ b/build2cmake/src/templates/cuda/preamble.cmake @@ -15,14 +15,14 @@ set(HIP_SUPPORTED_ARCHS "gfx906;gfx908;gfx90a;gfx940;gfx941;gfx942;gfx1030;gfx11 include(${CMAKE_CURRENT_LIST_DIR}/cmake/utils.cmake) -if(DEFINED Python_EXECUTABLE) +if(DEFINED Python3_EXECUTABLE) # Allow passing through the interpreter (e.g. from setup.py). - find_package(Python COMPONENTS Development Development.SABIModule Interpreter) - if (NOT Python_FOUND) + find_package(Python3 COMPONENTS Development Development.SABIModule Interpreter) + if (NOT Python3_FOUND) message(FATAL_ERROR "Unable to find python matching: ${EXECUTABLE}.") endif() else() - find_package(Python REQUIRED COMPONENTS Development Development.SABIModule Interpreter) + find_package(Python3 REQUIRED COMPONENTS Development Development.SABIModule Interpreter) endif() append_cmake_prefix_path("torch" "torch.utils.cmake_prefix_path") diff --git a/build2cmake/src/templates/metal/preamble.cmake b/build2cmake/src/templates/metal/preamble.cmake index 502471be..c5cf4256 100644 --- a/build2cmake/src/templates/metal/preamble.cmake +++ b/build2cmake/src/templates/metal/preamble.cmake @@ -11,14 +11,14 @@ message(STATUS "FetchContent base directory: ${FETCHCONTENT_BASE_DIR}") include(${CMAKE_CURRENT_LIST_DIR}/cmake/utils.cmake) -if(DEFINED Python_EXECUTABLE) +if(DEFINED Python3_EXECUTABLE) # Allow passing through the interpreter (e.g. from setup.py). - find_package(Python COMPONENTS Development Development.SABIModule Interpreter) - if (NOT Python_FOUND) + find_package(Python3 COMPONENTS Development Development.SABIModule Interpreter) + if (NOT Python3_FOUND) message(FATAL_ERROR "Unable to find python matching: ${EXECUTABLE}.") endif() else() - find_package(Python REQUIRED COMPONENTS Development Development.SABIModule Interpreter) + find_package(Python3 REQUIRED COMPONENTS Development Development.SABIModule Interpreter) endif() append_cmake_prefix_path("torch" "torch.utils.cmake_prefix_path") diff --git a/build2cmake/src/templates/utils.cmake b/build2cmake/src/templates/utils.cmake index 6c87d51e..abf82ac2 100644 --- a/build2cmake/src/templates/utils.cmake +++ b/build2cmake/src/templates/utils.cmake @@ -7,12 +7,12 @@ # macro (find_python_from_executable EXECUTABLE SUPPORTED_VERSIONS) file(REAL_PATH ${EXECUTABLE} EXECUTABLE) - set(Python_EXECUTABLE ${EXECUTABLE}) - find_package(Python COMPONENTS Interpreter Development.Module Development.SABIModule) - if (NOT Python_FOUND) + set(Python3_EXECUTABLE ${EXECUTABLE}) + find_package(Python3 COMPONENTS Interpreter Development.Module Development.SABIModule) + if (NOT Python3_FOUND) message(FATAL_ERROR "Unable to find python matching: ${EXECUTABLE}.") endif() - set(_VER "${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}") + set(_VER "${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}") set(_SUPPORTED_VERSIONS_LIST ${SUPPORTED_VERSIONS} ${ARGN}) if (NOT _VER IN_LIST _SUPPORTED_VERSIONS_LIST) message(FATAL_ERROR @@ -30,7 +30,7 @@ endmacro() function (run_python OUT EXPR ERR_MSG) execute_process( COMMAND - "${Python_EXECUTABLE}" "-c" "${EXPR}" + "${Python3_EXECUTABLE}" "-c" "${EXPR}" OUTPUT_VARIABLE PYTHON_OUT RESULT_VARIABLE PYTHON_ERROR_CODE ERROR_VARIABLE PYTHON_STDERR @@ -89,7 +89,7 @@ function (hipify_sources_target OUT_SRCS NAME ORIG_SRCS) add_custom_target( hipify${NAME} - COMMAND "${Python_EXECUTABLE}" ${CMAKE_SOURCE_DIR}/cmake/hipify.py -p ${CMAKE_SOURCE_DIR} -o ${CMAKE_CURRENT_BINARY_DIR} ${SRCS} + COMMAND "${Python3EXECUTABLE}" ${CMAKE_SOURCE_DIR}/cmake/hipify.py -p ${CMAKE_SOURCE_DIR} -o ${CMAKE_CURRENT_BINARY_DIR} ${SRCS} DEPENDS ${CMAKE_SOURCE_DIR}/cmake/hipify.py ${SRCS} BYPRODUCTS ${HIP_SRCS} COMMENT "Running hipify on ${NAME} extension source files.") @@ -505,9 +505,9 @@ function (define_gpu_extension_target GPU_MOD_NAME) endif() if (GPU_USE_SABI) - Python_add_library(${GPU_MOD_NAME} MODULE USE_SABI ${GPU_USE_SABI} ${GPU_WITH_SOABI} "${GPU_SOURCES}") + Python3_add_library(${GPU_MOD_NAME} MODULE USE_SABI ${GPU_USE_SABI} ${GPU_WITH_SOABI} "${GPU_SOURCES}") else() - Python_add_library(${GPU_MOD_NAME} MODULE ${GPU_WITH_SOABI} "${GPU_SOURCES}") + Python3_add_library(${GPU_MOD_NAME} MODULE ${GPU_WITH_SOABI} "${GPU_SOURCES}") endif() if (GPU_LANGUAGE STREQUAL "HIP") diff --git a/build2cmake/src/templates/xpu/preamble.cmake b/build2cmake/src/templates/xpu/preamble.cmake index 115b5d0e..4fcba2de 100644 --- a/build2cmake/src/templates/xpu/preamble.cmake +++ b/build2cmake/src/templates/xpu/preamble.cmake @@ -20,7 +20,7 @@ message(STATUS "FetchContent base directory: ${FETCHCONTENT_BASE_DIR}") include("cmake/utils.cmake") # Find Python with all necessary components for building extensions -find_package(Python REQUIRED COMPONENTS Interpreter Development.Module Development.SABIModule) +find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module Development.SABIModule) append_cmake_prefix_path("torch" "torch.utils.cmake_prefix_path") From 447685b1659c45bda7557ad5615fbcd332d9b006 Mon Sep 17 00:00:00 2001 From: Morgan Funtowicz Date: Wed, 1 Oct 2025 09:17:26 +0200 Subject: [PATCH 2/3] misc(cmake): typo --- build2cmake/src/templates/utils.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build2cmake/src/templates/utils.cmake b/build2cmake/src/templates/utils.cmake index abf82ac2..dc522755 100644 --- a/build2cmake/src/templates/utils.cmake +++ b/build2cmake/src/templates/utils.cmake @@ -89,7 +89,7 @@ function (hipify_sources_target OUT_SRCS NAME ORIG_SRCS) add_custom_target( hipify${NAME} - COMMAND "${Python3EXECUTABLE}" ${CMAKE_SOURCE_DIR}/cmake/hipify.py -p ${CMAKE_SOURCE_DIR} -o ${CMAKE_CURRENT_BINARY_DIR} ${SRCS} + COMMAND "${Python3_EXECUTABLE}" ${CMAKE_SOURCE_DIR}/cmake/hipify.py -p ${CMAKE_SOURCE_DIR} -o ${CMAKE_CURRENT_BINARY_DIR} ${SRCS} DEPENDS ${CMAKE_SOURCE_DIR}/cmake/hipify.py ${SRCS} BYPRODUCTS ${HIP_SRCS} COMMENT "Running hipify on ${NAME} extension source files.") From 4384f7341202fb42c4e868b9bf1292a07b844064 Mon Sep 17 00:00:00 2001 From: Morgan Funtowicz Date: Wed, 1 Oct 2025 09:22:07 +0200 Subject: [PATCH 3/3] misc(cmake): specify current interpreter as Python3_EXECUTABLE in setup.py --- build2cmake/src/templates/cuda/setup.py | 4 ++-- build2cmake/src/templates/metal/setup.py | 4 ++-- build2cmake/src/templates/xpu/setup.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build2cmake/src/templates/cuda/setup.py b/build2cmake/src/templates/cuda/setup.py index f00e174d..0d3c541c 100644 --- a/build2cmake/src/templates/cuda/setup.py +++ b/build2cmake/src/templates/cuda/setup.py @@ -39,12 +39,12 @@ def build_extension(self, ext: CMakeExtension) -> None: cmake_generator = os.environ.get("CMAKE_GENERATOR", "") - # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON + # Set Python3_EXECUTABLE instead if you use PYBIND11_FINDPYTHON # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code # from Python. cmake_args = [ f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}", - f"-DPython_EXECUTABLE={sys.executable}", + f"-DPython3_EXECUTABLE={sys.executable}", f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm ] build_args = [] diff --git a/build2cmake/src/templates/metal/setup.py b/build2cmake/src/templates/metal/setup.py index 4d078fb5..08164f1a 100644 --- a/build2cmake/src/templates/metal/setup.py +++ b/build2cmake/src/templates/metal/setup.py @@ -39,12 +39,12 @@ def build_extension(self, ext: CMakeExtension) -> None: cmake_generator = os.environ.get("CMAKE_GENERATOR", "") - # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON + # Set Python3_EXECUTABLE instead if you use PYBIND11_FINDPYTHON # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code # from Python. cmake_args = [ f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}", - f"-DPython_EXECUTABLE={sys.executable}", + f"-DPython3_EXECUTABLE={sys.executable}", f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm ] build_args = [] diff --git a/build2cmake/src/templates/xpu/setup.py b/build2cmake/src/templates/xpu/setup.py index 2a21cdfe..55bedcaf 100644 --- a/build2cmake/src/templates/xpu/setup.py +++ b/build2cmake/src/templates/xpu/setup.py @@ -39,12 +39,12 @@ def build_extension(self, ext: CMakeExtension) -> None: cmake_generator = os.environ.get("CMAKE_GENERATOR", "") - # Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON + # Set Python3_EXECUTABLE instead if you use PYBIND11_FINDPYTHON # EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code # from Python. cmake_args = [ f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}{os.sep}", - f"-DPython_EXECUTABLE={sys.executable}", + f"-DPython3_EXECUTABLE={sys.executable}", f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm ] build_args = []