Skip to content

COMP: Improve ITKVtkGlue build robustness on Windows and with unusable VTK - #6848

Merged
dzenanz merged 2 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-vtkglue-build-robustness
Sep 6, 2026
Merged

COMP: Improve ITKVtkGlue build robustness on Windows and with unusable VTK#6848
dzenanz merged 2 commits into
InsightSoftwareConsortium:mainfrom
hjmjohnson:comp-vtkglue-build-robustness

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Two build-robustness fixes for ITKVtkGlue, both from independent Windows validation of #6715 (now merged). Each replaces a failure that surfaces late and cryptically with one that names its remedy.

  • Unusable VTK configurations now fail at configure time instead of as an ImportError when the Python tests run.
  • Windows tests get VTK's DLL directory on PATH, instead of aborting with STATUS_DLL_NOT_FOUND before reaching main.
1. Reject unusable VTK configurations at configure time

Two VTK shapes were only detected when the Python tests ran:

  • VTK without VTK_WRAP_PYTHON — not caught until an import fails.
  • A static VTK. Its Python wrapping collapses into a single
    _vtkmodules_static module, and the tests die with
    ImportError: DLL load failed while importing _vtkmodules_static.
    A shared VTK produces per-module extensions and works.

Both are now checked while configuring, with the remedy named in the message.

VTK exports no shared/static variable — VTK_BUILD_SHARED_LIBS is not part of its package — so the imported VTK::CommonCore target is queried for its TYPE instead. An earlier attempt using the variable produced a false positive on a perfectly good shared VTK, since the undefined variable read as false.

2. VTK's DLL directory on PATH for the Windows tests

Windows has no RPATH, so the VtkGlue C++ test executables abort with
0xc0000135 (STATUS_DLL_NOT_FOUND) before reaching main. ctest reports
only an opaque exit code.

The failure is especially misleading because the Python tests pass in the
same run — itkTestDriver already sets their environment with
--add-before-libpath. So it presents as "C++ broken, Python fine", which
reads like a code defect rather than an environment gap.

ENVIRONMENT_MODIFICATION with path_list_prepend is applied to every test
registered in the directory, via get_property(DIRECTORY PROPERTY TESTS), so
the conditional rendering tests are covered too. It is WIN32-guarded and a
no-op elsewhere. ENVIRONMENT_MODIFICATION requires CMake 3.22, and ITK's
ITK_OLDEST_VALIDATED_POLICIES_VERSION is 3.22.1, so no version gate is
needed.

Verification

macOS arm64 against a purpose-built VTK 9.6.2 (non-kit, rendering, Python
wrapped for the same interpreter as ITK):

  • Configure succeeds with a valid VTK — the new checks do not false-positive.
  • All 12 VtkGlue tests still register and pass, in both
    ITK_USE_PYTHON_LIMITED_API=OFF and =ON.
  • pre-commit run --all-files exits 0.

The VTK_WRAP_PYTHON check is confirmed to read VTK's real exported value
rather than an empty one: it does not fire on a wrapped VTK, and an undefined
variable would have fired.

The Windows path is not exercised by this verification — the change is
WIN32-guarded and was authored from a Windows report, so it needs a Windows
CI run or a manual check to confirm.

Related findings, deliberately not in this PR

The same Windows validation surfaced three issues that are ITK-wide rather
than VtkGlue-specific, and belong in their own changes:

  • Module_ITKTestKernel fails silently without :BOOL. With
    ITK_BUILD_DEFAULT_MODULES=OFF, -DModule_ITKTestKernel=ON leaves
    INTERNAL=OFF; the dependent C++ tests are never created and ctest reports
    100% pass on what remains.
  • Python tests carry the wrong module label. Every Python test in a build
    here shows Labels: ITKFFTImageFilterInit Python. itk_python_add_test
    delegates to itk_add_test, which labels with ${itk-module}, and that
    variable is stale in the Wrapping/Modules/<Name>/test scope. The effect is
    that ctest -L ITKVtkGlue and ctest -R "VtkGlue|ImageToVTK|VTKImageTo"
    select different sets that both happen to contain 8 tests, which hides the
    discrepancy.
  • The resolved ITK_USE_PYTHON_LIMITED_API value is never printed, though
    it auto-enables by interpreter version.

Also related and already filed: #6846, ITKVtkGlue cannot configure against a
rendering-free VTK because the VTK_RENDERING_BACKEND guard tests a VTK 8
variable that VTK 9 never defines.

@hjmjohnson
hjmjohnson marked this pull request as ready for review September 6, 2026 15:30
@github-actions github-actions Bot added type:Compiler Compiler support or related warnings type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:Bridge Issues affecting the Bridge module labels Sep 6, 2026
@greptile-apps

