Skip to content

Build VTK from source #54

Build VTK from source

Build VTK from source #54

Workflow file for this run

name: Build VTK from source
on:
workflow_dispatch
env:
PYTHONUTF8: 1
jobs:
build:
name: Build with wrapper for Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ 'ubuntu-20.04', 'macos-13', 'macos-14', 'windows-2019' ]
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
steps:
- name: Checkout project
uses: actions/checkout@v4
- uses: actions/setup-python@v5
if: ${{ runner.os != 'macOS' }} # setup-python is currently very broken for macos-14 and possibly 13 too
with:
python-version: ${{ matrix.python-version }}
- name: Setup Micromamba on MacOS
if: ${{ runner.os == 'macOS' }} # setup-python is currently very broken for macos-14 and possibly 13 too
uses: mamba-org/setup-micromamba@v1
with:
environment-name: build-vtk # required by micromamba
create-args: >-
python=${{ matrix.python-version }}
- name: Setup Python Env
# shell: bash -l {0}
# The `bdist_wheel` command requires the `wheel` package
run: |
python -V
python -m pip install --upgrade pip
python -m pip install --upgrade wheel
python -m pip freeze
- name: Setup Windows build environment (MSVC)
if: ${{ runner.os == 'Windows' }}
uses: ilammy/msvc-dev-cmd@v1
- name: Ubuntu Deps
shell: bash -l {0}
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt install -y build-essential cmake mesa-common-dev mesa-utils freeglut3-dev python3-dev python3-venv git-core ninja-build cmake wget libglvnd0 libglvnd-dev
# - name: MacOS-13 Deps
# shell: bash -l {0}
# if: ${{ matrix.os != 'macos-11' }}
# run: |
- name: MacOS Deps # 13 and 14
shell: bash -l {0}
if: ${{ runner.os == 'macOS' }}
run: |
brew install ninja
micromamba info
# - name: Windows Deps
# shell: bash -l {0} #cmd?
# if: ${{ matrix.os != 'windows-2019' }}
# run: |
- name: Build Linux Wheel from Scratch
shell: bash -l {0}
if: ${{ runner.os == 'Linux' }}
run: |
python -V
pip install --upgrade setuptools
mkdir -p ./vtk/build
curl -L -O https://vtk.org/files/release/9.2/VTK-9.2.6.tar.gz # Update this for newer releases of VTK
tar -zxf VTK-9.2.6.tar.gz --directory ./vtk/
cd ./vtk/build
cmake -GNinja -DVTK_WHEEL_BUILD=ON -DVTK_WRAP_PYTHON=ON -DCMAKE_BUILD_TYPE=Release ../VTK-9.2.6
ninja
python setup.py bdist_wheel
cd ../../
find ./ -iname *.whl
- name: Build macOS Wheel from Scratch
shell: bash -l {0}
if: ${{ runner.os == 'macOS' }}
run: |
micromamba info
python -V
pip install --upgrade setuptools
mkdir -p ./vtk/build
curl -L -O https://vtk.org/files/release/9.2/VTK-9.2.6.tar.gz # Update this for newer releases of VTK
tar -zxf VTK-9.2.6.tar.gz --directory ./vtk/
cd ./vtk/build
cmake -GNinja -DVTK_WHEEL_BUILD=ON -DVTK_WRAP_PYTHON=ON -DCMAKE_BUILD_TYPE=Release ../VTK-9.2.6
ninja
python setup.py bdist_wheel
cd ../../
find ./ -iname *.whl
- name: Build Windows Wheel from Scratch
shell: cmd
if: ${{ runner.os == 'Windows' }}
run: |
python -V
cl
pip install --upgrade setuptools
mkdir vtk\build
curl -L -O https://vtk.org/files/release/9.2/VTK-9.2.6.tar.gz
tar -zxf VTK-9.2.6.tar.gz --directory vtk\
cd vtk\build
cmake -GNinja -DVTK_WHEEL_BUILD=ON -DVTK_WRAP_PYTHON=ON -DCMAKE_BUILD_TYPE=Release ..\VTK-9.2.6
ninja
python setup.py bdist_wheel
cd ..\..\
dir /s
- name: Prepare Python version string
shell: bash -l {0}
run: echo "PYTHON_VERSION_NO_DOTS=$(echo ${{ matrix.python-version }} | tr -d '.')" >> $GITHUB_ENV
- name: Rename MacOS ARM64 wheel
shell: bash -l {0}
if: ${{ matrix.os == 'macos-14' }}
run: |
echo "WHEEL_OS_VERSION=macosx_14_0_arm64" >> $GITHUB_ENV
- name: Rename MacOS AMD64 wheel
shell: bash -l {0}
if: ${{ matrix.os == 'macos-13' }}
run: |
echo "WHEEL_OS_VERSION=macosx_13_0_x86_64" >> $GITHUB_ENV
- name: Rename Linux AMD64 wheel
shell: bash -l {0}
if: ${{ matrix.os == 'ubuntu-20.04' }}
run: |
echo "WHEEL_OS_VERSION=linux_x86_64" >> $GITHUB_ENV
- name: Rename Windows AMD64 wheel
shell: bash -l {0}
if: ${{ matrix.os == 'windows-2019' }}
run: |
echo "WHEEL_OS_VERSION=win_amd64" >> $GITHUB_ENV
- name: Edit wheel
shell: bash -l {0}
run: |
wheel_file=$(ls vtk/build/dist/*.whl | xargs -n 1 basename) # Get the wheel file name from an ls of the dist directory
echo $wheel_file
mkdir ./wheel_build/ # Make a separate build directory
unzip vtk/build/dist/${wheel_file} -d ./wheel_build/ # Extract the wheel file
sed -i 's/Name:.*$/Name: cadquery_vtk/' ./wheel_build/*.dist-info/METADATA # Change the name in the METADATA file
sed -i 's/Version:.9.2.6.dev0$/Version: 9.2.6/' ./wheel_build/*.dist-info/METADATA # Remove the .dev0 from the version in the METADATA file
mv ./wheel_build/*.dist-info ./wheel_build/cadquery_vtk-9.2.6.dist-info # Rename the dist-info file to the new name
wheel pack ./wheel_build/; # Create a new wheel file with the new name by prepending "cadquery_" to the name
rm ./vtk/build/dist/*.whl # Remove the old wheel file
mv /*.whl ./vtk/build/dist/ # Move the new wheel file to the dist directory
# new_wheel_file=$(ls wheel_build/*.whl | xargs -n 1 basename)
# mv ./wheel_build/cadquery_${wheel_file} ./vtk/build/dist/ # Move the new wheel file to the dist directory
# mv vtk/build/dist/vtk-9.2.6.dev0-cp${{ env.PYTHON_VERSION_NO_DOTS }}-cp${{ env.PYTHON_VERSION_NO_DOTS }}-${{ env.WHEEL_OS_VERSION }}.whl vtk/build/dist/cadquery-vtk-9.2.6-cp${{ env.PYTHON_VERSION_NO_DOTS }}-cp${{ env.PYTHON_VERSION_NO_DOTS }}-${{ env.WHEEL_OS_VERSION }}.whl
- name: Test wheel
shell: bash -l {0}
run: |
python -V
pip install vtk/build/dist/*.whl
python -c "import vtk;print('vtk imported successfully')"
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: cadquery-vtk-${{ matrix.os }}-cp${{ matrix.python-version }}
path: vtk/build/dist/*.whl