-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MLIR] Fix nanobind linker args on macOS #125733
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
Set the "-U,_PyClassMethod_New" linker flag on the Python library itself isntead of on the CMAKE_MODULE_LINKER_FLAGS property.
@llvm/pr-subscribers-mlir Author: Nikhil Kalra (nikalra) ChangesSet the "-U,_PyClassMethod_New" linker flag on the Python library itself isntead of on the CMAKE_MODULE_LINKER_FLAGS property. Full diff: https://github.com/llvm/llvm-project/pull/125733.diff 1 Files Affected:
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index a23de004eb014ff..a21688213339b05 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -709,7 +709,7 @@ function(add_mlir_python_extension libname extname)
# 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
# for downstream users that do not do something like `-undefined dynamic_lookup`.
- set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-U -Wl,_PyClassMethod_New")
+ target_link_options(${libname} PRIVATE "LINKER:-U,_PyClassMethod_New")
endif()
endif()
|
But Just curious what issue do you have with the current solution? |
Would it be better if I made it a I gave I'm not sure what exactly is different between our build setup and the upstream one, but CMAKE_MODULE_LINKER_FLAGS were not getting propagated to the target so we'd fail to link when creating the Python .so. Our Python library is declared with |
Ya that's a reasonable in-between. Btw cc @marbre this change wouldn't affect IREE right because we just duplicated this same patch locally (in IREE CMake)? |
What we have in IREE atm to work around the issue is set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-U -Wl,_PyClassMethod_New") at top-level (https://github.com/iree-org/iree/blob/56bb652fd6b03b7473994426aa4a698f87a1418a/CMakeLists.txt#L655) if building for macOS. IREE also uses Happy to give this patch a try before merging upstream if you want me to (?). |
Ya can you please. |
I did in the meantime, and the patch upstream allows us to drop the downstream one, see https://github.com/iree-org/iree/actions/runs/13155988107. |
This drops the workaround to set linker flags to work around the issue when building the compiler Python bindings for macOS as this is fixed upstream as soon as llvm/llvm-project#125733 lands and was integrated into IREE's llvm fork. Closes iree-org#19591
@nikalra let me know if you need me to merge this (not sure if you have commit access) |
Set the "-U,_PyClassMethod_New" linker flag on the Python library itself isntead of on the CMAKE_MODULE_LINKER_FLAGS property.
This drops the workaround to set linker flags to work around the issue when building the compiler Python bindings for macOS as this is fixed upstream as soon as llvm/llvm-project#125733 lands and was integrated into IREE's llvm fork. Closes #19591
Set the "-U,_PyClassMethod_New" linker flag on the Python library itself isntead of on the CMAKE_MODULE_LINKER_FLAGS property.