Merge pull request #4890 from nulano/mingw-setup

This commit is contained in:
Hugo van Kemenade 2020-09-03 21:11:39 +03:00 committed by GitHub
commit 63d8a600cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 22 deletions

View File

@ -244,6 +244,7 @@ jobs:
${{ matrix.package }}-libimagequant \ ${{ matrix.package }}-libimagequant \
${{ matrix.package }}-libjpeg-turbo \ ${{ matrix.package }}-libjpeg-turbo \
${{ matrix.package }}-libraqm \ ${{ matrix.package }}-libraqm \
${{ matrix.package }}-libtiff \
${{ matrix.package }}-libwebp \ ${{ matrix.package }}-libwebp \
${{ matrix.package }}-openjpeg2 \ ${{ matrix.package }}-openjpeg2 \
subversion subversion
@ -253,9 +254,7 @@ jobs:
pushd depends && ./install_extra_test_images.sh && popd pushd depends && ./install_extra_test_images.sh && popd
- name: Build Pillow - name: Build Pillow
run: | run: CFLAGS="-coverage" python3 setup.py build_ext install
# libtiff is unable to open files
CFLAGS="-coverage" python3 setup.py build_ext --disable-tiff install
- name: Test Pillow - name: Test Pillow
run: | run: |

View File

@ -64,6 +64,8 @@ for raqm, libimagequant, and libxcb::
python3 -m pip install --upgrade pip python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow python3 -m pip install --upgrade Pillow
To install Pillow in MSYS2, see `Building on Windows using MSYS2/MinGW`_.
macOS Installation macOS Installation
^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^
@ -299,6 +301,42 @@ If you wish to compile Pillow manually, you can use the build scripts
in the ``winbuild`` directory used for CI testing and development. in the ``winbuild`` directory used for CI testing and development.
These scripts require Visual Studio 2017 or newer and NASM. These scripts require Visual Studio 2017 or newer and NASM.
Building on Windows using MSYS2/MinGW
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To build Pillow using MSYS2, make sure you run the **MSYS2 MinGW 32-bit** or
**MSYS2 MinGW 64-bit** console, *not* **MSYS2** directly.
The following instructions target the 64-bit build, for 32-bit
replace all occurrences of ``mingw-w64-x86_64-`` with ``mingw-w64-i686-``.
Make sure you have Python and GCC installed::
pacman -S \
mingw-w64-x86_64-gcc \
mingw-w64-x86_64-python3 \
mingw-w64-x86_64-python3-pip \
mingw-w64-x86_64-python3-setuptools
Prerequisites are installed on **MSYS2 MinGW 64-bit** with::
pacman -S \
mingw-w64-x86_64-libjpeg-turbo \
mingw-w64-x86_64-zlib \
mingw-w64-x86_64-libtiff \
mingw-w64-x86_64-freetype \
mingw-w64-x86_64-lcms2 \
mingw-w64-x86_64-libwebp \
mingw-w64-x86_64-openjpeg2 \
mingw-w64-x86_64-libimagequant \
mingw-w64-x86_64-libraqm
Now install Pillow with::
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
Building on FreeBSD Building on FreeBSD
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^

View File

