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

Add cibuildwheel workflow #2029

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 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
76 changes: 76 additions & 0 deletions .github/workflows/build-cibw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Build Wheels (cibuildwheel)

on: [workflow_dispatch]

jobs:
build_wheels:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python_version: "3.10"
cibw_python_version: 310
platform_id: manylinux_x86_64
manylinux_image: manylinux2014

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python_version }}

- name: Set Nightly Flag
run: echo "NIGHTLY=1" >> $GITHUB_ENV

- name: Install Dependencies
run: |
sudo apt-get install -y wget libicu-dev python3-pip python3-setuptools libboost-all-dev ninja-build
python3 -m pip install -r python/dev_requirements.txt

- name: Run CMake
run: |
cmake . -B build -DGTSAM_BUILD_PYTHON=1 -DGTSAM_PYTHON_VERSION=${{ matrix.python_version }}

- name: Build and test wheels
env:
CIBW_BUILD: cp${{ matrix.cibw_python_version }}-${{ matrix.platform_id }}
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux_image }}
CIBW_ARCHS: all
CIBW_ENVIRONMENT_PASS_LINUX: NIGHTLY

CIBW_BUILD_FRONTEND: "build"
CIBW_BEFORE_ALL: bash {project}/build_tools/wheels/cibw_before_all.sh ${{ matrix.python_version }} {project}

CIBW_BUILD_VERBOSITY: 1

run: bash build_tools/wheels/build_wheels.sh

- name: Store artifacts
uses: actions/upload-artifact@v4
with:
name: cibw-wheels-cp${{ matrix.cibw_python_version }}-${{ matrix.platform_id }}
path: wheelhouse/*.whl

upload_all:
name: Upload All
needs: build_wheels
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: dist/
merge-multiple: true

- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
repository-url: https://test.pypi.org/legacy/
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/build*
/build
/debug*
.idea
*.pyc
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ set (GTSAM_VERSION_PATCH 0)
set (GTSAM_PRERELEASE_VERSION "a0")
math (EXPR GTSAM_VERSION_NUMERIC "10000 * ${GTSAM_VERSION_MAJOR} + 100 * ${GTSAM_VERSION_MINOR} + ${GTSAM_VERSION_PATCH}")

if ("${GTSAM_PRERELEASE_VERSION}" STREQUAL "")
if (DEFINED ENV{NIGHTLY})
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to maybe re-brand to gtsam-develop, as in our slack discussion.

string(TIMESTAMP NOW "%Y.%m.%d.%H.%M")
Copy link
Member

Choose a reason for hiding this comment

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

And make this the PR merge commit hash

set (GTSAM_VERSION_STRING "${NOW}")
set (SETUP_NAME "gtsam-nightly")
elseif ("${GTSAM_PRERELEASE_VERSION}" STREQUAL "")
set (GTSAM_VERSION_STRING "${GTSAM_VERSION_MAJOR}.${GTSAM_VERSION_MINOR}.${GTSAM_VERSION_PATCH}")
set (SETUP_NAME "gtsam")
else()
set (GTSAM_VERSION_STRING "${GTSAM_VERSION_MAJOR}.${GTSAM_VERSION_MINOR}${GTSAM_PRERELEASE_VERSION}")
set (SETUP_NAME "gtsam")
endif()

project(GTSAM
Expand Down
7 changes: 7 additions & 0 deletions build_tools/wheels/build_wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

set -e
set -x

python -m pip install cibuildwheel
python -m cibuildwheel build/python --output-dir wheelhouse
43 changes: 43 additions & 0 deletions build_tools/wheels/cibw_before_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -e
set -x

PYTHON_VERSION="$1"
PROJECT_DIR="$2"

export PYTHON="python${PYTHON_VERSION}"

yum install -y wget ninja-build
$(which $PYTHON) -m pip install -r $PROJECT_DIR/python/dev_requirements.txt

# Install Boost
wget https://archives.boost.io/release/1.87.0/source/boost_1_87_0.tar.gz --quiet
tar -xzf boost_1_87_0.tar.gz
cd boost_1_87_0
./bootstrap.sh --prefix=/opt/boost
./b2 install --prefix=/opt/boost --with=all

# Remove build/cache files that were generated on host
cd ..
rm -rf $PROJECT_DIR/build
rm -rf CMakeCache.txt CMakeFiles

cmake $PROJECT_DIR \
-B build \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
-DGTSAM_BUILD_TESTS=OFF \
-DGTSAM_BUILD_UNSTABLE=${GTSAM_BUILD_UNSTABLE:-ON} \
-DGTSAM_USE_QUATERNIONS=OFF \
-DGTSAM_WITH_TBB=${GTSAM_WITH_TBB:-OFF} \
-DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF \
-DGTSAM_BUILD_WITH_MARCH_NATIVE=OFF \
-DGTSAM_BUILD_PYTHON=ON \
-DGTSAM_UNSTABLE_BUILD_PYTHON=${GTSAM_BUILD_UNSTABLE:-ON} \
-DGTSAM_PYTHON_VERSION=$PYTHON_VERSION \
-DPYTHON_EXECUTABLE:FILEPATH=$(which $PYTHON) \
-DGTSAM_ALLOW_DEPRECATED_SINCE_V43=OFF \
-DCMAKE_INSTALL_PREFIX=$PROJECT_DIR/gtsam_install

cd $PROJECT_DIR/build/python
make -j $(nproc) install
9 changes: 7 additions & 2 deletions python/setup.py.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Setup file to install the GTSAM package."""

from setuptools import setup, find_namespace_packages
from setuptools import setup, find_namespace_packages, Distribution

packages = find_namespace_packages(
where=".",
Expand All @@ -20,8 +20,12 @@ package_data = {
# Cleaner to read in the contents rather than copy them over.
readme_contents = open("${GTSAM_SOURCE_DIR}/README.md").read()

class BinaryDistribution(Distribution):
def has_ext_modules(foo):
return True

setup(
name='gtsam',
name='${SETUP_NAME}',
description='Georgia Tech Smoothing And Mapping library',
url='https://gtsam.org/',
version='${GTSAM_VERSION_STRING}', # https://www.python.org/dev/peps/pep-0440/
Expand All @@ -46,6 +50,7 @@ setup(
packages=packages,
include_package_data=True,
package_data=package_data,
distclass=BinaryDistribution,
test_suite="gtsam.tests",
install_requires=open("${GTSAM_SOURCE_DIR}/python/requirements.txt").readlines(),
zip_safe=False,
Expand Down
Loading