Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BLD: Simplify library linking on Windows #9693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ environment:
- PYTHON_VERSION: "3.6"
CONDA_INSTALL_LOCN: "C:\\Miniconda36-x64"
TEST_ALL: "no"
MPLSTATICBUILD: True

# We always use a 64-bit machine, but can build x86 distributions
# with the PYTHON_ARCH variable
Expand Down Expand Up @@ -74,17 +75,6 @@ install:
curl -sL https://github.com/python/cpython/pull/1224.patch |
patch -fsup 1 -d %CONDA_PREFIX% ) || cmd /c "exit /b 0"

# Let the install prefer the static builds of the libs
- set LIBRARY_LIB=%CONDA_PREFIX%\Library\lib
- mkdir lib || cmd /c "exit /b 0"
- copy /y %LIBRARY_LIB%\zlibstatic.lib lib\z.lib
- copy /y %LIBRARY_LIB%\libpng_static.lib lib\png.lib
# These z.lib / png.lib are not static versions but files which end up as
# dependencies to the dll file. This is fine for the conda build, but not here
# and for the wheels
- del %LIBRARY_LIB%\png.lib
- del %LIBRARY_LIB%\z.lib
- set MPLBASEDIRLIST=%CONDA_PREFIX%\Library\;.
# enables the local freetype build
- copy ci\travis\setup.cfg .
# Show the installed packages + versions
Expand All @@ -95,9 +85,9 @@ test_script:
- pip install -ve .
# these should show no z, png, or freetype dll...
- set "DUMPBIN=%VS140COMNTOOLS%\..\..\VC\bin\dumpbin.exe"
- '"%DUMPBIN%" /DEPENDENTS lib\matplotlib\ft2font*.pyd | findstr freetype.*.dll && exit /b 1 || exit /b 0'
- '"%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd | findstr z.*.dll && exit /b 1 || exit /b 0'
- '"%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd | findstr png.*.dll && exit /b 1 || exit /b 0'
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\ft2font*.pyd | findstr freetype.*.dll && exit /b 1 || exit /b 0'
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd | findstr z.*.dll && exit /b 1 || exit /b 0'
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd | findstr png.*.dll && exit /b 1 || exit /b 0'

# this are optional dependencies so that we don't skip so many tests...
- if x%TEST_ALL% == xyes conda install -q ffmpeg inkscape miktex pillow
Expand All @@ -114,6 +104,7 @@ test_script:
after_test:
# After the tests were a success, build wheels with the static libs
# Hide the output, the copied files really clutter the build log...
- set MPLSTATICBUILD=True
- 'python setup.py bdist_wheel > NUL:'
- dir dist\
- echo finished...
Expand Down
14 changes: 2 additions & 12 deletions INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -332,22 +332,12 @@ without fiddling with environment variables::
# for Python 2.7
conda install -c conda-forge backports.functools_lru_cache

# copy the libs which have "wrong" names
set LIBRARY_LIB=%CONDA_DEFAULT_ENV%\Library\lib
mkdir lib || cmd /c "exit /b 0"
copy %LIBRARY_LIB%\zlibstatic.lib lib\z.lib
copy %LIBRARY_LIB%\libpng_static.lib lib\png.lib

# Make the header files and the rest of the static libs available during the build
# CONDA_DEFAULT_ENV is a env variable which is set to the currently active environment path
set MPLBASEDIRLIST=%CONDA_DEFAULT_ENV%\Library\;.
# force the build against static libpng and zlib libraries
set MPLSTATICBUILD=True

# build the wheel
python setup.py bdist_wheel

The `build_alllocal.cmd` script in the root folder automates these steps if
you have already created and activated the conda environment.


Conda packages
^^^^^^^^^^^^^^
Expand Down
36 changes: 0 additions & 36 deletions build_alllocal.cmd

This file was deleted.

27 changes: 24 additions & 3 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ def _get_xdg_cache_dir():
'display_status': True,
'verbose': False,
'backend': None,
'basedirlist': None
'basedirlist': None,
'staticbuild': False,
}


Expand Down Expand Up @@ -119,6 +120,9 @@ def _get_xdg_cache_dir():
lft = bool(os.environ.get('MPLLOCALFREETYPE', False))
options['local_freetype'] = lft or options.get('local_freetype', False)

staticbuild = bool(os.environ.get('MPLSTATICBUILD', True))
options['staticbuild'] = staticbuild or options.get('staticbuild', False)


def get_win32_compiler():
"""
Expand Down Expand Up @@ -307,6 +311,23 @@ def get_file_hash(filename):
return hasher.hexdigest()


def deplib(libname):
if sys.platform != 'win32':
return libname

known_libs = {
# TODO: support versioned libpng on build system revrite
'png': ('libpng', '_static'),
'z': ('zlib', 'static'),
}

libname, static_postfix = known_libs[libname]
if options['staticbuild']:
libname += static_postfix

return libname


class PkgConfig(object):
"""
This is a class for communicating with pkg-config.
Expand Down Expand Up @@ -1122,7 +1143,7 @@ def add_flags(self, ext):
'lib/freetype2/include/freetype2'],
default_library_dirs=[
'freetype2/lib'],
default_libraries=['freetype', 'z'])
default_libraries=['freetype', deplib('z')])
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))

def do_custom_build(self):
Expand Down Expand Up @@ -1320,7 +1341,7 @@ def get_extension(self):
]
ext = make_extension('matplotlib._png', sources)
pkg_config.setup_extension(
ext, 'libpng', default_libraries=['png', 'z'],
ext, 'libpng', default_libraries=map(deplib, ['png', 'z']),
alt_exec='libpng-config --ldflags')
Numpy().add_flags(ext)
return ext
Expand Down