@ -133,18 +133,6 @@ class RequiredDependencyException(Exception):
PLATFORM_MINGW = os.name == "nt" and "GCC" in sys.version PLATFORM_MINGW = os.name == "nt" and "GCC" in sys.version
PLATFORM_PYPY = hasattr(sys, "pypy_version_info") PLATFORM_PYPY = hasattr(sys, "pypy_version_info")
if sys.platform == "win32" and PLATFORM_MINGW:
from distutils import cygwinccompiler
cygwin_versions = cygwinccompiler.get_versions()
if cygwin_versions[1] is None:
# ld version is None
# distutils cygwinccompiler might fetch the ld path from gcc
# Try the normal path instead
cygwin_versions = list(cygwin_versions)
cygwin_versions[1] = cygwinccompiler._find_exe_version("ld -v")
cygwinccompiler.get_versions = lambda: tuple(cygwin_versions)
def _dbg(s, tp=None): def _dbg(s, tp=None):
if DEBUG: if DEBUG:
@ -528,11 +516,6 @@ class pil_build_ext(build_ext):
_add_directory(library_dirs, "/lib") _add_directory(library_dirs, "/lib")
if sys.platform == "win32": if sys.platform == "win32":
if PLATFORM_MINGW:
_add_directory(
include_dirs, "C:\\msys64\\mingw32\\include\\libimagequant"
)
# on Windows, look for the OpenJPEG libraries in the location that # on Windows, look for the OpenJPEG libraries in the location that
# the official installer puts them # the official installer puts them
program_files = os.environ.get("ProgramFiles", "") program_files = os.environ.get("ProgramFiles", "")
@ -727,6 +710,10 @@ class pil_build_ext(build_ext):
if feature.tiff: if feature.tiff:
libs.append(feature.tiff) libs.append(feature.tiff)
defs.append(("HAVE_LIBTIFF", None)) defs.append(("HAVE_LIBTIFF", None))
# FIXME the following define should be detected automatically
# based on system libtiff, see #4237
if PLATFORM_MINGW:
defs.append(("USE_WIN32_FILEIO", None))
if feature.xcb: if feature.xcb:
libs.append(feature.xcb) libs.append(feature.xcb)
defs.append(("HAVE_XCB", None)) defs.append(("HAVE_XCB", None))

View File

@ -20,6 +20,17 @@
#include "TiffDecode.h" #include "TiffDecode.h"
/* Convert C file descriptor to WinApi HFILE if LibTiff was compiled with tif_win32.c
*
* This cast is safe, as the top 32-bits of HFILE are guaranteed to be zero,
* see https://docs.microsoft.com/en-us/windows/win32/winprog64/interprocess-communication
*/
#ifndef USE_WIN32_FILEIO
#define fd_to_tiff_fd(fd) (fd)
#else
#define fd_to_tiff_fd(fd) ((int)_get_osfhandle(fd))
#endif
void dump_state(const TIFFSTATE *state){ void dump_state(const TIFFSTATE *state){
TRACE(("State: Location %u size %d eof %d data: %p ifd: %d\n", (uint)state->loc, TRACE(("State: Location %u size %d eof %d data: %p ifd: %d\n", (uint)state->loc,
(int)state->size, (uint)state->eof, state->data, state->ifd)); (int)state->size, (uint)state->eof, state->data, state->ifd));
@ -316,7 +327,7 @@ int ImagingLibTiffDecode(Imaging im, ImagingCodecState state, UINT8* buffer, Py_
if (clientstate->fp) { if (clientstate->fp) {
TRACE(("Opening using fd: %d\n",clientstate->fp)); TRACE(("Opening using fd: %d\n",clientstate->fp));
lseek(clientstate->fp,0,SEEK_SET); // Sometimes, I get it set to the end. lseek(clientstate->fp,0,SEEK_SET); // Sometimes, I get it set to the end.
tiff = TIFFFdOpen(clientstate->fp, filename, mode); tiff = TIFFFdOpen(fd_to_tiff_fd(clientstate->fp), filename, mode);
} else { } else {
TRACE(("Opening from string\n")); TRACE(("Opening from string\n"));
tiff = TIFFClientOpen(filename, mode, tiff = TIFFClientOpen(filename, mode,
@ -521,7 +532,7 @@ int ImagingLibTiffEncodeInit(ImagingCodecState state, char *filename, int fp) {
if (fp) { if (fp) {
TRACE(("Opening using fd: %d for writing \n",clientstate->fp)); TRACE(("Opening using fd: %d for writing \n",clientstate->fp));
clientstate->tiff = TIFFFdOpen(clientstate->fp, filename, mode); clientstate->tiff = TIFFFdOpen(fd_to_tiff_fd(clientstate->fp), filename, mode);
} else { } else {
// malloc a buffer to write the tif, we're going to need to realloc or something if we need bigger. // malloc a buffer to write the tif, we're going to need to realloc or something if we need bigger.
TRACE(("Opening a buffer for writing \n")); TRACE(("Opening a buffer for writing \n"));