[Mlir-commits] [mlir] [MLIR] Fix nanobind linker args on macOS (PR #125733)

Nikhil Kalra llvmlistbot at llvm.org
Tue Feb 4 10:09:00 PST 2025


https://github.com/nikalra created https://github.com/llvm/llvm-project/pull/125733

Set the "-U,_PyClassMethod_New" linker flag on the Python library itself isntead of on the CMAKE_MODULE_LINKER_FLAGS property.

>From d98844b0ae9f68f215496433a4fb0c8458f28b02 Mon Sep 17 00:00:00 2001
From: Nikhil Kalra <nkalra at apple.com>
Date: Tue, 4 Feb 2025 10:07:36 -0800
Subject: [PATCH] [MLIR] Fix nanobind linker args on macOS

Set the "-U,_PyClassMethod_New" linker flag on the Python library itself isntead of on the CMAKE_MODULE_LINKER_FLAGS property.
---
 mlir/cmake/modules/AddMLIRPython.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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()
 



More information about the Mlir-commits mailing list