greptile-apps Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This change adds earlier VTK compatibility checks for Python wrapping and configures Windows VtkGlue tests to locate VTK DLLs. One explicit repository requirement remains: the new explanatory comments must be removed or shortened before merging.

Confidence Score: 4/5

Not merge-safe until the repository’s explicit comment requirement is satisfied.

The only final finding is a repository-rule violation; there are no confirmed runtime or security defects.

Files Needing Attention: Modules/Bridge/VtkGlue/itk-module-init.cmake and Modules/Bridge/VtkGlue/test/CMakeLists.txt

Reviews (1): Last reviewed commit: "COMP: Put VTK's DLL directory on PATH fo..." | Re-trigger Greptile

Comment thread Modules/Bridge/VtkGlue/itk-module-init.cmake Outdated
A VTK without Python wrapping, or a static VTK whose wrapping collapses
into a single _vtkmodules_static module, is only detected when the
Python tests run and fail to import. Check both while configuring and
name the remedy.

VTK exports no shared/static variable, so the imported VTK::CommonCore
target is queried directly.
Windows has no RPATH, so the test executables abort with
STATUS_DLL_NOT_FOUND before reaching main, which ctest reports only as
an opaque exit code. The Python tests are unaffected because
itkTestDriver already sets their environment.

ENVIRONMENT_MODIFICATION is a no-op on other platforms.

@dzenanz dzenanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good.

@dzenanz

dzenanz commented Sep 6, 2026

Copy link
Copy Markdown
Member

My home computer build now errors out during configure stage:

CMake Error at Modules/Bridge/VtkGlue/itk-module-init.cmake:59 (message):
  ITK_WRAP_PYTHON is ON and Module_ITKVtkGlue is enabled, but the VTK at

    C:/Libs/vtk-vs22

  was built with VTK_WRAP_PYTHON=OFF.  Rebuild VTK with VTK_WRAP_PYTHON=ON,

  or set Module_ITKVtkGlue=OFF.
Call Stack (most recent call first):
  CMake/ITKModuleEnablement.cmake:478 (include)
  CMakeLists.txt:802 (include)

@dzenanz
dzenanz merged commit 555ac9d into InsightSoftwareConsortium:main Sep 6, 2026
19 checks passed
@dzenanz

dzenanz commented Sep 7, 2026

Copy link
Copy Markdown
Member

This maybe hasn't gone enough. The DLL is still not found. But a different one?

$ ctest -C Release -VV --rerun-failed
UpdateCTestConfiguration  from :M:/CDev/ITK-py-namespace/DartConfiguration.tcl
Parse Config file:M:/CDev/ITK-py-namespace/DartConfiguration.tcl
Test project M:/CDev/ITK-py-namespace
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 4893
    Start 4893: PythonVtkGlueABI3EncodingTest

4893: Test command: M:\CDev\ITK-py-namespace\Wrapping\Generators\Python\itk\itkTestDriver.exe "--add-before-env" "PYTHONPATH" "M:/CDev/ITK-py-namespace/Wrapping/Generators/Python" "--add-before-env" "PYTHONPATH" "M:/CDev/ITK-py-namespace/Wrapping/Generators/Python/itk" "--add-before-libpath" "M:/CDev/ITK-py-namespace/Wrapping/Generators/Python/itk" "C:/Program Files/Python311/python.exe" "M:/CDev/ITK-git/Modules/Bridge/VtkGlue/wrapping/test/VtkGlueABI3EncodingTest.py"
4893: Working Directory: M:/CDev/ITK-git/Modules/Bridge/VtkGlue/wrapping/test
4893: Environment variables:
4893:  PYTHONPATH=C:/Libs/vtk-vs22/lib/site-packages
4893: Test timeout computed to be: 1500
4893: Traceback (most recent call last):
4893:   File "M:\CDev\ITK-git\Modules\Bridge\VtkGlue\wrapping\test\VtkGlueABI3EncodingTest.py", line 39, in <module>
4893:     from vtkmodules.vtkCommonDataModel import vtkImageData, vtkPolyData
4893: ImportError: DLL load failed while importing vtkCommonDataModel: The specified module could not be found.
4893: itkTestDriver: Process exited with return value: 1
1/3 Test #4893: PythonVtkGlueABI3EncodingTest ......***Failed    0.17 sec
test 4894
    Start 4894: PythonVtkGlueRoundTripTest

