8000 BLD: Switch to static linking by default on windows · matplotlib/matplotlib@44ed274 · GitHub
[go: up one dir, main page]

Skip to content

Commit 44ed274

Browse files
Kojoleytacaswell
authored andcommitted
BLD: Switch to static linking by default on windows
1 parent 627624c commit 44ed274

File tree

6 files changed

+43
-48
lines changed

6 files changed

+43
-48
lines changed

.appveyor.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,6 @@ install:
7676
curl -sL https://github.com/python/cpython/pull/1224.patch |
7777
patch -fsup 1 -d %CONDA_PREFIX% ) || cmd /c "exit /b 0"
7878

79-
# Let the install prefer the static builds of the libs
80-
- set LIBRARY_LIB=%CONDA_PREFIX%\Library\lib
81-
- mkdir lib || cmd /c "exit /b 0"
82-
- copy /y %LIBRARY_LIB%\zlibstatic.lib lib\zlib.lib
83-
- copy /y %LIBRARY_LIB%\libpng16_static.lib lib\libpng16.lib
84-
# These z.lib / png.lib are not static versions but files which end up as
85-
# dependencies to the dll file. This is fine for the conda build, but not here
86-
# and for the wheels
87-
- del %LIBRARY_LIB%\png.lib
88-
- del %LIBRARY_LIB%\z.lib
8979
# enables the local freetype build
9080
- set MPLLOCALFREETYPE=1
9181
# Show the installed packages + versions
@@ -97,9 +87,9 @@ test_script:
9787
- pip install -ve .
9888
# these should show no z, png, or freetype dll...
9989
- set "DUMPBIN=%VS140COMNTOOLS%\..\..\VC\bin\dumpbin.exe"
100-
- '"%DUMPBIN%" /DEPENDENTS lib\matplotlib\ft2font*.pyd | findstr freetype.*.dll && exit /b 1 || exit /b 0'
101-
- '"%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd | findstr z.*.dll && exit /b 1 || exit /b 0'
102-
- '"%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd | findstr png.*.dll && exit /b 1 || exit /b 0'
90+
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\ft2font*.pyd | findstr freetype.*.dll && exit /b 1 || exit /b 0'
91+
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd | findstr z.*.dll && exit /b 1 || exit /b 0'
92+
- 'if x%MPLSTATICBUILD% == xTrue "%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd | findstr png.*.dll && exit /b 1 || exit /b 0'
10393

10494
# this are optional dependencies so that we don't skip so many tests...
10595
- if x%TEST_ALL% == xyes conda install -q ffmpeg inkscape miktex pillow
@@ -116,6 +106,7 @@ test_script:
116106
after_test:
117107
# After the tests were a success, build wheels with the static libs
118108
# Hide the output, the copied files really clutter the build log...
109+
- set MPLSTATICBUILD=True
119110
- 'python setup.py bdist_wheel > NUL:'
120111
- dir dist\
121112
- echo finished...

INSTALL.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,10 @@ the list of conda packages.
307307

308308
conda create -n "matplotlib_build" python=3.7 numpy python-dateutil pyparsing tornado cycler tk libpng zlib freetype msinttypes
309309
conda activate matplotlib_build
310+
# force the build against static libpng and zlib libraries
311+
set MPLSTATICBUILD=True
312+
python setup.py bdist_wheel
310313

311-
For building, call the script ``build_alllocal.cmd`` in the root folder of the
312-
repository::
313-
314-
build_alllocal.cmd
315314

316315
Conda packages
317316
^^^^^^^^^^^^^^

build_alllocal.cmd

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

ci/azure-pipelines-steps.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ steps:
2222

