Skip to content

Define Python_FIND_VIRTUALENV in addition to Python3_FIND_VIRTUALENV #4004

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions build_tools/e2eshark_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cmake -S "$repo_root/externals/llvm-project/llvm" -B "$build_dir" \
-GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DPython3_FIND_VIRTUALENV=ONLY \
-DPython_FIND_VIRTUALENV=ONLY \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_EXTERNAL_PROJECTS="torch-mlir" \
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$PWD" \
Expand Down
1 change: 1 addition & 0 deletions build_tools/python_deploy/build_windows_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cmake -GNinja -Bbuild \
-DLLVM_TARGETS_TO_BUILD=host \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
-DPython3_FIND_VIRTUALENV=ONLY \
-DPython_FIND_VIRTUALENV=ONLY \
-DLLVM_EXTERNAL_PROJECTS="torch-mlir" \
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$PWD" \
-DPython3_EXECUTABLE="$(which python)" \
Expand Down
3 changes: 3 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ cmake -GNinja -Bbuild \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DPython3_FIND_VIRTUALENV=ONLY \
-DPython_FIND_VIRTUALENV=ONLY \
Comment on lines 63 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MLIR searches for both Python3 and Python. If both variables are not defined equally and there multiple python versions on the system, CMake may behave really weirdly.

Could MLIR use IREE's approach instead? https://github.com/iree-org/iree/blob/fd74b8829bebb9c64d45d265d906dbc7b0301c40/CMakeLists.txt#L654-L663

if(IREE_BUILD_PYTHON_BINDINGS)
  # ...
  find_package(Python3 3.9 COMPONENTS Interpreter Development NumPy)
  find_package(Python3 3.9 COMPONENTS Interpreter Development.Module NumPy REQUIRED)
  # Some parts of the build use FindPython instead of FindPython3. Why? No
  # one knows, but they are different. So make sure to bootstrap this one too.
  # Not doing this here risks them diverging, which on multi-Python systems,
  # can be troublesome. Note that nanobind requires FindPython.
  set(Python_EXECUTABLE "${Python3_EXECUTABLE}")
  find_package(Python 3.9 COMPONENTS Interpreter Development.Module NumPy REQUIRED)
elseif(IREE_BUILD_COMPILER OR IREE_BUILD_TESTS)
  find_package(Python3 COMPONENTS Interpreter REQUIRED)
  set(Python_EXECUTABLE "${Python3_EXECUTABLE}")
  find_package(Python COMPONENTS Interpreter REQUIRED)
endif()

That's been working well for us, and it's less configuration needed by the user. One small bandaid in the build system is fine with me... but this starts to spread extra arguments across scripts and documentation too.

-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_EXTERNAL_PROJECTS="torch-mlir" \
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$PWD" \
Expand Down Expand Up @@ -93,6 +94,7 @@ If you're running into issues with the above build command, consider using the f
cmake -GNinja -Bbuild \
-DCMAKE_BUILD_TYPE=Release \
-DPython3_FIND_VIRTUALENV=ONLY \
-DPython_FIND_VIRTUALENV=ONLY \
-DLLVM_ENABLE_PROJECTS=mlir \
-DLLVM_EXTERNAL_PROJECTS="torch-mlir" \
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$PWD" \
Expand Down Expand Up @@ -125,6 +127,7 @@ If you have built llvm-project separately in the directory `$LLVM_INSTALL_DIR`,
cmake -GNinja -Bbuild \
-DCMAKE_BUILD_TYPE=Release \
-DPython3_FIND_VIRTUALENV=ONLY \
-DPython_FIND_VIRTUALENV=ONLY \
-DMLIR_DIR="$LLVM_INSTALL_DIR/lib/cmake/mlir/" \
-DLLVM_DIR="$LLVM_INSTALL_DIR/lib/cmake/llvm/" \
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def cmake_build(self, cmake_build_dir):
f"-DCMAKE_BUILD_TYPE={CMAKE_BUILD_TYPE}",
f"-DPython3_EXECUTABLE={sys.executable}",
f"-DPython3_FIND_VIRTUALENV=ONLY",
f"-DPython_EXECUTABLE={sys.executable}",
f"-DPython_FIND_VIRTUALENV=ONLY",
f"-DMLIR_ENABLE_BINDINGS_PYTHON=ON",
f"-DLLVM_TARGETS_TO_BUILD=host",
f"-DLLVM_ENABLE_ZSTD=OFF",
Expand Down
Loading