Skip to content

Commit

Permalink
Build wheels with cibuildwheel (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarlinpe authored Dec 15, 2023
1 parent 7bbb69b commit bb17321
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 201 deletions.
45 changes: 9 additions & 36 deletions .github/workflows/build-new.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PyCOLMAP build and publish
name: Build and publish wheels

on:
push:
Expand All @@ -11,52 +11,25 @@ on:
workflow_dispatch:

jobs:
linux-build:
name: Wrapper Linux Build
runs-on: ubuntu-latest
strategy:
matrix:
platform: [ manylinux2014_x86_64 ]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build the Linux wheels
run: |
sudo docker run --rm -e PLAT=${{ matrix.platform }} -v `pwd`:/io quay.io/pypa/${{ matrix.platform }} /io/package/build-wheels-linux.sh
# cleanup for custom runner
sudo chown -R $(whoami):$(whoami) .
- name: Archive wheels
uses: actions/upload-artifact@v3
with:
# we strip the version number from the artifact name
name: pycolmap-${{ matrix.platform }}
path: wheelhouse/pycolmap-*.whl

mac-build:
name: Wrapper macOS Build
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-12, macos-13 ]
os: [ubuntu-latest, macos-12, macos-13]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build the macOS wheels
run: |
./package/build-wheels-macos.sh
- uses: actions/checkout@v4
- name: Build wheels
uses: pypa/cibuildwheel@v2.16.2
- name: Archive wheels
uses: actions/upload-artifact@v3
with:
name: pycolmap-${{ matrix.os }}
path: ./wheelhouse/pycolmap-*.whl
path: wheelhouse/pycolmap-*.whl

pypi-publish:
name: Publish wheels to PyPI
needs: [ linux-build, mac-build ]
needs: build
runs-on: ubuntu-latest
# We publish the wheel to pypi when a new tag is pushed,
# either by creating a new GitHub release or explictly with `git tag`
Expand Down
90 changes: 0 additions & 90 deletions package/build-wheels-macos.sh

This file was deleted.

95 changes: 20 additions & 75 deletions package/build-wheels-linux.sh → package/install-colmap-centos.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#!/bin/bash
PYTHON_VERSIONS=("cp38-cp38" "cp39-cp39" "cp310-cp310" "cp311-cp311")

set -e -x
uname -a
echo "Current CentOS Version:"
cat /etc/centos-release

ls -ltrh /io/

CURRDIR=$(pwd)
echo "Num. processes to use for building: $(nproc)"
echo "${CURRDIR}"

# ------ Install dependencies from the default repositories ------
cd $CURRDIR
cd ${CURRDIR}
yum install -y \
wget \
git \
Expand All @@ -29,9 +24,7 @@ yum install -y \
lz4-devel

# ------ Install boost ------
cd $CURRDIR
#yum install -y centos-release-scl-rh devtoolset-7-gcc-c++
mkdir -p boost && cd boost
cd ${CURRDIR}
export BOOST_FILENAME=boost_1_71_0
wget -nv https://boostorg.jfrog.io/artifactory/main/release/1.71.0/source/${BOOST_FILENAME}.tar.gz
tar xzf ${BOOST_FILENAME}.tar.gz
Expand All @@ -40,102 +33,54 @@ cd ${BOOST_FILENAME}
./b2 -j$(nproc) cxxflags="-fPIC" variant=release link=shared --disable-icu install

# ------ Install gflags ------
cd $CURRDIR
cd ${CURRDIR}
git clone --branch v2.2.2 --depth 1 https://github.com/gflags/gflags.git
cd glflags
cd gflags
mkdir build && cd build
cmake ..
make -j$(nproc)
make install
cmake .. -DBUILD_SHARED_LIBS=ON
make -j$(nproc) install

# ------ Install glog ------
cd $CURRDIR
cd ${CURRDIR}
git clone --branch v0.6.0 --depth 1 https://github.com/google/glog.git
cd glog
mkdir build && cd build
cmake ..
make -j$(nproc)
make install

# Disable CGAL since it pulls many dependencies and increases the wheel size
#yum install -y yum-utils
#yum-config-manager --add-repo=http://springdale.princeton.edu/data/springdale/7/x86_64/os/Computational/
#yum install -y --nogpgcheck CGAL-devel
make -j$(nproc) install

# ------ Install Eigen ------
cd $CURRDIR
cd ${CURRDIR}
EIGEN_VERSION="3.3.9"
export EIGEN_DIR="$CURRDIR/eigen-${EIGEN_VERSION}"
export EIGEN_DIR="${CURRDIR}/eigen"
wget https://gitlab.com/libeigen/eigen/-/archive/${EIGEN_VERSION}/eigen-${EIGEN_VERSION}.tar.gz
tar -xvzf eigen-${EIGEN_VERSION}.tar.gz
cd $EIGEN_DIR
mv eigen-${EIGEN_VERSION} ${EIGEN_DIR}
cd ${EIGEN_DIR}
mkdir build && cd build
cmake ..

