Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ jobs:
pip install -r test-requirements.txt
pip install --no-index --find-links=./dist swmm_toolkit
pytest

# Regression test for the Python3_SOABI fallback. Builds with
# NO_STABLE_ABI=1 and runs the ctest suffix guardrail to catch the
# double-dot filename bug (e.g. _solver..so) that occurs when
# CMake's FindPython3 fails to populate Python3_SOABI.
- name: Build + ctest (NO_STABLE_ABI path)
shell: bash
env:
NO_STABLE_ABI: "1"
run: |
pip install cmake swig
cmake -S . -B build_cmake
cmake --build build_cmake --config Release
ctest --test-dir build_cmake --output-on-failure -C Release
2 changes: 2 additions & 0 deletions swmm-toolkit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ cmake_policy(SET CMP0078 NEW)
cmake_policy(SET CMP0086 NEW)
include(${SWIG_USE_FILE})

enable_testing()

# Add project subdirectories
add_subdirectory(swmm-solver)

Expand Down
33 changes: 33 additions & 0 deletions swmm-toolkit/src/swmm/toolkit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ set(PY_LIMITED_API_DEF "Py_LIMITED_API=0x03090000")
string(TOLOWER "$ENV{NO_STABLE_ABI}" _abi_val)
if(_abi_val STREQUAL "1" OR _abi_val STREQUAL "true")
set(PY_LIMITED_API_DEF "")
if(NOT Python3_SOABI)
execute_process(
COMMAND ${Python3_EXECUTABLE} -c
"import sysconfig; print(sysconfig.get_config_var('SOABI') or '')"
OUTPUT_VARIABLE Python3_SOABI
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
set(SOABI ".${Python3_SOABI}")
endif()

Expand Down Expand Up @@ -188,6 +196,31 @@ install(
COMPONENT python
)

#############################################################
#################### SUFFIX TESTS ####################
#############################################################

# Verify that each extension module was linked with a valid Python ABI suffix.
# Guards against the double-dot bug (_solver..so) that occurs when
# CMake's FindPython3 fails to populate Python3_SOABI.
# Run with: cmake --build <build_dir> && ctest --test-dir <build_dir>

foreach(_ext_target output solver)
add_test(
NAME ExtensionSuffix_${_ext_target}
COMMAND ${Python3_EXECUTABLE} -c
"import importlib.machinery, os; \
p = r'$<TARGET_FILE:${_ext_target}>'; \
valid = importlib.machinery.EXTENSION_SUFFIXES; \
assert os.path.exists(p), f'Extension not found: {p!r}'; \
assert '..' not in os.path.basename(p), \
f'Double-dot ABI bug in {p!r} -- Python3_SOABI was empty at configure time'; \
assert any(p.endswith(s) for s in valid), \
f'Invalid suffix in {p!r}, expected one of {valid}'; \
print('PASS:', p)"
)
endforeach()

# Copy libomp.dylib on macOS if using scikit-build-core
if(APPLE AND DEFINED SKBUILD_PLATLIB_DIR)
install(
Expand Down
Loading