From 286742eeb889399c3868887eec5dcbf3078bc21a Mon Sep 17 00:00:00 2001 From: Jean Abou Samra Date: Sun, 15 Oct 2023 21:34:58 +0200 Subject: [PATCH] CI: Also build macOS wheels --- .github/workflows/build_wheels.yml | 15 +++++---- ci/build.sh | 54 +++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build_wheels.yml b/.github/workflows/build_wheels.yml index a8b69ac..31be268 100644 --- a/.github/workflows/build_wheels.yml +++ b/.github/workflows/build_wheels.yml @@ -5,18 +5,21 @@ on: [push, pull_request] # versions and macOS / Windows. jobs: - build_wheels_linux: - name: Build Linux wheels - # The Docker container the job is run in. - container: quay.io/pypa/manylinux2014_x86_64 + build_wheels: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + name: Build wheels # The host system that runs Docker. - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + # The Docker container the job is run in. + container: ${{ matrix.os == 'ubuntu-latest' && 'quay.io/pypa/manylinux2014_x86_64' || null }} steps: - uses: actions/checkout@v3 - uses: conda-incubator/setup-miniconda@v2 with: miniconda-version: latest - environment-file: ci/environment/conda-linux-64.lock + environment-file: ${{ matrix.os == 'ubuntu-latest' && 'ci/environment/conda-linux-64.lock' || 'ci/environment/conda-osx-64.lock' }} - name: Build the wheels # The following line here and elsewhere is needed for our Conda environment to # be activated. See: diff --git a/ci/build.sh b/ci/build.sh index 32b4e32..afc7791 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -17,14 +17,21 @@ RPATH_OPTION="-Wl,-rpath,'\$ORIGIN',--disable-new-dtags" # Shell quoting madness to survive through qmake and make ... RPATH_OPTION_2="-Wl,-rpath,'\\'\\\$\\\$ORIGIN\\'',--disable-new-dtags" +if [ "$OSTYPE" == "linux-gnu" ]; then + export LIBRARY_PATH=$CONDA_BUILD_SYSROOT/lib:$CONDA_PREFIX/lib +else # macOS + export LIBRARY_PATH=$CONDA_PREFIX/lib + export MACOSX_DEPLOYMENT_TARGET=11.0 +fi + # Download and extract the Poppler source code POPPLER=poppler-$POPPLER_VERSION curl -O https://poppler.freedesktop.org/$POPPLER.tar.xz -tar -xf $POPPLER.tar.xz +tar -xvf $POPPLER.tar.xz # Patch Poppler to avoid building the tests. Newer Poppler versions have a config # variable for this. -sed -i 's/add_subdirectory(test)//g' $POPPLER/CMakeLists.txt +sed -iback 's/add_subdirectory(test)//g' $POPPLER/CMakeLists.txt pushd $POPPLER @@ -61,10 +68,12 @@ CMAKE_OPTIONS+=" -DBUILD_QT5_TESTS=OFF" # Install locally CMAKE_OPTIONS+=" -DCMAKE_INSTALL_PREFIX==../../../installed-poppler" +if [ "$OSTYPE" == "linux-gnu" ]; then + export LDFLAGS=$RPATH_OPTION +fi + # Generate Poppler Makefile -LDFLAGS=$RPATH_OPTION \ PKG_CONFIG_LIBDIR=$CONDA_PREFIX/lib/pkgconfig \ -LIBRARY_PATH=$CONDA_BUILD_SYSROOT/lib:$CONDA_PREFIX/lib \ cmake -S . -B build $CMAKE_OPTIONS # Build Poppler @@ -73,23 +82,44 @@ make -j$(nproc) make install popd +export -n LDFLAGS + popd # Now build python-poppler-qt5. Add a RUNPATH just like for poppler. -PKG_CONFIG_LIBDIR=installed-poppler/lib64/pkgconfig:$CONDA_PREFIX/lib/pkgconfig \ -LIBRARY_PATH=$CONDA_BUILD_SYSROOT/lib:$CONDA_PREFIX/lib \ - sip-wheel --verbose --link-args=$RPATH_OPTION_2 --build-dir=build +if [ "$OSTYPE" == "linux-gnu" ]; then + SIP_EXTRA_ARGS="--link-args=$RPATH_OPTION_2" + POPPLER_LIB_DIR=installed-poppler/lib64 +else + SIP_EXTRA_ARGS= + POPPLER_LIB_DIR=installed-poppler/lib +fi + +PKG_CONFIG_LIBDIR=$POPPLER_LIB_DIR/pkgconfig:$CONDA_PREFIX/lib/pkgconfig \ + sip-wheel --verbose $SIP_EXTRA_ARGS --build-dir=build # Unpack wheel to tinker with it WHEEL=(python_poppler_qt5*.whl) -wheel unpack $WHEEL +wheel unpack "$WHEEL" pushd python_poppler_qt5-$PYTHON_POPPLER_QT5_VERSION # Vendor libopenjp2 and libjpeg -cp ../installed-poppler/lib64/*.so* \ - $CONDA_PREFIX/lib/libopenjp2.so* \ - $CONDA_PREFIX/lib/libjpeg.so* \ - PyQt5/Qt5/lib/ +if [ "$OSTYPE" == "linux-gnu" ]; then + LIB_FILES="../$POPPLER_LIB_DIR/*.so* $CONDA_PREFIX/lib/libopenjp2.so* $CONDA_PREFIX/lib/libjpeg.so*" +else + LIB_FILES="../$POPPLER_LIB_DIR/*.dylib* $CONDA_PREFIX/lib/libopenjp2.dylib* $CONDA_PREFIX/lib/libjpeg.dylib*" +fi + +cp $LIB_FILES PyQt5/Qt5/lib/ + +pushd PyQt5/Qt5/lib +if [ "$OSTYPE" != "linux-gnu" ]; then + for file in _popplerqt5*.so libpoppler*.dylib; do + install_name_tool -delete_rpath "$CONDA_PREFIX/lib" "$file" + install_name_tool -add_rpath "@loader_path" "$file" + done +fi +popd # Repack the wheel popd