4894: Test command: M:\CDev\ITK-py-namespace\Wrapping\Generators\Python\itk\itkTestDriver.exe "--add-before-env" "PYTHONPATH" "M:/CDev/ITK-py-namespace/Wrapping/Generators/Python" "--add-before-env" "PYTHONPATH" "M:/CDev/ITK-py-namespace/Wrapping/Generators/Python/itk" "--add-before-libpath" "M:/CDev/ITK-py-namespace/Wrapping/Generators/Python/itk" "C:/Program Files/Python311/python.exe" "M:/CDev/ITK-git/Modules/Bridge/VtkGlue/wrapping/test/VtkGlueRoundTripTest.py"
4894: Working Directory: M:/CDev/ITK-git/Modules/Bridge/VtkGlue/wrapping/test
4894: Environment variables:
4894:  PYTHONPATH=C:/Libs/vtk-vs22/lib/site-packages
4894: Test timeout computed to be: 1500
4894: Traceback (most recent call last):
4894:   File "M:\CDev\ITK-git\Modules\Bridge\VtkGlue\wrapping\test\VtkGlueRoundTripTest.py", line 30, in <module>
4894:     from vtkmodules.vtkCommonDataModel import vtkImageData
4894: ImportError: DLL load failed while importing vtkCommonDataModel: The specified module could not be found.
4894: itkTestDriver: Process exited with return value: 1
2/3 Test #4894: PythonVtkGlueRoundTripTest .........***Failed    0.26 sec
test 4895
    Start 4895: PythonVtkGlueTypemapCoverageTest

4895: Test command: M:\CDev\ITK-py-namespace\Wrapping\Generators\Python\itk\itkTestDriver.exe "--add-before-env" "PYTHONPATH" "M:/CDev/ITK-py-namespace/Wrapping/Generators/Python" "--add-before-env" "PYTHONPATH" "M:/CDev/ITK-py-namespace/Wrapping/Generators/Python/itk" "--add-before-libpath" "M:/CDev/ITK-py-namespace/Wrapping/Generators/Python/itk" "C:/Program Files/Python311/python.exe" "M:/CDev/ITK-git/Modules/Bridge/VtkGlue/wrapping/test/VtkGlueTypemapCoverageTest.py"
4895: Working Directory: M:/CDev/ITK-git/Modules/Bridge/VtkGlue/wrapping/test
4895: Environment variables:
4895:  PYTHONPATH=C:/Libs/vtk-vs22/lib/site-packages
4895: Test timeout computed to be: 1500
4895: Traceback (most recent call last):
4895:   File "M:\CDev\ITK-git\Modules\Bridge\VtkGlue\wrapping\test\VtkGlueTypemapCoverageTest.py", line 32, in <module>
4895:     from vtkmodules.vtkCommonDataModel import vtkImageData
4895: ImportError: DLL load failed while importing vtkCommonDataModel: The specified module could not be found.
4895: itkTestDriver: Process exited with return value: 1
3/3 Test #4895: PythonVtkGlueTypemapCoverageTest ...***Failed    0.44 sec

0% tests passed, 3 tests failed out of 3

Label Time Summary:
ITKFFTImageFilterInit    =   0.88 sec*proc (3 tests)
Python                   =   0.88 sec*proc (3 tests)

Total Test time (real) =   1.33 sec

The following tests FAILED:
        4893 - PythonVtkGlueABI3EncodingTest (Failed)            ITKFFTImageFilterInit Python
        4894 - PythonVtkGlueRoundTripTest (Failed)               ITKFFTImageFilterInit Python
        4895 - PythonVtkGlueTypemapCoverageTest (Failed)         ITKFFTImageFilterInit Python
Errors while running CTest
Output from these tests are in: M:/CDev/ITK-py-namespace/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.

dzenan.zukic@ZERATUL3 MINGW64 /m/CDev/ITK-py-namespace

@dzenanz

dzenanz commented Sep 7, 2026

Copy link
Copy Markdown
Member

I did clean build of VTK with shared libraries, and I still run into test failures:

Dzenan@Ryzenator MINGW64 /c/Misc/ITK-patches-dev-py26
$ ctest -C Release -VV --rerun-failed
UpdateCTestConfiguration  from :C:/Misc/ITK-patches-dev-py26/DartConfiguration.tcl
Parse Config file:C:/Misc/ITK-patches-dev-py26/DartConfiguration.tcl
Test project C:/Misc/ITK-patches-dev-py26
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 518
    Start 518: PythonVtkGlueABI3EncodingTest

518: Test command: C:\Misc\ITK-patches-dev-py26\Wrapping\Generators\Python\itk\itkTestDriver.exe "--add-before-env" "PYTHONPATH" "C:/Misc/ITK-patches-dev-py26/Wrapping/Generators/Python" "--add-before-env" "PYTHONPATH" "C:/Misc/ITK-patches-dev-py26/Wrapping/Generators/Python/itk" "--add-before-libpath" "C:/Misc/ITK-patches-dev-py26/Wrapping/Generators/Python/itk" "C:/Program Files/Python312/python.exe" "C:/Misc/ITK-patches-dev/Modules/Bridge/VtkGlue/wrapping/test/VtkGlueABI3EncodingTest.py"
518: Working Directory: C:/Misc/ITK-patches-dev/Modules/Bridge/VtkGlue/wrapping/test
518: Environment variables:
518:  PYTHONPATH=C:/Libs/vtk-vs22/lib/site-packages
518: Test timeout computed to be: 1500
518: Traceback (most recent call last):
518:   File "C:\Misc\ITK-patches-dev\Modules\Bridge\VtkGlue\wrapping\test\VtkGlueABI3EncodingTest.py", line 39, in <module>
518:     from vtkmodules.vtkCommonDataModel import vtkImageData, vtkPolyData
518: ImportError: DLL load failed while importing vtkCommonDataModel: The specified module could not be found.
518: itkTestDriver: Process exited with return value: 1
1/3 Test #518: PythonVtkGlueABI3EncodingTest ......***Failed    0.21 sec
test 519
    Start 519: PythonVtkGlueRoundTripTest

