Skip to content

Commit 91faab4

Browse files
authored
Merge pull request #165 from cheginit/fix/soabi-fallback
fix(toolkit): populate Python3_SOABI from sysconfig when empty
2 parents af909e4 + 2047713 commit 91faab4

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

.github/workflows/unit_test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,17 @@ jobs:
5858
pip install -r test-requirements.txt
5959
pip install --no-index --find-links=./dist swmm_toolkit
6060
pytest
61+
62+
# Regression test for the Python3_SOABI fallback. Builds with
63+
# NO_STABLE_ABI=1 and runs the ctest suffix guardrail to catch the
64+
# double-dot filename bug (e.g. _solver..so) that occurs when
65+
# CMake's FindPython3 fails to populate Python3_SOABI.
66+
- name: Build + ctest (NO_STABLE_ABI path)
67+
shell: bash
68+
env:
69+
NO_STABLE_ABI: "1"
70+
run: |
71+
pip install cmake swig
72+
cmake -S . -B build_cmake
73+
cmake --build build_cmake --config Release
74+
ctest --test-dir build_cmake --output-on-failure -C Release

swmm-toolkit/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ cmake_policy(SET CMP0078 NEW)
3636
cmake_policy(SET CMP0086 NEW)
3737
include(${SWIG_USE_FILE})
3838

39+
enable_testing()
40+
3941
# Add project subdirectories
4042
add_subdirectory(swmm-solver)
4143

swmm-toolkit/src/swmm/toolkit/CMakeLists.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ set(PY_LIMITED_API_DEF "Py_LIMITED_API=0x03090000")
2828
string(TOLOWER "$ENV{NO_STABLE_ABI}" _abi_val)
2929
if(_abi_val STREQUAL "1" OR _abi_val STREQUAL "true")
3030
set(PY_LIMITED_API_DEF "")
31+
if(NOT Python3_SOABI)
32+
execute_process(
33+
COMMAND ${Python3_EXECUTABLE} -c
34+
"import sysconfig; print(sysconfig.get_config_var('SOABI') or '')"
35+
OUTPUT_VARIABLE Python3_SOABI
36+
OUTPUT_STRIP_TRAILING_WHITESPACE
37+
)
38+
endif()
3139
set(SOABI ".${Python3_SOABI}")
3240
endif()
3341

@@ -188,6 +196,31 @@ install(
188196
COMPONENT python
189197
)
190198

199+
#############################################################
200+
#################### SUFFIX TESTS ####################
201+
#############################################################
202+
203+
# Verify that each extension module was linked with a valid Python ABI suffix.
204+
# Guards against the double-dot bug (_solver..so) that occurs when
205+
# CMake's FindPython3 fails to populate Python3_SOABI.
206+
# Run with: cmake --build <build_dir> && ctest --test-dir <build_dir>
207+
208+
foreach(_ext_target output solver)
209+
add_test(
210+
NAME ExtensionSuffix_${_ext_target}
211+
COMMAND ${Python3_EXECUTABLE} -c
212+
"import importlib.machinery, os; \
213+
p = r'$<TARGET_FILE:${_ext_target}>'; \
214+
valid = importlib.machinery.EXTENSION_SUFFIXES; \
215+
assert os.path.exists(p), f'Extension not found: {p!r}'; \
216+
assert '..' not in os.path.basename(p), \
217+
f'Double-dot ABI bug in {p!r} -- Python3_SOABI was empty at configure time'; \
218+
assert any(p.endswith(s) for s in valid), \
219+
f'Invalid suffix in {p!r}, expected one of {valid}'; \
220+
print('PASS:', p)"
221+
)
222+
endforeach()
223+
191224
# Copy libomp.dylib on macOS if using scikit-build-core
192225
if(APPLE AND DEFINED SKBUILD_PLATLIB_DIR)
193226
install(

0 commit comments

Comments
 (0)