Skip to content

Conversation

@makslevental
Copy link
Contributor

@makslevental makslevental commented Dec 25, 2024

Without passing ${eh_rtti_enable} to target_compile_options(nanobind-static ... this fails to build under clang-cl.exe on Windows because exceptions aren't enabled.

Tested by rebasing on top of this PR (i.e., my fork) here.

@makslevental makslevental force-pushed the makslevental/python-clang-cl branch 2 times, most recently from 6774f06 to d3947d5 Compare December 25, 2024 01:27
@makslevental makslevental force-pushed the makslevental/python-clang-cl branch from d3947d5 to 412eae3 Compare December 25, 2024 01:35
@makslevental makslevental changed the title [mlir][python] Support CLANG_CL [mlir][python] Support CLANG_CL Dec 25, 2024
set_target_properties(${name} PROPERTIES
MLIR_AGGREGATE_EXCLUDE_LIBS "${_embed_libs}")
if(MSVC)
if(WIN32)
Copy link
Contributor Author

@makslevental makslevental Dec 25, 2024

Choose a reason for hiding this comment

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

this change and the other MSVC -> WIN32 one below aren't strictly related to the build failure but it's also wrong - this is a windows platform requirement, not an MSVC requirement.

@makslevental makslevental marked this pull request as ready for review December 25, 2024 02:00
@llvmbot llvmbot added the mlir label Dec 25, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 25, 2024

@llvm/pr-subscribers-mlir

Author: Maksim Levental (makslevental)

Changes

Without passing ${eh_rtti_enable} to target_compile_options(nanobind-static ... this fails to build under clang-cl.exe on Windows.

Tested by rebasing on top of this PR (i.e., my fork) here.


Full diff: https://github.com/llvm/llvm-project/pull/121075.diff

2 Files Affected:

  • (modified) mlir/cmake/modules/AddMLIR.cmake (+1-1)
  • (modified) mlir/cmake/modules/AddMLIRPython.cmake (+11-9)
diff --git a/mlir/cmake/modules/AddMLIR.cmake b/mlir/cmake/modules/AddMLIR.cmake
index e1e79593ec2cb4..9c7b00b660ba7d 100644
--- a/mlir/cmake/modules/AddMLIR.cmake
+++ b/mlir/cmake/modules/AddMLIR.cmake
@@ -584,7 +584,7 @@ function(add_mlir_aggregate name)
   # TODO: Should be transitive.
   set_target_properties(${name} PROPERTIES
     MLIR_AGGREGATE_EXCLUDE_LIBS "${_embed_libs}")
-  if(MSVC)
+  if(WIN32)
     set_property(TARGET ${name} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
   endif()
 
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 53a70139fd5a68..9d4e06c7909c81 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -512,7 +512,7 @@ function(add_mlir_python_common_capi_library name)
   )
   add_dependencies(${name} ${_header_sources_target})
 
-  if(MSVC)
+  if(WIN32)
     set_property(TARGET ${name} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
   endif()
   set_target_properties(${name} PROPERTIES
@@ -649,6 +649,15 @@ function(add_mlir_python_extension libname extname)
     message(FATAL_ERROR "Unhandled arguments to add_mlir_python_extension(${libname}, ... : ${ARG_UNPARSED_ARGUMENTS}")
   endif()
 
+  # The extension itself must be compiled with RTTI and exceptions enabled.
+  # Also, some warning classes triggered by pybind11 are disabled.
+  set(eh_rtti_enable)
+  if (MSVC)
+    set(eh_rtti_enable /EHsc /GR)
+  elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL)
+    set(eh_rtti_enable -frtti -fexceptions)
+  endif ()
+
   # The actual extension library produces a shared-object or DLL and has
   # sources that must be compiled in accordance with pybind11 needs (RTTI and
   # exceptions).
@@ -671,18 +680,11 @@ function(add_mlir_python_extension libname extname)
           -Wno-nested-anon-types
           -Wno-c++98-compat-extra-semi
           -Wno-covered-switch-default
+          ${eh_rtti_enable}
       )
     endif()
   endif()
 
-  # The extension itself must be compiled with RTTI and exceptions enabled.
-  # Also, some warning classes triggered by pybind11 are disabled.
-  set(eh_rtti_enable)
-  if (MSVC)
-    set(eh_rtti_enable /EHsc /GR)
-  elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE)
-    set(eh_rtti_enable -frtti -fexceptions)
-  endif ()
   target_compile_options(${libname} PRIVATE ${eh_rtti_enable})
 
   # Configure the output to match python expectations.

@makslevental makslevental requested review from hawkinsw and stellaraccident and removed request for hawkinsw December 25, 2024 02:01
Copy link
Member

@jpienaar jpienaar left a comment

Choose a reason for hiding this comment

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

Thanks!

@makslevental makslevental merged commit 6a7687c into llvm:main Dec 25, 2024
11 checks passed
@makslevental makslevental deleted the makslevental/python-clang-cl branch December 25, 2024 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants