Skip to content

Commit

Permalink
Correct handling of vendored fribidi.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Nov 6, 2024
1 parent 51e3623 commit e82b539
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
46 changes: 31 additions & 15 deletions .github/workflows/wheels-dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
#!/bin/bash

# Setup that needs to be done before multibuild utils are invoked
PROJECTDIR=$(pwd)
if [[ "$(uname -s)" == "Darwin" ]]; then
# Build and install macOS builds into the `build/deps` folder.
BUILD_PREFIX=$(pwd)/build/deps
# Safety check - macOS builds require that CIBW_ARCHS is set, and that it
# only contains a single value (even though cwbuildwheel) allows multiple
# values in CIBW_ARCHS.
if [[ -z "$CIBW_ARCHS" ]]; then
echo "ERROR: Pillow macOS builds require CIBW_ARCHS be defined."
exit 1
fi
if [[ "$CIBW_ARCHS" == *" "* ]]; then
echo "ERROR: Pillow macOS builds only support a single architecture in CIBW_ARCHS."
exit 1
fi

# Build macOS dependencies in `build/darwin`
# Install them into `build/deps/darwin`
WORKDIR=$(pwd)/build/darwin
BUILD_PREFIX=$(pwd)/build/deps/darwin
PLAT=$CIBW_ARCHS
else
export MB_ML_LIBC=${AUDITWHEEL_POLICY::9}
export MB_ML_VER=${AUDITWHEEL_POLICY:9}
# Build prefix will default to /usr/local
WORKDIR=$(pwd)/build
PLAT=$CIBW_ARCHS
MB_ML_LIBC=${AUDITWHEEL_POLICY::9}
MB_ML_VER=${AUDITWHEEL_POLICY:9}
fi

# Define custom utilities
export PLAT=$CIBW_ARCHS
source wheels/multibuild/common_utils.sh
source wheels/multibuild/library_builders.sh
if [ -z "$IS_MACOS" ]; then
Expand Down Expand Up @@ -117,17 +135,14 @@ function build {

ORIGINAL_CFLAGS=$CFLAGS
CFLAGS="$CFLAGS -O3 -DNDEBUG"
if [[ -n "$IS_MACOS" ]]; then
CFLAGS="$CFLAGS -Wl,-headerpad_max_install_names"
fi
build_libwebp
CFLAGS=$ORIGINAL_CFLAGS

build_brotli

if [ -n "$IS_MACOS" ]; then
# Custom freetype build
build_simple freetype $FREETYPE_VERSION https://download.savannah.gnu.org/releases/freetype tar.gz --with-harfbuzz=no
build_simple freetype $FREETYPE_VERSION https://download.savannah.gnu.org/releases/freetype tar.gz --without-harfbuzz
else
build_freetype
fi
Expand All @@ -136,17 +151,18 @@ function build {
}

# Perform all dependency builds in the build subfolder.
mkdir -p build
pushd build > /dev/null
mkdir -p $WORKDIR
pushd $WORKDIR > /dev/null

# Any stuff that you need to do before you start building the wheels
# Runs in the root directory of this repository.
if [[ ! -d pillow-depends-main ]]; then
if [[ ! -f pillow-depends-main.zip ]]; then
if [[ ! -d $WORKDIR/pillow-depends-main ]]; then
if [[ ! -f $PROJECTDIR/pillow-depends-main.zip ]]; then
echo "Download pillow dependency sources..."
curl -fSL -o pillow-depends-main.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
curl -fSL -o $PROJECTDIR/pillow-depends-main.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
fi
untar pillow-depends-main.zip
echo "Unpacking pillow dependency sources..."
untar $PROJECTDIR/pillow-depends-main.zip
fi

if [[ -n "$IS_MACOS" ]]; then
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/wheels-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
fi
$HOMEBREW_HOME/bin/brew install fribidi

# Add the Homebrew lib folder so that vendored libraries can be found.
export DYLD_LIBRARY_PATH=$HOMEBREW_HOME/lib
# Add the lib folder for fribidi so that the vendored library can be found.
# Don't use /opt/homebrew/lib directly - use the lib folder where the
# installed copy of fribidi is cellared. This ensures we don't pick up the
# Homebrew version of any other library that we're dependent on (most notably,
# freetype).
export DYLD_LIBRARY_PATH=$(dirname $(realpath $HOMEBREW_HOME/lib/libfribidi.dylib))
elif [ "${AUDITWHEEL_POLICY::9}" == "musllinux" ]; then
apk add curl fribidi
else
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,9 @@ Tests/images/msp
Tests/images/picins
Tests/images/sunraster

# Test and dependency downloads
pillow-depends-main.zip
pillow-test-images.zip

# pyinstaller
*.spec
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ build-verbosity = 1

config-settings = "raqm=enable raqm=vendor fribidi=vendor imagequant=disable"
# Add an explicit dependencies prefix for macOS.
macos.config-settings = "raqm=enable raqm=vendor fribidi=vendor imagequant=disable dependencies-prefix=./build/deps"
macos.config-settings = "raqm=enable raqm=vendor fribidi=vendor imagequant=disable dependencies-prefix=./build/deps/darwin"

test-command = "cd {project} && .github/workflows/wheels-test.sh"
test-extras = "tests"

[tool.cibuildwheel.macos.environment]
PATH = "$(pwd)/build/deps/bin:$(dirname $(which python3)):/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
PATH = "$(pwd)/build/deps/darwin/bin:$(dirname $(which python3)):/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"

[tool.black]
exclude = "wheels/multibuild"
Expand Down

0 comments on commit e82b539

Please sign in to comment.