Building custom wheels of VTK

I am trying to build my own custom (minimal) wheel of VTK. However, I am seeing that the VTK libraries (i.e. libvtkCommonCore.so, etc.) are not getting included in wheel package. The .sos for the Python module are included. What am I missing?

cmake_minimum_required(VERSION 3.14)
project(BuildVTKWheel)

include(ExternalProject)
find_package(Python3 COMPONENTS Interpreter REQUIRED)

# Specify the VTK version and download URL
set(VTK_VERSION "9.4")
set(VTK_VERSION_PATCH "2")
set(VTK_URL "https://vtk.org/files/release/${VTK_VERSION}/VTK-${VTK_VERSION}.${VTK_VERSION_PATCH}.tar.gz")

ExternalProject_Add(VTK
  URL                 ${VTK_URL}
  DOWNLOAD_EXTRACT_TIMESTAMP TRUE
  PREFIX              ${CMAKE_BINARY_DIR}/vtk
  BUILD_IN_SOURCE     OFF
  CMAKE_ARGS
    -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/vtk/install
    -DCMAKE_BUILD_TYPE=Release
    -DPython3_EXECUTABLE=${Python3_EXECUTABLE}

    # Enable Python wrapping
    -DVTK_WRAP_PYTHON=ON
    -DVTK_WHEEL_BUILD=ON
    -DVTK_INSTALL_SDK=ON
    -DVTK_VERSION_SUFFIX="custom"
    -DVTK_ENABLE_REMOTE_MODULES=OFF
    -DVTK_BUILD_PYI_FILES=ON

    # Disable all modules by default, then explicitly enable the ones you need:
    -DVTK_BUILD_ALL_MODULES:BOOL=OFF
    -DVTK_GROUP_ENABLE_Imaging:BOOL=DONT_WANT
    -DVTK_GROUP_ENABLE_Views:BOOL=NO
    -DVTK_GROUP_ENABLE_Web:BOOL=NO
    -DVTK_GROUP_ENABLE_Qt:BOOL=NO
    -DVTK_GROUP_ENABLE_Rendering:BOOL=NO
    -DVTK_GROUP_ENABLE_StandAlone:BOOL=DONT_WANT

    # Enable specific VTK modules
    -DVTK_MODULE_ENABLE_VTK_IOXML:STRING=YES
    -DVTK_MODULE_ENABLE_VTK_IOLegacy=YES
    -DVTK_MODULE_ENABLE_VTK_FiltersGeometry=YES
    -DVTK_MODULE_ENABLE_VTK_FiltersFlowPaths=YES

#   BUILD_COMMAND   ${CMAKE_COMMAND} --build .
  INSTALL_COMMAND
    ${Python3_EXECUTABLE} setup.py bdist_wheel
)

# Optional: create a "build all" target that depends on VTK
add_custom_target(build-vtk-wheel ALL
  DEPENDS VTK
  COMMENT "Downloading, building, installing VTK, and packaging Python wheel"
)

I am seeing this CMake warning too, not sure if it’s relevant:

CMake Warning (dev) at CMake/vtkWheelPreparation.cmake:42 (message):
  Platform build directory warning: mismatch with manual computation:
  "build/lib.linux-x86_64-cpython-310" vs.  "build/lib.linux-x86_64-3.10"

I just checked, and yes, the warning is why the libraries are missing from the wheel.

Edit CMake/wheel_extract_platlib.py and make it print(api) instead of print(manual) and the libraries will go where they belong.

I’m not sure why this problem exists or whether it impacts the pypi wheels.

api is only set if there’s access to actually ask for the information. Python 3.12+ does not expose mechanisms to ask where libraries will be searched for because distutils is gone.

Please trace why the tag = on line 13 is being used instead of 15. Python 3.10 on Linux should be falling into the else, but maybe something is wonky?

For reference, I’m doing my checks on ubuntu 22.04 (primary system) since it has Python 3.10. My redhat system has Python 3.11.

It is falling into the else on line 15, which gives

print(tag) -> cpython-310
print(manual) -> build/lib.linux-x86_64-cpython-310

vs.

print(api) -> build/lib.linux-x86_64-3.10

sigh. Well, the warning is doing its job. But we need to fix the manual computation logic to match. Perhaps there’s an old setuptools installation here?

Maybe an old setuptools provided by the distro. I don’t recall installing it deliberately, but it’s there:

Python 3.10.12 (main, Feb 4 2025, 14:57:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
>>> setuptools.__file__
'/usr/lib/python3/dist-packages/setuptools/__init__.py'
>>> setuptools.__version__
'59.6.0'

According to dpkg, it’s an official deb package:

python3-setuptools  59.6.0-1.2ubuntu0.22.04.3

Edit:

Seems that setuptools-62.1.0 or later is needed, this can be checked in the script.

In contrast, redhat provides setuptools package specific to the python version:

Python 3.11.11 (main, Dec 12 2024, 09:11:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-22)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
>>> setuptools.__file__
'/usr/lib/python3.11/site-packages/setuptools/__init__.py'
>>> setuptools.__version__
'65.5.1'
python3.11-setuptools-65.5.1-3.el8_10.noarch

MR is here: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/12189