COMP: Use pixi-supplied SWIG 4.3.x and CastXML for Python wrapping (intermediary toward SWIG 4.4.1)#6480
Conversation
The generated SWIG wrappers reference the SWIG_Py_DECREF runtime macro, first shipped in SWIG 4.3.0 (the release line descending from the vendored 2024-03-26-master snapshot). System SWIG 4.2.x lacks the macro and fails to compile ITKCommonPython.cpp with "use of undeclared identifier 'SWIG_Py_DECREF'", so the previous 4.2.0 floor was never viable. Assisted-by: Claude Code — bisected the working SWIG range via clean pixi system-SWIG builds
A system SWIG below swig_version_min cannot produce compilable wrappers (missing the SWIG_Py_DECREF runtime macro), yet the prior WARNING let configuration proceed to a confusing 'undeclared identifier' compile error thousands of lines into the build. Promote it to FATAL_ERROR so the version mismatch is reported at configure time with an actionable hint.
Add swig and castxml to the python pixi feature and pass ITK_USE_SYSTEM_SWIG/ITK_USE_SYSTEM_CASTXML in configure-python so wrapping uses the conda-forge toolchain instead of the internal download/build. SWIG is pinned to 4.3.x because that is the verified working window for ITK's Limited-API (abi3) wrapping on main: - 4.2.x fails to compile (the generated wrappers need the SWIG_Py_DECREF runtime macro, absent before the 4.3 line). - 4.3.1 builds, imports, and runs filters cleanly. - 4.4.1 compiles and links but fails at import with 'moduledef' object has no attribute 'delete_SwigPyIterator' under Limited API; see InsightSoftwareConsortium#6479. 4.3.x is the lineage descending from the vendored 2024-03-26-master snapshot, so it matches the codegen ITK is currently tuned to. CastXML 0.7.0 has no such constraint and is used unpinned within 0.7. Assisted-by: Claude Code — bisected the SWIG range via clean pixi system-toolchain builds
|
| Filename | Overview |
|---|---|
| Wrapping/Generators/SwigInterface/CMakeLists.txt | Raises swig_version_min from 4.2.0 to 4.3.0 and promotes the too-old-SWIG diagnostic from WARNING to FATAL_ERROR with a clear remediation hint. Both changes are straightforward and correct. |
| pyproject.toml | Adds swig/castxml to the python feature and enables ITK_USE_SYSTEM_SWIG/CASTXML in configure-python; configure-debug-python is missing the same flags, creating a silent inconsistency between release and debug Python workflows. |
| pixi.lock | Regenerated lock file adds swig 4.3.1, castxml 0.7.0, and transitive deps (libllvm20, libclang-cpp20.1, libxml2, pcre2, etc.) for all five target platforms (linux-64, linux-aarch64, osx-64, osx-arm64, win-64). |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["pixi run build-python\n(python environment)"] --> B["configure-python task\nITK_USE_SYSTEM_SWIG=ON\nITK_USE_SYSTEM_CASTXML=ON"]
B --> C{CMakeLists.txt\nITK_USE_SYSTEM_SWIG?}
C -->|ON| D["find_package(SWIG REQUIRED)"]
D --> E{SWIG_VERSION\n>= 4.3.0?}
E -->|YES| F["Use pixi swig 4.3.1\n✅ Build succeeds"]
E -->|NO| G["FATAL_ERROR\n❌ Configure fails with hint"]
A2["pixi run build-debug-python\n(python environment)"] --> B2["configure-debug-python task\n⚠️ NO SYSTEM_SWIG flag"]
B2 --> C2{CMakeLists.txt\nITK_USE_SYSTEM_SWIG?}
C2 -->|OFF default| H["Download vendored\nswig 2024-03-26-master\n(pixi swig 4.3.1 unused)"]
style G fill:#f88,stroke:#c00
style H fill:#ffc,stroke:#aa0
style F fill:#8f8,stroke:#080
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A["pixi run build-python\n(python environment)"] --> B["configure-python task\nITK_USE_SYSTEM_SWIG=ON\nITK_USE_SYSTEM_CASTXML=ON"]
B --> C{CMakeLists.txt\nITK_USE_SYSTEM_SWIG?}
C -->|ON| D["find_package(SWIG REQUIRED)"]
D --> E{SWIG_VERSION\n>= 4.3.0?}
E -->|YES| F["Use pixi swig 4.3.1\n✅ Build succeeds"]
E -->|NO| G["FATAL_ERROR\n❌ Configure fails with hint"]
A2["pixi run build-debug-python\n(python environment)"] --> B2["configure-debug-python task\n⚠️ NO SYSTEM_SWIG flag"]
B2 --> C2{CMakeLists.txt\nITK_USE_SYSTEM_SWIG?}
C2 -->|OFF default| H["Download vendored\nswig 2024-03-26-master\n(pixi swig 4.3.1 unused)"]
style G fill:#f88,stroke:#c00
style H fill:#ffc,stroke:#aa0
style F fill:#8f8,stroke:#080
Comments Outside Diff (1)
-
pyproject.toml, line 259-268 (link)Debug Python builds will silently ignore pixi-supplied SWIG/CastXML
configure-debug-pythonis missing-DITK_USE_SYSTEM_SWIG:BOOL=ONand-DITK_USE_SYSTEM_CASTXML:BOOL=ON. When a user in thepythonenvironment runspixi run build-debug-python, CMake falls through to the vendored SWIG download path, leaving the pixi-suppliedswigandcastxmlpackages unused. The release and debug Python workflows are now silently inconsistent: one uses system tools, the other fetches a different binary.
Reviews (1): Last reviewed commit: "COMP: Use pixi-supplied SWIG 4.3.x and C..." | Re-trigger Greptile
Enable ITK Python wrapping to use the pixi/conda-forge-supplied SWIG and CastXML (via the existing
ITK_USE_SYSTEM_SWIG/ITK_USE_SYSTEM_CASTXMLoptions) and correct the system-SWIG version floor to match what actually compiles.What changed
Wrapping/Generators/SwigInterface/CMakeLists.txtswig_version_min4.2.0 → 4.3.0 (4.2.x cannot compile — see matrix).WARNING→FATAL_ERRORso a too-old system SWIG fails at configure time instead of a confusingSWIG_Py_DECREFcompile error thousands of lines into the build.pyproject.tomlswig = ">=4.3.1,<4.4"andcastxml = ">=0.7.0,<0.8"to thepythonpixi feature.configure-pythonpasses-DITK_USE_SYSTEM_SWIG=ON -DITK_USE_SYSTEM_CASTXML=ON.pixi.lockregenerated for the above.Verified system-SWIG matrix (ITK main 6.0.0, macOS arm64, Limited API on, CastXML 0.7.0 from conda)
use of undeclared identifier 'SWIG_Py_DECREF'inITKCommonPython.cpp(macro absent before the 4.3 runtime)itk.median_image_filterSWIG_Py_DECREF, pre-4.4 ABI codegenmoduledef/delete_SwigPyIteratorcodegen change (#6479)The vendored
2024-03-26-masteris plain upstream SWIG master (no ITK fork/patches), so 4.3.x is the natural release lineage of the snapshot ITK already targets.Test plan
Locally on macOS arm64:
pixi run build-pythonwith system SWIG 4.3.1 + CastXML 0.7.0 builds all wrapping targets (8462/8462),import itksucceeds, and a real filter runs. 4.2.1 and 4.4.1 were confirmed to fail as tabled above.pre-commit run --all-filespasses on the branch tip.Not yet exercised: Linux and Windows confirmation of the 4.3.x window — relying on CI for cross-platform validation.