# ------ Install CERES solver ------
cd $CURRDIR
cd ${CURRDIR}
git clone https://ceres-solver.googlesource.com/ceres-solver
cd ceres-solver
git checkout $(git describe --tags) # Checkout the latest release
mkdir build
cd build
mkdir build && cd build
cmake .. -DBUILD_TESTING=OFF \
-DBUILD_EXAMPLES=OFF \
-DEigen3_DIR="$EIGEN_DIR/cmake/"
make -j$(nproc)
make install

# ------ Build FreeImage from source and install ------
#cd $CURRDIR
#wget http://downloads.sourceforge.net/freeimage/FreeImage3180.zip
#unzip FreeImage3180.zip
#cd FreeImage
#make
#make install
-DEigen3_DIR="${EIGEN_DIR}/cmake/"
make -j$(nproc) install

# ------ Build COLMAP ------
cd $CURRDIR
cd ${CURRDIR}
git clone https://github.com/colmap/colmap.git
cd colmap
git checkout c0355417328f3706a30a9265fd52bc7a5aa4cb8c
mkdir build/
cd build/
mkdir build && cd build
CXXFLAGS="-fPIC" CFLAGS="-fPIC" cmake .. -DCMAKE_BUILD_TYPE=Release \
-DBoost_USE_STATIC_LIBS=OFF \
-DBOOST_ROOT=/usr/local \
-DCUDA_ENABLED=OFF \
-DCGAL_ENABLED=OFF \
-DGUI_ENABLED=OFF \
-DEIGEN3_INCLUDE_DIRS=$EIGEN_DIR

if [ $ec -ne 0 ]; then
echo "Error:"
cat ./CMakeCache.txt
exit $ec
fi
set -e -x
make -j$(nproc) install

# ------ Build pycolmap wheel ------
cd /io/
WHEEL_DIR="wheels/"
for PYTHON_VERSION in ${PYTHON_VERSIONS[@]}; do
PYTHON_EXEC="/opt/python/${PYTHON_VERSION}/bin/python"
${PYTHON_EXEC} -m pip install --upgrade pip
${PYTHON_EXEC} -m pip wheel \
--no-deps \
-w ${WHEEL_DIR} \
--config-settings=cmake.define.EIGEN3_INCLUDE_DIRS="${EIGEN_DIR}" \
.
done

PYTHON_DEFAULT="/opt/python/${PYTHON_VERSIONS[-1]}/bin/python"
${PYTHON_DEFAULT} -m pip install auditwheel

# Bundle external shared libraries into the wheels
OUT_DIR="/io/wheelhouse"
mkdir -p ${OUT_DIR}
for whl in ${WHEEL_DIR}/*.whl; do
auditwheel repair "$whl" -w ${OUT_DIR} --plat ${PLAT}
done
ls -ltrh ${OUT_DIR}
66 changes: 66 additions & 0 deletions package/install-colmap-macos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
set -x -e

CURRDIR=$(pwd)
NUM_LOGICAL_CPUS=$(sysctl -n hw.logicalcpu)

# See https://github.com/actions/setup-python/issues/577
find /usr/local/bin -lname '*/Library/Frameworks/Python.framework/*' -delete
# See https://github.com/actions/setup-python/issues/577#issuecomment-1500828576
rm /usr/local/bin/go || true
rm /usr/local/bin/gofmt || true

# Updating requires Xcode 14.0, which cannot be installed on macOS 11.
brew remove swiftlint
brew remove node@18

brew update
brew install \
git \
wget \
cmake \
eigen \
freeimage \
flann \
glog \
gflags \
metis \
suite-sparse \
ceres-solver \
glew \
sqlite3 \
libomp \
llvm \
lz4

# Install Boost
mkdir boost && cd boost
BOOST_FILENAME="boost_1_83_0"
wget https://boostorg.jfrog.io/artifactory/main/release/1.83.0/source/${BOOST_FILENAME}.tar.gz
tar xzf ${BOOST_FILENAME}.tar.gz
cd ${BOOST_FILENAME}
BOOST_DIR=${CURRDIR}/boost_install
./bootstrap.sh --prefix=${BOOST_DIR} \
--with-libraries=filesystem,system,program_options,graph,test \
--without-icu clang-darwin
./b2 -j ${NUM_LOGICAL_CPUS} \
cxxflags="-fPIC" \
link=static \
runtime-link=static \
variant=release \
--disable-icu \
--prefix=${BOOST_DIR} \
install

cd ${CURRDIR}
git clone https://github.com/colmap/colmap.git
cd colmap
git checkout c0355417328f3706a30a9265fd52bc7a5aa4cb8c
mkdir build && cd build
cmake .. -DGUI_ENABLED=OFF \
-DCUDA_ENABLED=OFF \
-DCGAL_ENABLED=OFF \
-DBoost_USE_STATIC_LIBS=OFF \
-DBOOSTROOT=${BOOST_DIR} \
-DBoost_NO_SYSTEM_PATHS=ON
make -j ${NUM_LOGICAL_CPUS} install
Loading

0 comments on commit bb17321

Please sign in to comment.