|
| 1 | +#!/bin/bash |
| 2 | +# Define custom utilities |
| 3 | +# Setup that needs to be done before multibuild utils are invoked |
| 4 | +PROJECTDIR=$(pwd) |
| 5 | +if [[ "$(uname -s)" == "Darwin" ]]; then |
| 6 | + # Safety check - macOS builds require that CIBW_ARCHS is set, and that it |
| 7 | + # only contains a single value (even though cibuildwheel allows multiple |
| 8 | + # values in CIBW_ARCHS). |
| 9 | + if [[ -z "$CIBW_ARCHS" ]]; then |
| 10 | + echo "ERROR: Pillow macOS builds require CIBW_ARCHS be defined." |
| 11 | + exit 1 |
| 12 | + fi |
| 13 | + if [[ "$CIBW_ARCHS" == *" "* ]]; then |
| 14 | + echo "ERROR: Pillow macOS builds only support a single architecture in CIBW_ARCHS." |
| 15 | + exit 1 |
| 16 | + fi |
| 17 | + |
| 18 | + # Build macOS dependencies in `build/darwin` |
| 19 | + # Install them into `build/deps/darwin` |
| 20 | + export WORKDIR=$(pwd)/build/darwin |
| 21 | + export BUILD_PREFIX=$(pwd)/build/deps/darwin |
| 22 | +else |
| 23 | + # Build prefix will default to /usr/local |
| 24 | + export WORKDIR=$(pwd)/build |
| 25 | + export MB_ML_LIBC=${AUDITWHEEL_POLICY::9} |
| 26 | + export MB_ML_VER=${AUDITWHEEL_POLICY:9} |
| 27 | +fi |
| 28 | +export PLAT="${CIBW_ARCHS:-$AUDITWHEEL_ARCH}" |
| 29 | + |
| 30 | +source multibuild/common_utils.sh |
| 31 | +source multibuild/library_builders.sh |
| 32 | +if [ -z "$IS_MACOS" ]; then |
| 33 | + source multibuild/manylinux_utils.sh |
| 34 | +fi |
| 35 | + |
| 36 | +source wheelbuild/config.sh |
| 37 | + |
| 38 | +function build_pkg_config { |
| 39 | + if [ -e pkg-config-stamp ]; then return; fi |
| 40 | + # This essentially duplicates the Homebrew recipe |
| 41 | + CFLAGS="$CFLAGS -Wno-int-conversion" build_simple pkg-config 0.29.2 https://pkg-config.freedesktop.org/releases tar.gz \ |
| 42 | + --disable-debug --disable-host-tool --with-internal-glib \ |
| 43 | + --with-pc-path=$BUILD_PREFIX/share/pkgconfig:$BUILD_PREFIX/lib/pkgconfig \ |
| 44 | + --with-system-include-path=$(xcrun --show-sdk-path --sdk macosx)/usr/include |
| 45 | + export PKG_CONFIG=$BUILD_PREFIX/bin/pkg-config |
| 46 | + touch pkg-config-stamp |
| 47 | +} |
| 48 | + |
| 49 | +function build { |
| 50 | + if [[ -n "$IS_MACOS" ]] && [[ "$CIBW_ARCHS" == "arm64" ]]; then |
| 51 | + sudo chown -R runner /usr/local |
| 52 | + fi |
| 53 | + pre_build |
| 54 | +} |
| 55 | + |
| 56 | +if [[ -n "$IS_MACOS" ]]; then |
| 57 | + # Homebrew (or similar packaging environments) install can contain some of |
| 58 | + # the libraries that we're going to build. However, they may be compiled |
| 59 | + # with a MACOSX_DEPLOYMENT_TARGET that doesn't match what we want to use, |
| 60 | + # and they may bring in other dependencies that we don't want. The same will |
| 61 | + # be true of any other locations on the path. To avoid conflicts, strip the |
| 62 | + # path down to the bare minimum (which, on macOS, won't include any |
| 63 | + # development dependencies). |
| 64 | + export PATH="$BUILD_PREFIX/bin:$(dirname $(which python3)):/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin" |
| 65 | + export CMAKE_PREFIX_PATH=$BUILD_PREFIX |
| 66 | + |
| 67 | + # Ensure the basic structure of the build prefix directory exists. |
| 68 | + mkdir -p "$BUILD_PREFIX/bin" |
| 69 | + mkdir -p "$BUILD_PREFIX/lib" |
| 70 | + |
| 71 | + # Ensure pkg-config is available |
| 72 | + build_pkg_config |
| 73 | + # Ensure cmake is available |
| 74 | + python3 -m pip install cmake |
| 75 | +fi |
| 76 | + |
| 77 | +# Perform all dependency builds in the build subfolder. |
| 78 | +mkdir -p $WORKDIR |
| 79 | +pushd $WORKDIR > /dev/null |
| 80 | + |
| 81 | +wrap_wheel_builder build |
| 82 | + |
| 83 | +# Return to the project root to finish the build |
| 84 | +popd > /dev/null |
0 commit comments