[Mlir-commits] [mlir] [mlir][Python] create MLIRPythonSupport (PR #171775)
Maksim Levental
llvmlistbot at llvm.org
Fri Dec 26 13:55:50 PST 2025
================
@@ -297,6 +302,51 @@ function(_mlir_python_install_sources name source_root_dir destination)
)
endfunction()
+function(build_nanobind_lib)
+ cmake_parse_arguments(ARG
+ ""
+ "INSTALL_COMPONENT;INSTALL_DESTINATION;OUTPUT_DIRECTORY"
+ ""
+ ${ARGN})
+
+ if (NB_ABI MATCHES "[0-9]t")
+ set(_ft "-ft")
+ endif()
+ # nanobind does a string match on the suffix to figure out whether to build
+ # the lib with free threading...
+ set(NB_LIBRARY_TARGET_NAME "nanobind${_ft}-${MLIR_BINDINGS_PYTHON_NB_DOMAIN}")
+ set(NB_LIBRARY_TARGET_NAME "${NB_LIBRARY_TARGET_NAME}" PARENT_SCOPE)
+ nanobind_build_library(${NB_LIBRARY_TARGET_NAME} AS_SYSINCLUDE)
+ target_compile_definitions(${NB_LIBRARY_TARGET_NAME}
+ PRIVATE
+ NB_DOMAIN=${MLIR_BINDINGS_PYTHON_NB_DOMAIN}
+ )
+ # nanobind configures with LTO for shared build which doesn't work everywhere
+ # (see https://github.com/llvm/llvm-project/issues/139602).
+ if(NOT LLVM_ENABLE_LTO)
+ set_target_properties(${NB_LIBRARY_TARGET_NAME} PROPERTIES
+ INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF
+ INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL OFF
+ )
+ endif()
+ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ target_link_options(${NB_LIBRARY_TARGET_NAME} PRIVATE "-Wl,-z,undefs")
+ endif()
----------------
makslevental wrote:
for Darwin/Apple/MacOS nanobind already does the right thing https://github.com/wjakob/nanobind/blob/4ba51fcf795971c5d603d875ae4184bc0c9bd8e6/cmake/nanobind-config.cmake#L204 by explicitly `-U` all the necessary symbols (i.e., same reason the `undefs` is only necessary for Linux below). added a comment here.
https://github.com/llvm/llvm-project/pull/171775
More information about the Mlir-commits
mailing list