@@ -112,24 +112,25 @@ set(CPP_SOURCES
112112)
113113
114114# Create the nanobind module
115+ # Python 3.12+: Use stable ABI (abi3) for forward compatibility with 3.13+
116+ # Python 3.10/3.11: Version-specific module (nanobind stable ABI requires 3.12+)
115117if (Python_VERSION VERSION_GREATER_EQUAL "3.12" )
116- nanobind_add_module(_C
117- NB_STATIC
118- STABLE_ABI
119- LTO
120- ${CPP_SOURCES}
121- ${CUDA_SOURCES}
122- )
118+ message (STATUS "Python ${Python_VERSION} detected - enabling stable ABI (abi3)" )
119+ nanobind_add_module(_C NB_STATIC STABLE_ABI LTO ${CPP_SOURCES} ${CUDA_SOURCES} )
120+ # Explicitly set abi3 suffix
121+ if (WIN32 )
122+ set_target_properties (_C PROPERTIES SUFFIX ".abi3.pyd" )
123+ else ()
124+ set_target_properties (_C PROPERTIES SUFFIX ".abi3.so" )
125+ endif ()
126+ target_compile_definitions (_C PRIVATE Py_LIMITED_API=0x030C0000)
123127else ()
124- # Python 3.10/3.11: version-specific module
125- nanobind_add_module(_C
126- NB_STATIC
127- LTO
128- ${CPP_SOURCES}
129- ${CUDA_SOURCES}
130- )
128+ message (STATUS "Python ${Python_VERSION} detected - building version-specific wheel" )
129+ nanobind_add_module(_C NB_STATIC LTO ${CPP_SOURCES} ${CUDA_SOURCES} )
131130endif ()
132131
132+ target_compile_definitions (_C PRIVATE NB_STATIC)
133+
133134# Set target properties
134135target_compile_options (_C PRIVATE
135136 $<$<COMPILE_LANGUAGE:CUDA>:${CUDA_NVCC_FLAGS} >
@@ -181,22 +182,6 @@ if(CMAKE_CONFIGURATION_TYPES)
181182 )
182183endif ()
183184
184- # Set properties for ABI3 compatibility (Stable ABI) - Python 3.12+ only
185- # Nanobind's stable ABI support requires Python 3.12+
186- if (Python_VERSION VERSION_GREATER_EQUAL "3.12" )
187- message (STATUS "Python ${Python_VERSION} detected - enabling stable ABI (abi3)" )
188- target_compile_definitions (_C PRIVATE
189- Py_LIMITED_API=0x030C0000
190- NB_STATIC
191- )
192- else ()
193- message (STATUS "Python ${Python_VERSION} detected - building version-specific wheel" )
194- target_compile_definitions (_C PRIVATE
195- NB_STATIC
196- )
197- endif ()
198-
199-
200185# Install target
201186install (TARGETS _C
202187 LIBRARY DESTINATION .
0 commit comments