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

Skip to content

Commit f650c67

Browse files
committed
BLD: Simplify library linking on Windows
1 parent ba4142a commit f650c67

File tree

4 files changed

+31
-65
lines changed

4 files changed

+31
-65
lines changed

.appveyor.yml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ environment:
2828
- PYTHON_VERSION: "3.6"
2929
CONDA_INSTALL_LOCN: "C:\\Miniconda36-x64"
3030
TEST_ALL: "no"
31+
MPLSTATICBUILD: True
3132

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

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

10292
# this are optional dependencies so that we don't skip so many tests...
10393
- if x%TEST_ALL% == xyes conda install -q ffmpeg inkscape miktex pillow
@@ -114,6 +104,7 @@ test_script:
114104
after_test:
115105
# After the tests were a success, build wheels with the static libs
116106
# Hide the output, the copied files really clutter the build log...
107+
- set MPLSTATICBUILD=True
117108
- 'python setup.py bdist_wheel > NUL:'
118109
- dir dist\
119110
- echo finished...

INSTALL.rst

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,22 +332,12 @@ without fiddling with environment variables::
332332
# for Python 2.7
333333
conda install -c conda-forge backports.functools_lru_cache
334334

335-
# copy the libs which have "wrong" names
336-
set LIBRARY_LIB=%CONDA_DEFAULT_ENV%\Library\lib
337-
mkdir lib || cmd /c "exit /b 0"
338-
copy %LIBRARY_LIB%\zlibstatic.lib lib\z.lib
339-
copy %LIBRARY_LIB%\libpng_static.lib lib\png.lib
340-
341-
# Make the header files and the rest of the static libs available during the build
342-
# CONDA_DEFAULT_ENV is a env variable which is set to the currently active environment path
343-
set MPLBASEDIRLIST=%CONDA_DEFAULT_ENV%\Library\;.
335+
# force the build against static libpng and zlib libraries
336+
set MPLSTATICBUILD=True
344337

345338
# build the wheel
346339
python setup.py bdist_wheel
347340

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

352342
Conda packages
353343
^^^^^^^^^^^^^^

build_alllocal.cmd

Lines changed: 0 additions & 36 deletions
This file was deleted.

setupext.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def _get_xdg_cache_dir():
8888
'display_status': True,
8989
'verbose': False,
9090
'backend': None,
91-
'basedirlist': None
91+
'basedirlist': None,
92+
'staticbuild': False,
9293
}
9394

9495

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

123+
staticbuild = bool(os.environ.get('MPLSTATICBUILD', True))
124+
options['staticbuild'] = staticbuild or options.get('staticbuild', False)
125+
122126

123127
def get_win32_compiler():
124128
"""
@@ -307,6 +311,23 @@ def get_file_hash(filename):
307311
return hasher.hexdigest()
308312

309313

314+
def deplib(libname):
315+
if sys.platform != 'win32':
316+
return libname
317+
318+
known_libs = {
319+
# TODO: support versioned libpng on build system revrite
320+
'png': ('libpng', '_static'),
321+
'z': ('zlib', 'static'),
322+
}
323+
324+
libname, static_postfix = known_libs[libname]
325+
if options['staticbuild']:
326+
libname += static_postfix
327+
328+
return libname
329+
330+
310331
class PkgConfig(object):
311332
"""
312333
This is a class for communicating with pkg-config.
@@ -1122,7 +1143,7 @@ def add_flags(self, ext):
11221143
'lib/freetype2/include/freetype2'],
11231144
default_library_dirs=[
11241145
'freetype2/lib'],
1125-
default_libraries=['freetype', 'z'])
1146+
default_libraries=['freetype', deplib('z')])
11261147
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))
11271148

11281149
def do_custom_build(self):
@@ -1320,7 +1341,7 @@ def get_extension(self):
13201341
]
13211342
ext = make_extension('matplotlib._png', sources)
13221343
pkg_config.setup_extension(
1323-
ext, 'libpng', default_libraries=['png', 'z'],
1344+
ext, 'libpng', default_libraries=map(deplib, ['png', 'z']),
13241345
alt_exec='libpng-config --ldflags')
13251346
Numpy().add_flags(ext)
13261347
return ext

0 commit comments

Comments
 (0)