Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add docker build scripts #9

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### PyVista VTK Wheels

Here are hosted VTK wheels build using OSMesa on Ubuntu 20.04 with glib 2.31 for the Python 3.8 wheel, and Ubuntu 22.04 for the OSMesa Python 3.9 wheel. For a variety of reasons, these wheels were not built on an earlier version of Linux, nor were "repaired" using ``auditwheel``, and are therefore have limited comparability. See the last section for build notes.
Here are hosted VTK wheels build using OSMesa on Ubuntu 20.04 with glib 2.31 for the Python 3.8 wheel, and Ubuntu 22.04 for the OSMesa Python 3.9 wheel. For a variety of reasons, these wheels were not built on an earlier version of Linux, nor were "repaired" using ``auditwheel``, and are therefore have limited comparability. See the last section for build notes.

These wheels are used within the [PyVista documentation build](https://github.com/pyvista/pyvista/blob/main/azure-pipelines.yml) to avoid using ``xvfb``, which has been found to be unstable and has lower performance.
These wheels are used within the [PyVista documentation build](https://github.com/pyvista/pyvista/blob/main/.github/workflows/docs.yml) to avoid using ``xvfb``, which has been found to be unstable and has lower performance.

### Build Process for the Python 3.8/3.9 OSMesa Wheels

Expand Down
2 changes: 2 additions & 0 deletions build/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.whl
*.tar.gz
4 changes: 4 additions & 0 deletions build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.png
*.tar.gz
*.whl
VTK-*
59 changes: 59 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
ARG PYTHON_VERSION=3.9
FROM python:$PYTHON_VERSION
ARG DEBIAN_FRONTEND=noninteractive

# Install apt dependencies
WORKDIR /opt/workdir
COPY packages.apt /opt/workdir/
RUN apt-get update && \
xargs apt-get install --no-install-recommends --yes <packages.apt && \
rm -rf /var/lib/apt/lists/*

ARG VTK_VERSION=9.2.2
ARG BUILD_VARIANT=osmesa
# https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9674
ENV VTK_BUILD_VARIANT_SUFFIX=$BUILD_VARIANT

# Download VTK
RUN echo ${VTK_VERSION}
COPY download_vtk.sh ./
RUN ./download_vtk.sh

# Build requested variant from configs
RUN mkdir /opt/workdir/VTK-${VTK_VERSION}/build
WORKDIR /opt/workdir/VTK-${VTK_VERSION}/build
COPY *.cmake /opt/workdir/VTK-${VTK_VERSION}/build/
RUN cmake -GNinja \
-C configure_${BUILD_VARIANT}.cmake \
..
RUN ninja

# Edit the setup.py file to support variant in version
# https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9674
COPY hack_version.py ./
RUN python hack_version.py

# Make Python wheel
RUN python -m pip install wheel
RUN python setup.py bdist_wheel

# Move wheel to /opt/wheels/
RUN mkdir /opt/wheels/ && cp /opt/workdir/VTK-${VTK_VERSION}/build/dist/*.whl /opt/wheels/

# Test/verify the wheel
WORKDIR /opt/
RUN python -m pip install /opt/wheels/*.whl
# Test
RUN python -c "import vtk;vtk.vtkRenderer()"
RUN python -m pip install pyvista
RUN python -c "import pyvista;print(pyvista.Report())"
# Make sure off screen by default
# RUN python -c "import pyvista;pyvista.Cone().plot(show_edges=True)"

# Repair wheel to include OSMesa libs
# RUN python -m pip install auditwheel
# RUN auditwheel show /opt/wheels/*.whl
# RUN auditwheel repair --plat linux_x86_64 /opt/wheels/*.whl


ENTRYPOINT [ "/bin/bash", "-l", "-c" ]
44 changes: 44 additions & 0 deletions build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Build OSMesa or EGL Wheels

The docker build and scripts in this directly make it possible to target any recent version of VTK and Python (on linux) to create OSMesa and EGL wheels.

## Docker build script

Edit `make_wheel.sh` to specify the VTK and Python versions you desire, then run:

```
./make_wheel.sh
```

After this completes, it should dump the built wheel in your current directory.


## Building natively

The included `.cmake` files here make it fairly easy to reproduce this build on your system (linux, Mac, and maybe even Windows).

To create an OSMesa wheel:

```
export VTK_VERSION="9.2.2"
export BUILD_VARIANT="osmesa"

./download_vtk.sh

cd VTK-${VTK_VERSION}
mkdir build
cd build
cp ../../*.cmake ./
cmake -GNinja \
-C configure_${BUILD_VARIANT}.cmake \
..
ninja

# Edit the setup.py file to support variant in version
# https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9674
cp ../../hack_version.py ./
python hack_version.py

python -m pip install wheel
python setup.py bdist_wheel
```
31 changes: 31 additions & 0 deletions build/configure_base.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# set(VTK_BUILD_LEGACY_REMOVE ON)
set(VTK_BUILD_TESTING OFF CACHE STRING "")
set(VTK_BUILD_DOCUMENTATION OFF CACHE STRING "")
set(VTK_BUILD_EXAMPLES OFF CACHE STRING "")

set(VTK_USE_LARGE_DATA ON CACHE STRING "")
set(VTK_LINKER_FATAL_WARNINGS ON CACHE STRING "")

# Enable extra build warnings in CI.
set(VTK_ENABLE_EXTRA_BUILD_WARNINGS ON CACHE STRING "")
set(VTK_ENABLE_EXTRA_BUILD_WARNINGS_EVERYTHING ON CACHE STRING "")

# # Default to Release builds.
# if ("$ENV{CMAKE_BUILD_TYPE}" STREQUAL "")
# set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
# else ()
# set(CMAKE_BUILD_TYPE "$ENV{CMAKE_BUILD_TYPE}" CACHE STRING "")
# endif ()

set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")

# Wheel configuration
set(VTK_WHEEL_BUILD ON CACHE STRING "")
set(VTK_PYTHON_VERSION "3" CACHE STRING "")
# configuration_flag(VTK_WRAP_PYTHON "python")
set(VTK_WRAP_PYTHON YES CACHE STRING "")
set(VTK_MODULE_ENABLE_VTK_PythonInterpreter NO CACHE STRING "")
set(VTK_BUILD_PYI_FILES ON CACHE BOOL "")
set(VTK_DEBUG_LEAKS OFF CACHE BOOL "")

include("${CMAKE_CURRENT_LIST_DIR}/configure_modules.cmake")
9 changes: 9 additions & 0 deletions build/configure_egl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include("${CMAKE_CURRENT_LIST_DIR}/configure_base.cmake")

# configuration_flag(VTK_DEFAULT_RENDER_WINDOW_OFFSCREEN "offscreen")
set(VTK_DEFAULT_RENDER_WINDOW_HEADLESS True CACHE BOOL "")
set(VTK_OPENGL_HAS_EGL True CACHE BOOL "")
set(VTK_OPENGL_HAS_OSMESA False CACHE BOOL "")
set(VTK_USE_COCOA False CACHE BOOL "")
set(VTK_USE_X False CACHE BOOL "")
set(VTK_RENDERING_BACKEND "OpenGL2" CACHE STRING "")
37 changes: 37 additions & 0 deletions build/configure_modules.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# NOTE: this is included in `configure_base.cmake`
# Remote modules are not under VTK's development process.
set(VTK_ENABLE_REMOTE_MODULES OFF CACHE BOOL "")
# Enable everything by default
set(VTK_BUILD_ALL_MODULES ON CACHE BOOL "")
# Disable some things
# ref https://gitlab.kitware.com/vtk/vtk/-/blob/master/.gitlab/ci/configure_macos.cmake
# Modules which require software not on CI machines.
set(VTK_MODULE_ENABLE_VTK_CommonArchive NO CACHE STRING "") # libarchive
set(VTK_MODULE_ENABLE_VTK_DomainsMicroscopy NO CACHE STRING "") # openslide
set(VTK_MODULE_ENABLE_VTK_FiltersOpenTURNS NO CACHE STRING "") # openturns
set(VTK_MODULE_ENABLE_VTK_FiltersReebGraph NO CACHE STRING "") # boost
set(VTK_MODULE_ENABLE_VTK_GeovisGDAL NO CACHE STRING "") # gdal
set(VTK_MODULE_ENABLE_VTK_IOADIOS2 NO CACHE STRING "") # adios
set(VTK_MODULE_ENABLE_VTK_IOFFMPEG NO CACHE STRING "") # ffmpeg
set(VTK_MODULE_ENABLE_VTK_IOGDAL NO CACHE STRING "") # ffmpeg
set(VTK_MODULE_ENABLE_VTK_IOLAS NO CACHE STRING "") # liblas, boost
set(VTK_MODULE_ENABLE_VTK_IOMySQL NO CACHE STRING "") # mysql
set(VTK_MODULE_ENABLE_VTK_IOODBC NO CACHE STRING "") # odbc
set(VTK_MODULE_ENABLE_VTK_IOOpenVDB NO CACHE STRING "") # OpenVDB
set(VTK_MODULE_ENABLE_VTK_IOPDAL NO CACHE STRING "") # pdal
set(VTK_MODULE_ENABLE_VTK_IOPostgreSQL NO CACHE STRING "") # postgresql
set(VTK_MODULE_ENABLE_VTK_InfovisBoost NO CACHE STRING "") # boost
set(VTK_MODULE_ENABLE_VTK_InfovisBoostGraphAlgorithms NO CACHE STRING "") # boost
set(VTK_MODULE_ENABLE_VTK_RenderingFreeTypeFontConfig NO CACHE STRING "") # fontconfig
set(VTK_MODULE_ENABLE_VTK_RenderingMatplotlib NO CACHE STRING "") # matplotlib
set(VTK_MODULE_ENABLE_VTK_RenderingOpenVR NO CACHE STRING "") # openvr
set(VTK_MODULE_ENABLE_VTK_RenderingOpenXR NO CACHE STRING "") # OpenXR
set(VTK_MODULE_ENABLE_VTK_RenderingRayTracing NO CACHE STRING "") # ospray
set(VTK_MODULE_ENABLE_VTK_fides NO CACHE STRING "") # adios
set(VTK_MODULE_ENABLE_VTK_xdmf3 NO CACHE STRING "") # boost
set(VTK_MODULE_ENABLE_VTK_IOOCCT NO CACHE STRING "") # occt
set(VTK_ENABLE_CATALYST OFF CACHE BOOL "") # catalyst

set(VTK_GROUP_ENABLE_Qt NO CACHE STRING "")
set(VTK_USE_MPI NO CACHE STRING "")
set(VTK_GROUP_ENABLE_MPI NO CACHE STRING "")
9 changes: 9 additions & 0 deletions build/configure_osmesa.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
include("${CMAKE_CURRENT_LIST_DIR}/configure_base.cmake")

# configuration_flag(VTK_DEFAULT_RENDER_WINDOW_OFFSCREEN "offscreen")
# configuration_flag(VTK_OPENGL_HAS_OSMESA "osmesa")
set(VTK_DEFAULT_RENDER_WINDOW_HEADLESS True CACHE BOOL "")
set(VTK_OPENGL_HAS_EGL False CACHE BOOL "")
set(VTK_OPENGL_HAS_OSMESA True CACHE BOOL "")
set(VTK_USE_COCOA False CACHE BOOL "")
set(VTK_USE_X False CACHE BOOL "")
7 changes: 7 additions & 0 deletions build/download_vtk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -x
VTK_MINOR_VERSION=$(python -c "print('.'.join('${VTK_VERSION}'.split('.')[:2]))")
echo Downlodaing... https://www.vtk.org/files/release/${VTK_MINOR_VERSION}/VTK-${VTK_VERSION}.tar.gz
curl -L -o VTK-${VTK_VERSION}.tar.gz https://www.vtk.org/files/release/${VTK_MINOR_VERSION}/VTK-${VTK_VERSION}.tar.gz
tar -xzf VTK-${VTK_VERSION}.tar.gz && rm VTK-${VTK_VERSION}.tar.gz
set +x
10 changes: 10 additions & 0 deletions build/hack_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Manual patch to adjust version string.

See # https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9674
"""
with open('setup.py', 'r') as f:
content = f.read().replace(
"version = version_base + '.dev0'",
"version = version_base + '.' + os.environ.get('VTK_BUILD_VARIANT_SUFFIX', 'dev0')")
with open('setup.py', 'w') as f:
f.write(content)
15 changes: 15 additions & 0 deletions build/make_wheel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PYTHON_VERSION="3.9"
VTK_VERSION="9.2.2"
BUILD_VARIANT="egl"

IMAGE_NAME="vtkbuild-$BUILD_VARIANT"

docker build \
-t $IMAGE_NAME \
--build-arg PYTHON_VERSION=$PYTHON_VERSION \
--build-arg VTK_VERSION=$VTK_VERSION \
--build-arg BUILD_VARIANT=$BUILD_VARIANT \
.

# Extract the wheel
docker run -v $PWD:/opt/build-dir --rm $IMAGE_NAME "cp /opt/wheels/*.whl /opt/build-dir"
17 changes: 17 additions & 0 deletions build/packages.apt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
build-essential
ca-certificates
cmake
curl
gcc
git
ninja-build
libgl1-mesa-dev
libosmesa6-dev
libxt-dev
libhdf5-dev
libsdl2-mixer-2.0-0
libsdl2-image-2.0-0
libsdl2-2.0-0
libc6-dev
libssl-dev
libexpat1-dev
Binary file added vtk-9.2.2.egl-cp39-cp39-linux_x86_64.whl
Binary file not shown.
Binary file added vtk-9.2.2.osmesa-cp39-cp39-linux_x86_64.whl
Binary file not shown.