diff --git a/.appveyor.yml b/.appveyor.yml index a2a0f9f8c34b..5abeeba8ab7f 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -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 @@ -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 @@ -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 @@ -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... diff --git a/INSTALL.rst b/INSTALL.rst index fdcfecbf1d86..24d205e48c19 100644 --- a/INSTALL.rst +++ b/INSTALL.rst @@ -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 ^^^^^^^^^^^^^^ diff --git a/build_alllocal.cmd b/build_alllocal.cmd deleted file mode 100644 index 7a357302c4ae..000000000000 --- a/build_alllocal.cmd +++ /dev/null @@ -1,36 +0,0 @@ -:: This assumes you have installed all the dependencies via conda packages: -:: # create a new environment with the required packages -:: conda create -n "matplotlib_build" python=3.4 numpy python-dateutil pyparsing pytz tornado "cycler>=0.10" tk libpng zlib freetype -:: activate matplotlib_build -:: if you want qt backend, you also have to install pyqt -:: conda install pyqt -:: # this package is only available in the conda-forge channel -:: conda install -c conda-forge msinttypes -:: if you build on py2.7: -:: conda install -c conda-forge backports.functools_lru_cache - -set TARGET=bdist_wheel -IF [%1]==[] ( - echo Using default target: %TARGET% -) else ( - set TARGET=%1 - echo Using user supplied target: %TARGET% -) - -IF NOT DEFINED CONDA_PREFIX ( - echo No Conda env activated: you need to create a conda env with the right packages and activate it! - GOTO:eof -) - -:: copy the libs which have "wrong" names -set LIBRARY_LIB=%CONDA_PREFIX%\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_PREFIX is a env variable which is set to the currently active environment path -set MPLBASEDIRLIST=%CONDA_PREFIX%\Library\;. - -:: build the target -python setup.py %TARGET% diff --git a/setupext.py b/setupext.py index 378b366f0c0e..6499e2d1dc2f 100644 --- a/setupext.py +++ b/setupext.py @@ -88,7 +88,8 @@ def _get_xdg_cache_dir(): 'display_status': True, 'verbose': False, 'backend': None, - 'basedirlist': None + 'basedirlist': None, + 'staticbuild': False, } @@ -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(): """ @@ -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. @@ -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): @@ -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