-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[mlir][python][cmake] Allow skipping nanobind compile options changes. #123997
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
Conversation
@llvm/pr-subscribers-mlir Author: Scott Todd (ScottTodd) ChangesContext: #107103 (comment) This code is brittle, especially when called from a superproject that adds the get_property(all_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS) The changes here do help with my downstream build, but I'm not sure if using the llvm-project/mlir/cmake/modules/MLIRDetectPythonEnv.cmake Lines 4 to 5 in 7ad8a3d
Some other solutions to consider:
Full diff: https://github.com/llvm/llvm-project/pull/123997.diff 1 Files Affected:
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 815f65b106d945..018a81f1ad5500 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -672,8 +672,11 @@ function(add_mlir_python_extension libname extname)
${ARG_SOURCES}
)
- if (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL)
- # Avoids warnings from upstream nanobind.
+ if (NOT MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES
+ AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
+ # Avoid some warnings from upstream nanobind.
+ # If a superproject set MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES, let
+ # the super project handle compile options as it wishes.
set(nanobind_target "nanobind-static")
if (NOT TARGET ${nanobind_target})
# Get correct nanobind target name: nanobind-static-ft or something else
@@ -702,7 +705,7 @@ function(add_mlir_python_extension libname extname)
${eh_rtti_enable}
)
endif()
-
+
if(APPLE)
# NanobindAdaptors.h uses PyClassMethod_New to build `pure_subclass`es but nanobind
# doesn't declare this API as undefined in its linker flags. So we need to declare it as such
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me, thanks!
Tested a bit more downstream and I'm confident that this solves our issues. The code here could still be reworked, ideally by fixing the nanobind warnings upstream and not needing to fiddle with compile options at all. |
I can confirm that this does resolve the downstream issue. I agree that this code still deserves to be reworked. |
Context: llvm#107103 (comment) This code is brittle, especially when called from a superproject that adds the `nanobind-*` target in a different source directory: ```cmake get_property(all_targets DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY BUILDSYSTEM_TARGETS) ``` The changes here do help with my downstream build, but I'm not sure if using the `MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES` option introduced in llvm#117934 is the right fix given that the option is currently scoped directly to one location with a matching name: https://github.com/llvm/llvm-project/blob/7ad8a3da4771ce8abbd146611124104d42a4e63e/mlir/cmake/modules/MLIRDetectPythonEnv.cmake#L4-L5 Some other solutions to consider: 1. Search through an explicit list of target names using `if (TARGET)` 2. Iterate over _all_ targets in the project, not just the targets in the current directory, using code like https://stackoverflow.com/a/62311397 3. Iterate over targets in the directory known to MLIR (`llvm-project/mlir/python`) 4. Move this `target_compile_options` setup into `mlir_configure_python_dev_packages` (I started on this, but that runs into similar issues where the target is defined in a different directory)
Context: #107103 (comment)
This code is brittle, especially when called from a superproject that adds the
nanobind-*
target in a different source directory:The changes here do help with my downstream build, but I'm not sure if using the
MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES
option introduced in #117934 is the right fix given that the option is currently scoped directly to one location with a matching name:llvm-project/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
Lines 4 to 5 in 7ad8a3d
Some other solutions to consider:
if (TARGET)
llvm-project/mlir/python
)target_compile_options
setup intomlir_configure_python_dev_packages
(I started on this, but that runs into similar issues where the target is defined in a different directory)