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

Skip to content

Commit 5305ba6

Browse files
committed
Enable windows arm64 targets
- Add FreeType 2.11.1 support - Add MSBuild platform selection for ARM64 - Add support for static builds for FreeType versions 2.10 and above
1 parent 39a6bab commit 5305ba6

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Windows on Arm Support
2+
----------------------
3+
4+
Preliminary support for windows on arm64 target added.
5+
6+
Matplotlib for windows/arm64 requires FreeType 2.11 or above.
7+
8+
No binary wheels are available yet but can be build from source.

lib/matplotlib/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import sys
101101
import tempfile
102102
import warnings
103+
import platform
103104

104105
import numpy
105106
from packaging.version import parse as parse_version
@@ -1199,7 +1200,10 @@ def is_interactive():
11991200
def _init_tests():
12001201
# The version of FreeType to install locally for running the
12011202
# tests. This must match the value in `setupext.py`
1202-
LOCAL_FREETYPE_VERSION = '2.6.1'
1203+
if sys.platform.startswith('win') and platform.machine() == 'ARM64':
1204+
LOCAL_FREETYPE_VERSION = '2.11.1'
1205+
else:
1206+
LOCAL_FREETYPE_VERSION = '2.6.1'
12031207

12041208
from matplotlib import ft2font
12051209
if (ft2font.__freetype_version__ != LOCAL_FREETYPE_VERSION or

setupext.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import tarfile
1515
import textwrap
1616
import urllib.request
17+
from packaging import version
1718

1819
from setuptools import Distribution, Extension
1920

@@ -167,12 +168,18 @@ def get_and_extract_tarball(urls, sha, dirname):
167168
'955e17244e9b38adb0c98df66abb50467312e6bb70eac07e49ce6bd1a20e809a',
168169
'2.10.1':
169170
'3a60d391fd579440561bf0e7f31af2222bc610ad6ce4d9d7bd2165bca8669110',
171+
'2.11.1':
172+
'f8db94d307e9c54961b39a1cc799a67d46681480696ed72ecf78d4473770f09b'
170173
}
171174
# This is the version of FreeType to use when building a local version. It
172175
# must match the value in lib/matplotlib.__init__.py and also needs to be
173176
# changed below in the embedded windows build script (grep for "REMINDER" in
174177
# this file). Also update the cache path in `.circleci/config.yml`.
175-
LOCAL_FREETYPE_VERSION = '2.6.1'
178+
if sys.platform.startswith('win') and platform.machine() == 'ARM64': # older versions are not supported for win/arm64
179+
LOCAL_FREETYPE_VERSION = '2.11.1'
180+
else:
181+
LOCAL_FREETYPE_VERSION = '2.6.1'
182+
176183
LOCAL_FREETYPE_HASH = _freetype_hashes.get(LOCAL_FREETYPE_VERSION, 'unknown')
177184

178185
# Also update the cache path in `.circleci/config.yml`.
@@ -645,9 +652,10 @@ def do_custom_build(self, env):
645652
subprocess.check_call([make], env=env, cwd=src_path)
646653
else: # compilation on windows
647654
shutil.rmtree(src_path / "objs", ignore_errors=True)
655+
is_x64 = platform.architecture()[0] == '64bit'
648656
msbuild_platform = (
649-
'x64' if platform.architecture()[0] == '64bit' else 'Win32')
650-
base_path = Path("build/freetype-2.6.1/builds/windows")
657+
'ARM64' if platform.machine() == 'ARM64' else 'x64' if is_x64 else 'Win32')
658+
base_path = Path("build/freetype-{}/builds/windows".format(LOCAL_FREETYPE_VERSION))
651659
vc = 'vc2010'
652660
sln_path = (
653661
base_path / vc / "freetype.sln"
@@ -677,15 +685,23 @@ def do_custom_build(self, env):
677685

678686
cc = get_ccompiler()
679687
cc.initialize() # Get msbuild in the %PATH% of cc.spawn.
688+
# Freetype 2.10.0+ support static builds and use them if available as they are easier to deploy
689+
msbuild_configuration = 'Release Static' if version.parse(LOCAL_FREETYPE_VERSION) >= version.parse("2.10.0") else 'Release'
680690
cc.spawn(["msbuild", str(sln_path),
681691
"/t:Clean;Build",
682-
f"/p:Configuration=Release;Platform={msbuild_platform}"])
692+
f"/p:Configuration={msbuild_configuration};Platform={msbuild_platform}"])
683693
# Move to the corresponding Unix build path.
684694
(src_path / "objs" / ".libs").mkdir()
685695
# Be robust against change of FreeType version.
686-
lib_path, = (src_path / "objs" / vc / msbuild_platform).glob(
687-
"freetype*.lib")
688-
shutil.copy2(lib_path, src_path / "objs/.libs/libfreetype.lib")
696+
lib_paths = Path(src_path / "objs").rglob('freetype*.lib')
697+
libfreetype_file = None
698+
for lib_path in lib_paths:
699+
# check if freetype.lib in required platform directory
700+
if msbuild_platform in lib_path.resolve().as_uri():
701+
libfreetype_file = lib_path
702+
continue
703+
print("Copying {} to {}".format(lib_path.resolve(), src_path / "objs/.libs/libfreetype.lib"))
704+
shutil.copy2(libfreetype_file, src_path / "objs/.libs/libfreetype.lib")
689705

690706

691707
class Qhull(SetupPackage):

0 commit comments

Comments
 (0)