Skip to content

[mlir] Add option to disable MLIR Python dev package configuration. #117934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ configure_file(
# Requires:
# The pybind11 library can be found (set with -DPYBIND_DIR=...)
# The python executable is correct (set with -DPython3_EXECUTABLE=...)
# By default, find_package and probing for installed pybind11 is performed.
# Super projects can set MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES=ON to
# disable all package setup and control it themselves.
#-------------------------------------------------------------------------------

set(MLIR_ENABLE_BINDINGS_PYTHON 0 CACHE BOOL
Expand All @@ -170,8 +173,17 @@ set(MLIR_DETECT_PYTHON_ENV_PRIME_SEARCH 1 CACHE BOOL
"Prime the python detection by searching for a full 'Development' \
component first (temporary while diagnosing environment specific Python \
detection issues)")
set(MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES 0 CACHE BOOL
"Performs python dev package configuration sufficient to use all MLIR \
python features. Super-projects that wish to control their own setup \
must perform an appropriate find_package of Python3 with \
'Development.Module' and ensure that find_package(pybind11) is \
satisfied (and keep up to date as requirements evolve).")

if(MLIR_ENABLE_BINDINGS_PYTHON)
include(MLIRDetectPythonEnv)
# Note that both upstream and downstreams often call this macro. It gates
# internally on the MLIR_CONFIGURE_PYTHON_DEV_PACKAGES option.
mlir_configure_python_dev_packages()
endif()

Expand Down
54 changes: 28 additions & 26 deletions mlir/cmake/modules/MLIRDetectPythonEnv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@

# Finds and configures python packages needed to build MLIR Python bindings.
macro(mlir_configure_python_dev_packages)
if(MLIR_DETECT_PYTHON_ENV_PRIME_SEARCH)
# Prime the search for python to see if there is a full development
# package. This seems to work around cmake bugs searching only for
# Development.Module in some environments. However, in other environments
# it may interfere with the subsequent search for Development.Module.
find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
COMPONENTS Interpreter Development)
endif()
if(NOT MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES)
if(MLIR_DETECT_PYTHON_ENV_PRIME_SEARCH)
# Prime the search for python to see if there is a full development
# package. This seems to work around cmake bugs searching only for
# Development.Module in some environments. However, in other environments
# it may interfere with the subsequent search for Development.Module.
find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
COMPONENTS Interpreter Development)
endif()

# After CMake 3.18, we are able to limit the scope of the search to just
# Development.Module. Searching for Development will fail in situations where
# the Python libraries are not available. When possible, limit to just
# Development.Module.
# See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode
set(_python_development_component Development.Module)
# After CMake 3.18, we are able to limit the scope of the search to just
# Development.Module. Searching for Development will fail in situations where
# the Python libraries are not available. When possible, limit to just
# Development.Module.
# See https://pybind11.readthedocs.io/en/stable/compiling.html#findpython-mode
set(_python_development_component Development.Module)

find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
COMPONENTS Interpreter ${_python_development_component} REQUIRED)
unset(_python_development_component)
message(STATUS "Found python include dirs: ${Python3_INCLUDE_DIRS}")
message(STATUS "Found python libraries: ${Python3_LIBRARIES}")
message(STATUS "Found numpy v${Python3_NumPy_VERSION}: ${Python3_NumPy_INCLUDE_DIRS}")
mlir_detect_pybind11_install()
find_package(pybind11 2.10 CONFIG REQUIRED)
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIR}")
message(STATUS "Python prefix = '${PYTHON_MODULE_PREFIX}', "
"suffix = '${PYTHON_MODULE_SUFFIX}', "
"extension = '${PYTHON_MODULE_EXTENSION}")
find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION}
COMPONENTS Interpreter ${_python_development_component} REQUIRED)
unset(_python_development_component)
message(STATUS "Found python include dirs: ${Python3_INCLUDE_DIRS}")
message(STATUS "Found python libraries: ${Python3_LIBRARIES}")
message(STATUS "Found numpy v${Python3_NumPy_VERSION}: ${Python3_NumPy_INCLUDE_DIRS}")
mlir_detect_pybind11_install()
find_package(pybind11 2.10 CONFIG REQUIRED)
message(STATUS "Found pybind11 v${pybind11_VERSION}: ${pybind11_INCLUDE_DIR}")
message(STATUS "Python prefix = '${PYTHON_MODULE_PREFIX}', "
"suffix = '${PYTHON_MODULE_SUFFIX}', "
"extension = '${PYTHON_MODULE_EXTENSION}")
endif()
endmacro()

# Detects a pybind11 package installed in the current python environment
Expand Down