519: Test command: C:\Misc\ITK-patches-dev-py26\Wrapping\Generators\Python\itk\itkTestDriver.exe "--add-before-env" "PYTHONPATH" "C:/Misc/ITK-patches-dev-py26/Wrapping/Generators/Python" "--add-before-env" "PYTHONPATH" "C:/Misc/ITK-patches-dev-py26/Wrapping/Generators/Python/itk" "--add-before-libpath" "C:/Misc/ITK-patches-dev-py26/Wrapping/Generators/Python/itk" "C:/Program Files/Python312/python.exe" "C:/Misc/ITK-patches-dev/Modules/Bridge/VtkGlue/wrapping/test/VtkGlueRoundTripTest.py"
519: Working Directory: C:/Misc/ITK-patches-dev/Modules/Bridge/VtkGlue/wrapping/test
519: Environment variables:
519:  PYTHONPATH=C:/Libs/vtk-vs22/lib/site-packages
519: Test timeout computed to be: 1500
519: Traceback (most recent call last):
519:   File "C:\Misc\ITK-patches-dev\Modules\Bridge\VtkGlue\wrapping\test\VtkGlueRoundTripTest.py", line 30, in <module>
519:     from vtkmodules.vtkCommonDataModel import vtkImageData
519: ImportError: DLL load failed while importing vtkCommonDataModel: The specified module could not be found.
519: itkTestDriver: Process exited with return value: 1
2/3 Test #519: PythonVtkGlueRoundTripTest .........***Failed    0.32 sec
test 520
    Start 520: PythonVtkGlueTypemapCoverageTest

520: Test command: C:\Misc\ITK-patches-dev-py26\Wrapping\Generators\Python\itk\itkTestDriver.exe "--add-before-env" "PYTHONPATH" "C:/Misc/ITK-patches-dev-py26/Wrapping/Generators/Python" "--add-before-env" "PYTHONPATH" "C:/Misc/ITK-patches-dev-py26/Wrapping/Generators/Python/itk" "--add-before-libpath" "C:/Misc/ITK-patches-dev-py26/Wrapping/Generators/Python/itk" "C:/Program Files/Python312/python.exe" "C:/Misc/ITK-patches-dev/Modules/Bridge/VtkGlue/wrapping/test/VtkGlueTypemapCoverageTest.py"
520: Working Directory: C:/Misc/ITK-patches-dev/Modules/Bridge/VtkGlue/wrapping/test
520: Environment variables:
520:  PYTHONPATH=C:/Libs/vtk-vs22/lib/site-packages
520: Test timeout computed to be: 1500
520: Traceback (most recent call last):
520:   File "C:\Misc\ITK-patches-dev\Modules\Bridge\VtkGlue\wrapping\test\VtkGlueTypemapCoverageTest.py", line 32, in <module>
520:     from vtkmodules.vtkCommonDataModel import vtkImageData
520: ImportError: DLL load failed while importing vtkCommonDataModel: The specified module could not be found.
520: itkTestDriver: Process exited with return value: 1
3/3 Test #520: PythonVtkGlueTypemapCoverageTest ...***Failed    1.11 sec

0% tests passed, 3 tests failed out of 3

Label Time Summary:
ITKVtkGlue    =   1.63 sec*proc (3 tests)
Python        =   1.63 sec*proc (3 tests)

Total Test time (real) =   1.80 sec

The following tests FAILED:
        518 - PythonVtkGlueABI3EncodingTest (Failed)            ITKVtkGlue Python
        519 - PythonVtkGlueRoundTripTest (Failed)               ITKVtkGlue Python
        520 - PythonVtkGlueTypemapCoverageTest (Failed)         ITKVtkGlue Python
Errors while running CTest
Output from these tests are in: C:/Misc/ITK-patches-dev-py26/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.

Dzenan@Ryzenator MINGW64 /c/Misc/ITK-patches-dev-py26

Looking at the test command line, I don't think that VTK binary dir is added to PATH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Bridge Issues affecting the Bridge module type:Compiler Compiler support or related warnings type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants