Skip to content

Commit

Permalink
ci: overhaul the python wheels crafting
Browse files Browse the repository at this point in the history
  • Loading branch information
sanguinariojoe committed Aug 7, 2024
1 parent 7114657 commit 92f2e98
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 126 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ name: Python-manylinux-arch
on:
workflow_call:
inputs:
os:
description: 'Host OS'
required: false
type: string
default: '["ubuntu-22.04"]'
arch:
description: 'Architecture target'
required: true
Expand All @@ -23,8 +28,16 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04]

os: ${{ fromJSON(inputs.os) }}
env:
# Skip 32-bit windows wheels builds.
CIBW_SKIP: "*-win32*"
CIBW_ARCHS: ${{inputs.arch}}
CIBW_BEFORE_ALL: >
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install -DEXTERNAL_EIGEN:BOOL=OFF -DPYTHON_WRAPPER:BOOL=OFF -DFORTRAN_WRAPPER:BOOL=OFF -DRUST_WRAPPER:BOOL=OFF -DUSE_VTK=ON -DVTK_DIR=${{github.workspace}}/vtk/lib/cmake/vtk-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}/ -DMOORDYN_PACKAGE_IGNORE_VTK_DEPENDENCY=ON -DBUILD_TESTING=OFF &&
cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} &&
cmake --install ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
steps:
- uses: actions/checkout@v4

Expand All @@ -39,14 +52,37 @@ jobs:
python set_version.py
python set_eigen_data.py
rm set_version.py set_eigen_data.py
cat pyproject.toml
shell: bash

- name:
run: |
if [ ${{inputs.os}} == '["ubuntu-22.04"]' ]; then
echo "VTK_NAME=vtk-manylinux2014_${{inputs.arch}}.tar.gz" >> $GITHUB_ENV
elif [ ${{inputs.os}} == '["macOS-latest"]' ]; then
echo "VTK_NAME=vtk-macOS-x86_64.tar.gz" >> $GITHUB_ENV
elif [ ${{inputs.os}} == '["windows-latest"]' ]; then
echo "VTK_NAME=vtk-Windows-x86_64.tar.gz" >> $GITHUB_ENV
else
exit 255
fi
- name: download pre-built VTK static library
uses: suisei-cn/[email protected]
with:
url: https://github.com/sanguinariojoe/vtk-builds/releases/download/VTK-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}.${{env.VTK_VERSION_PATCH}}-static/vtk-manylinux2014_${{inputs.arch}}.tar.gz
url: https://github.com/sanguinariojoe/vtk-builds/releases/download/VTK-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}.${{env.VTK_VERSION_PATCH}}-static/$VTK_NAME
target: ${{github.workspace}}/

- name: Create folders
run: |
mkdir -p ${{github.workspace}}/vtk
mkdir -p ${{github.workspace}}/build
mkdir -p ${{github.workspace}}/install
- name: Extract VTK tgz
run: |
tar -xvzf $VTK_NAME -C vtk/
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
Expand Down
182 changes: 95 additions & 87 deletions .github/workflows/python-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Python-Wheels

on:
push:
branches: [ $default-branch, master ]
branches: [ $default-branch, master, python ]

permissions: write-all

Expand All @@ -19,7 +19,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04, windows-latest, macOS-latest]
os: [ubuntu-22.04]