2323
- script: |
2424
nuget install libpng-msvc14-x64 -ExcludeVersion -OutputDirectory "$(build.BinariesDirectory)"
25-
echo ##vso[task.setvariable variable=CL]/I$(build.BinariesDirectory)\libpng-msvc14-x64\build\native\include
26-
echo ##vso[task.setvariable variable=LINK]/LIBPATH:$(build.BinariesDirectory)\libpng-msvc14-x64\build\native\lib_release
25+
nuget install zlib-msvc14-x64 -ExcludeVersion -OutputDirectory "$(build.BinariesDirectory)"
2726
echo ##vso[task.prependpath]$(build.BinariesDirectory)\libpng-msvc14-x64\build\native\bin_release
27+
echo ##vso[task.prependpath]$(build.BinariesDirectory)\zlib-msvc14-x64\build\native\bin_release
28+
echo ##vso[task.setvariable variable=CL]/I$(build.BinariesDirectory)\libpng-msvc14-x64\build\native\include /I$(build.BinariesDirectory)\zlib-msvc14-x64\build\native\include
29+
echo ##vso[task.setvariable variable=LINK]/LIBPATH:$(build.BinariesDirectory)\libpng-msvc14-x64\build\native\lib_release /LIBPATH:$(build.BinariesDirectory)\zlib-msvc14-x64\build\native\lib_release
30+
2831
displayName: 'Install dependencies with nuget'
2932
3033
- ${{ if eq(parameters.installer, 'brew') }}:

setup.cfg.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@
6161
# modules. The default is determined by fallback.
6262
#
6363
#backend = Agg
64+
65+
[build]
66+
# Build options
67+
# If we should try to use static libraries on Windows
68+
#staticbuild = True

setupext.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def write_cache(local_fn, data):
151151
# matplotlib build options, which can be altered using setup.cfg
152152
options = {
153153
'backend': None,
154+
'staticbuild': False,
154155
}
155156

156157

@@ -164,12 +165,18 @@ def write_cache(local_fn, data):
164165

165166
if config.has_option('test', 'local_freetype'):
166167
options['local_freetype'] = config.getboolean("test", "local_freetype")
168+
169+
if config.has_option('build', 'staticbuild'):
170+
options['staticbuild'] = config.getboolean("build", "staticbuild")
167171
else:
168172
config = None
169173

170174
lft = bool(os.environ.get('MPLLOCALFREETYPE', False))
171175
options['local_freetype'] = lft or options.get('local_freetype', False)
172176

177+
staticbuild = bool(os.environ.get('MPLSTATICBUILD', os.name == 'nt'))
178+
options['staticbuild'] = staticbuild or options.get('staticbuild', False)
179+
173180

174181
if '-q' in sys.argv or '--quiet' in sys.argv:
175182
def print_raw(*args, **kwargs): pass # Suppress our own output.
@@ -195,6 +202,23 @@ def get_buffer_hash(fd):
195202
return hasher.hexdigest()
196203

197204

205+
def deplib(libname):
206+
if sys.platform != 'win32':
207+
return libname
208+
209+
known_libs = {
210+
# TODO: support versioned libpng on build system rewrite
211+
'libpng16': ('libpng16', '_static'),
212+
'z': ('zlib', 'static'),
213+
}
214+
215+
libname, static_postfix = known_libs[libname]
216+
if options['staticbuild']:
217+
libname += static_postfix
218+
219+
return libname
220+
221+
198222
@functools.lru_cache(1) # We only need to compute this once.
199223
def get_pkg_config():
200224
"""
@@ -501,7 +525,7 @@ def add_flags(self, ext):
501525
ext, 'freetype2',
502526
atleast_version='9.11.3',
503527
alt_exec=['freetype-config'],
504-
default_libraries=['freetype', 'z'])
528+
default_libraries=['freetype', deplib('z')])
505529
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))
506530

507531
def do_custom_build(self):
@@ -635,7 +659,7 @@ def get_extension(self):
635659
default_libraries=(
636660
['png', 'z'] if os.name == 'posix' else
637661
# libpng upstream names their lib libpng16.lib, not png.lib.
638-
['libpng16'] if os.name == 'nt' else
662+
[deplib('libpng16'), deplib('z')] if os.name == 'nt' else
639663
[]
640664
))
641665
add_numpy_flags(ext)

0 commit comments

Comments
 (0)
0