@@ -5,41 +5,57 @@ if (NOT TARGET Python::Module)
5
5
endif ()
6
6
7
7
# Determine the right suffix for ordinary and stable ABI extensions.
8
- # Python_SOSABI is guaranteed to be available in CMake 3.26+, and it may
9
- # also be available as part of backported FindPython in scikit-build-core
10
- if (DEFINED Python_SOSABI)
11
- if (WIN32 )
12
- set (NB_SUFFIX_EXT ".pyd" )
13
- else ()
14
- set (NB_SUFFIX_EXT "${CMAKE_SHARED_MODULE_SUFFIX} " )
15
- endif ()
16
8
17
- set (NB_SUFFIX ".${Python_SOABI}${NB_SUFFIX_EXT} " )
9
+ # We always need to know the extension
10
+ if (WIN32 )
11
+ set (NB_SUFFIX_EXT ".pyd" )
12
+ else ()
13
+ set (NB_SUFFIX_EXT "${CMAKE_SHARED_MODULE_SUFFIX} " )
14
+ endif ()
15
+
16
+ # This was added in CMake 3.17+, also available earlier in scikit-build-core.
17
+ # PyPy sets an invalid SOABI (platform missing), causing older FindPythons to
18
+ # report an incorrect value. Only use it if it looks correct (X-X-X form).
19
+ if (DEFINED Python_SOABI AND "${Python_SOABI} " MATCHES ".+-.+-.+" )
20
+ set (NB_SUFFIX ".${Python_SOABI}${NB_SUFFIX_EXT} " )
21
+ endif ()
18
22
19
- if (Python_SOSABI STREQUAL "" )
23
+ # Python_SOSABI is guaranteed to be available in CMake 3.26+, and it may
24
+ # also be available as part of backported FindPython in scikit-build-core.
25
+ if (DEFINED Python_SOSABI)
26
+ if (Python_SOSABI STREQUAL "" )
20
27
set (NB_SUFFIX_S "${NB_SUFFIX_EXT} " )
21
28
else ()
22
29
set (NB_SUFFIX_S ".${Python_SOSABI}${NB_SUFFIX_EXT} " )
23
30
endif ()
24
- else ()
25
- # Query Python directly to get the right suffix
31
+ endif ()
32
+
33
+ # If either suffix is missing, call Python to compute it
34
+ if (NOT DEFINED NB_SUFFIX OR NOT DEFINED NB_SUFFIX_S)
35
+ # Query Python directly to get the right suffix.
26
36
execute_process (
27
37
COMMAND "${Python_EXECUTABLE} " "-c"
28
38
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"
29
39
RESULT_VARIABLE NB_SUFFIX_RET
30
- OUTPUT_VARIABLE NB_SUFFIX
40
+ OUTPUT_VARIABLE EXT_SUFFIX
31
41
OUTPUT_STRIP_TRAILING_WHITESPACE)
32
42
33
- if (NB_SUFFIX_RET AND NOT NB_SUFFIX_RET EQUAL 0)
43
+ if (NB_SUFFIX_RET AND NOT NB_SUFFIX_RET EQUAL 0)
34
44
message (FATAL_ERROR "nanobind: Python sysconfig query to "
35
45
"find 'EXT_SUFFIX' property failed!" )
36
46
endif ()
37
47
38
- get_filename_component (NB_SUFFIX_EXT "${NB_SUFFIX} " LAST_EXT)
39
- if (WIN32 )
40
- set (NB_SUFFIX_S "${NB_SUFFIX_EXT} " )
41
- else ()
42
- set (NB_SUFFIX_S ".abi3${NB_SUFFIX_EXT} " )
48
+ if (NOT DEFINED NB_SUFFIX)
49
+ set (NB_SUFFIX "${EXT_SUFFIX} " )
50
+ endif ()
51
+
52
+ if (NOT DEFINED NB_SUFFIX_S)
53
+ get_filename_component (NB_SUFFIX_EXT "${EXT_SUFFIX} " LAST_EXT)
54
+ if (WIN32 )
55
+ set (NB_SUFFIX_S "${NB_SUFFIX_EXT} " )
56
+ else ()
57
+ set (NB_SUFFIX_S ".abi3${NB_SUFFIX_EXT} " )
58
+ endif ()
43
59
endif ()
44
60
endif ()
45
61
0 commit comments