8000 CI: Fix FreeType build. · matplotlib/matplotlib@6c7e672 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c7e672

Browse files
anntzertacaswell
authored andcommitted
CI: Fix FreeType build.
1 parent 0ff669f commit 6c7e672

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ exclude =
2828

2929
per-file-ignores =
3030
setup.py: E402
31+
setupext.py: E501
3132

3233
tools/subset.py: E221, E251, E261, E302, E501
3334

ci/azure-pipelines-steps.yml

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

2323
- script: |
2424
nuget install libpng-msvc14-x64 -ExcludeVersion -OutputDirectory "$(build.BinariesDirectory)"
25-
echo ##vso[task.setvariable variable=MPLBASEDIRLIST]win32_static;$(build.BinariesDirectory)\libpng-msvc14-x64\build\native
26-
echo ##vso[task.setvariable variable=LIBDIR]%LIBDIR%;$(build.BinariesDirectory)\libpng-msvc14-x64\build\native\lib_release
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
2727
echo ##vso[task.prependpath]$(build.BinariesDirectory)\libpng-msvc14-x64\build\native\bin_release
2828
displayName: 'Install dependencies with nuget'
2929

setupext.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import configparser
2-
from distutils import sysconfig
2+
from distutils import ccompiler, sysconfig
33
from distutils.core import Extension
44
import functools
55
import glob
@@ -569,30 +569,35 @@ def do_custom_build(self):
569569
subprocess.check_call(["make"], env=env, cwd=src_path)
570570
else:
571571
# compilation on windows
572-
shutil.rmtree(pathlib.Path(src_path, "objs"), ignore_errors=True)
573-
import distutils.msvc9compiler as msvc
574-
# FreeType has no build profile for 2014, so we don't bother.
572+
shutil.rmtree(str(pathlib.Path(src_path, "objs")),
573+
ignore_errors=True)
574+
msbuild_platform = (
575+
'x64' if platform.architecture()[0] == '64bit' else 'Win32')
576+
base_path = pathlib.Path("build/freetype-2.6.1/builds/windows")
575577
vc = 'vc2010'
576-
WinXX = 'x64' if platform.architecture()[0] == '64bit' else 'Win32'
577-
xXX = 'x64' if platform.architecture()[0] == '64bit' else 'x86'
578-
vcvarsall = msvc.find_vcvarsall(10.0)
579-
if vcvarsall is None:
580-
raise RuntimeError('Microsoft VS 2010 required')
581-
cmdfile = pathlib.Path("build/build_freetype.cmd")
582-
cmdfile.write_text(fr"""
583-
call "%ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" ^
584-
/Release /{xXX} /xp
585-
call "{vcvarsall}" {xXX}
586-
set MSBUILD=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
587-
%MSBUILD% "builds\windows\{vc}\freetype.sln" ^
588-
/t:Clean;Build /p:Configuration="Release";Platform={WinXX}
578+
sln_path = (
579+
base_path / vc / "freetype.sln"
580+
)
581+
# https://developercommunity.visualstudio.com/comments/190992/view.html
582+
(sln_path.parent / "Directory.Build.props").write_text("""
583+
<Project>
584+
<PropertyGroup>
585+
<!-- The following line *cannot* be split over multiple lines. -->
586+
<WindowsTargetPlatformVersion>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetLatestSDKTargetPlatformVersion('Windows', '10.0'))</WindowsTargetPlatformVersion>
587+
</PropertyGroup>
588+
</Project>
589589
""")
590-
subprocess.check_call([str(cmdfile.resolve())],
591-
shell=True, cwd=src_path)
590+
cc = ccompiler.new_compiler()
591+
cc.initialize() # Get devenv & msbuild in the %PATH% of cc.spawn.
592+
cc.spawn(["devenv", str(sln_path), "/upgrade"])
593+
cc.spawn(["msbuild", str(sln_path),
594+
"/t:Clean;Build",
595+
f"/p:Configuration=Release;Platform={msbuild_platform}"])
592596
# Move to the corresponding Unix build path.
593597
(src_path / "objs" / ".libs").mkdir()
594598
# Be robust against change of FreeType version.
595-
lib_path, = (src_path / "objs" / vc / xXX).glob("freetype*.lib")
599+
lib_path, = (src_path / "objs" / vc / msbuild_platform).glob(
600+
"freetype*.lib")
596601
shutil.copy2(lib_path, src_path / "objs/.libs/libfreetype.lib")
597602

598603

@@ -630,8 +635,7 @@ def get_extension(self):
630635
default_libraries=(
631636
['png', 'z'] if os.name == 'posix' else
632637
# libpng upstream names their lib libpng16.lib, not png.lib.
633-
# zlib upstream names their lib zlib.lib, not z.lib.
634-
['libpng16', 'zlib'] if os.name == 'nt' else
638+
['libpng16'] if os.name == 'nt' else
635639
[]
636640
))
637641
add_numpy_flags(ext)

0 commit comments

Comments
 (0)
0