steps:
- uses: actions/checkout@v4
Expand All @@ -34,145 +34,153 @@ jobs:
mv wrappers/python/wheels.github/* ./
python set_version.py
python set_eigen_data.py
rm set_version.py set_eigen_data.py
rm set_version.py set_eigen_data.py
cat pyproject.toml
shell: bash

- name: download pre-built VTK static library (non-Linux)
uses: suisei-cn/[email protected]
with:
url: https://github.com/sanguinariojoe/vtk-builds/releases/download/VTK-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}.${{env.VTK_VERSION_PATCH}}-static/vtk-${{runner.os}}-x86_64.tar.gz
target: ${{github.workspace}}/
if: runner.os != 'Linux'

- name: download pre-built VTK static library (Linux-x86_64)
uses: suisei-cn/[email protected]
with:
url: https://github.com/sanguinariojoe/vtk-builds/releases/download/VTK-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}.${{env.VTK_VERSION_PATCH}}-static/vtk-manylinux2014_x86_64.tar.gz
target: ${{github.workspace}}/
if: runner.os == 'Linux'

- name: download pre-built VTK static library (Linux-i686)
uses: suisei-cn/[email protected]
with:
url: https://github.com/sanguinariojoe/vtk-builds/releases/download/VTK-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}.${{env.VTK_VERSION_PATCH}}-static/vtk-manylinux2014_i686.tar.gz
target: ${{github.workspace}}/
if: runner.os == 'Linux'

- name: Create folders
run: |
mkdir -p ${{github.workspace}}/vtk
if: runner.os != 'Linux'

- name: Extract VTK tgz
run: |
tar -xvzf vtk-${{runner.os}}-x86_64.tar.gz -C vtk/
if: runner.os != 'Linux'

- name: Build the source distribution
run: |
python -m pip install -U pip setuptools
python setup.py sdist
if: runner.os == 'Linux'

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
if: runner.os == 'Linux'

- name: Build wheels
uses: pypa/[email protected]
with:
output-dir: dist
env:
# configure cibuildwheel to build native archs ('auto'), and some
# emulated ones
CIBW_ARCHS_LINUX: auto
# Skip 32-bit wheels builds as well as musllinux
CIBW_SKIP: "*-win32 *musllinux*"
CIBW_BEFORE_ALL_LINUX: >
echo "Considering vtk-manylinux2014_`uname -m`.tar.gz..." &&
mkdir -p vtk &&
tar -xvzf vtk-manylinux2014_`uname -m`.tar.gz -C vtk/
- uses: actions/upload-artifact@v4
id: build_wheels
with:
name: python-wheels-${{runner.os}}
name: python-wheels-sdist
path: ./dist/*

build_aarch64:
name: Build Python wheels aarch64
uses: FloatingArrayDesign/MoorDyn/.github/workflows/python-wheels-manylinux-arch.yml@master
build_Linux_x86_64:
name: Build Linux_x86_64
uses: FloatingArrayDesign/MoorDyn/.github/workflows/python-wheels-emulated.yml@main
with:
os: '["ubuntu-22.04"]'
arch: "x86_64"
secrets: inherit

build_Windows_AMD64:
name: Build Windows_AMD64
uses: FloatingArrayDesign/MoorDyn/.github/workflows/python-wheels-emulated.yml@main
with:
os: '["windows-latest"]'
arch: "AMD64"
secrets: inherit

build_MacOS_x86_64:
name: Build Windows_x86_64
uses: FloatingArrayDesign/MoorDyn/.github/workflows/python-wheels-emulated.yml@main
with:
os: '["macOS-latest"]'
arch: "x86_64"
secrets: inherit

build_Linux_i686:
name: Build Linux_i686
uses: FloatingArrayDesign/MoorDyn/.github/workflows/python-wheels-emulated.yml@main
with:
os: '["ubuntu-22.04"]'
arch: "i686"
secrets: inherit

build_Linux_aarch64:
name: Build Linux_aarch64
uses: FloatingArrayDesign/MoorDyn/.github/workflows/python-wheels-emulated.yml@main
with:
os: '["ubuntu-22.04"]'
arch: "aarch64"
secrets: inherit

build_ppc64le:
name: Build Python wheels ppc64le
uses: FloatingArrayDesign/MoorDyn/.github/workflows/python-wheels-manylinux-arch.yml@master
build_Linux_ppc64le:
name: Build Linux_ppc64le
uses: FloatingArrayDesign/MoorDyn/.github/workflows/python-wheels-emulated.yml@main
with:
os: '["ubuntu-22.04"]'
arch: "ppc64le"
secrets: inherit
build_s390x:
name: Build Python wheels s390x
uses: FloatingArrayDesign/MoorDyn/.github/workflows/python-wheels-manylinux-arch.yml@master

build_Linux_s390x:
name: Build Linux_s390x
uses: FloatingArrayDesign/MoorDyn/.github/workflows/python-wheels-emulated.yml@main
with:
os: '["ubuntu-22.04"]'
arch: "s390x"
secrets: inherit

publish:
runs-on: ${{ matrix.os }}
needs: [build_wheels, build_aarch64, build_ppc64le, build_s390x]
needs: [build_wheels, build_Linux_x86_64, build_Windows_AMD64, build_MacOS_x86_64, build_Linux_i686, build_Linux_aarch64, build_Linux_ppc64le, build_Linux_s390x]
strategy:
matrix:
os: [ubuntu-22.04]

steps:
- uses: actions/checkout@v4

- name: Download Linux x86_64 dists
uses: actions/download-artifact@v4
- name: Download sdist
uses: actions/download-artifact@v3
with:
name: python-wheels-sdist
path: dist/

- name: Download Linux_x86_64
uses: actions/download-artifact@v3
with:
name: python-wheels-Linux
name: python-wheels-Linux_x86_64
path: dist/

- name: Download MacOS x86_64 dists
uses: actions/download-artifact@v4
- name: Download Windows_AMD64
uses: actions/download-artifact@v3
with:
name: python-wheels-macOS
name: python-wheels-Windows_AMD64
path: dist/

- name: Download Windows x86_64 dists
uses: actions/download-artifact@v4
- name: Download MacOS_x86_64
uses: actions/download-artifact@v3
with:
name: python-wheels-Windows
name: python-wheels-MacOS_x86_64
path: dist/

- name: Download Linux aarch64 dists
uses: actions/download-artifact@v4
- name: Download Linux_i686
uses: actions/download-artifact@v3
with:
name: python-wheels-aarch64
name: python-wheels-Linux_i686
path: dist/

- name: Download Linux ppc64le dists
uses: actions/download-artifact@v4
- name: Download Linux_aarch64
uses: actions/download-artifact@v3
with:
name: python-wheels-ppc64le
name: python-wheels-Linux_aarch64
path: dist/

- name: Download Linux s390x dists
uses: actions/download-artifact@v4
- name: Download Linux_ppc64le
uses: actions/download-artifact@v3
with:
name: python-wheels-s390x
name: python-wheels-Linux_ppc64le
path: dist/

- name: Download Linux_s390x
uses: actions/download-artifact@v3
with:
name: python-wheels-Linux_s390x
path: dist/

- name: Download MacOS_universal2
uses: actions/download-artifact@v3
with:
name: python-wheels-MacOS_universal2
path: dist/

- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.MOORDYN_TESTPYPI_API }}
repository-url: https://test.pypi.org/legacy/
skip-existing: true

- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
# password: ${{ secrets.MOORDYN_TESTPYPI_API }}
# repository-url: https://test.pypi.org/legacy/
password: ${{ secrets.MOORDYN_PYPI_API }}
repository-url: https://upload.pypi.org/legacy/
skip-existing: true
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
42 changes: 6 additions & 36 deletions wrappers/python/wheels.github/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,13 @@ def arefiles(files):
MODULE_PATH = os.path.join('wrappers', 'python', 'moordyn')
MOORDYN_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)),
'source')
MOORDYN_SRCS = get_sources('source')
MOORDYN_SRCS.append(os.path.join('wrappers', 'python', 'cmoordyn.cpp'))
MOORDYN_SRCS = [os.path.join('wrappers', 'python', 'cmoordyn.cpp')]

if os.path.isdir(MODULE_PATH):
# We better copy the moordyn module on the root
shutil.rmtree('moordyn', ignore_errors=True)
shutil.copytree(MODULE_PATH, 'moordyn')

# Get everything required to compile with VTK support
vtk_version = '9.2'
try:
vtk_version = os.environ['VTK_VERSION_MAJOR'] + "." + \
os.environ['VTK_VERSION_MINOR']
except KeyError:
print("$VTK_VERSION_MAJOR.$VTK_VERSION_MINOR env variables missing")
vtk_libraries = ["vtkCommonCore", "vtkIOXML", "vtkIOGeometry",
"vtkIOXMLParser", "vtkIOLegacy", "vtkIOCore",
"vtkCommonExecutionModel", "vtkCommonDataModel",
"vtkCommonTransforms", "vtkCommonMath", "vtkCommonMisc",
"vtkCommonSystem", "vtkFiltersGeneral", "vtkFiltersCore",
"vtkdoubleconversion", "vtklz4", "vtklzma", "vtkzlib",
"vtkkissfft", "vtkpugixml", "vtkexpat", "vtkloguru", "vtksys"]

# Eigen needs at least C++ 14, and Moordyn itself uses C++ 17
extra_compile_args = ["-std=c++17"]
if platform.system() == "Windows":
Expand All @@ -94,32 +78,18 @@ def arefiles(files):
('MOORDYN_MAJOR_VERSION', '${MOORDYN_MAJOR_VERSION}'),
('MOORDYN_MINOR_VERSION', '${MOORDYN_MINOR_VERSION}'),
('MOORDYN_PATCH_VERSION', '${MOORDYN_PATCH_VERSION}')]
include_dirs = [MOORDYN_PATH, "vtk/include/vtk-" + vtk_version]
if platform.system() == "Windows":
extra_link_args = [
"ws2_32.lib", "dbghelp.lib", "psapi.lib", "kernel32.lib", "user32.lib",
"gdi32.lib", "winspool.lib", "shell32.lib", "ole32.lib",
"oleaut32.lib", "uuid.lib", "comdlg32.lib", "advapi32.lib"]
vtk_libs = ["vtk/lib/" + lib + "-" + vtk_version + ".lib"
for lib in vtk_libraries]
else:
extra_link_args = []
vtk_libs = ["vtk/lib/lib" + lib + "-" + vtk_version + ".a"
for lib in vtk_libraries]

if arefiles(vtk_libs):
extra_link_args = vtk_libs + extra_link_args
definitions = definitions + [('USE_VTK', '1'),]
else:
print("WARNING: Installing without VTK support")
include_dirs = [MOORDYN_PATH]
library_dirs = ['install/lib/', 'install/lib64/']
libraries = ['moordyn']

cmoordyn = Extension('cmoordyn',
sources=MOORDYN_SRCS,
language='c++',
define_macros=definitions,
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)

setup(
Expand Down

0 comments on commit 92f2e98

Please sign in to comment.