8000 Minor style tweaks to freetype build. by anntzer · Pull Request #25142 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Minor style tweaks to freetype build. #25142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,10 @@ def add_flags(cls, ext):
else:
src_path = Path('build', f'freetype-{LOCAL_FREETYPE_VERSION}')
# Statically link to the locally-built freetype.
# This is certainly broken on Windows.
ext.include_dirs.insert(0, str(src_path / 'include'))
if sys.platform == 'win32':
libfreetype = 'libfreetype.lib'
else:
libfreetype = 'libfreetype.a'
ext.extra_objects.insert(
0, str(src_path / 'objs' / '.libs' / libfreetype))
0, str((src_path / 'objs/.libs/libfreetype').with_suffix(
'.lib' if sys.platform == 'win32' else '.a')))
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'local'))

def do_custom_build(self, env):
Expand All @@ -617,11 +613,9 @@ def do_custom_build(self, env):
dirname=f'freetype-{LOCAL_FREETYPE_VERSION}',
)

if sys.platform == 'win32':
libfreetype = 'libfreetype.lib'
else:
libfreetype = 'libfreetype.a'
if (src_path / 'objs' / '.libs' / libfreetype).is_file():
libfreetype = (src_path / "objs/.libs/libfreetype").with_suffix(
".lib" if sys.platform == "win32" else ".a")
if libfreetype.is_file():
return # Bail out because we have already built FreeType.

print(f"Building freetype in {src_path}")
Expand Down Expand Up @@ -669,13 +663,6 @@ def do_custom_build(self, env):
subprocess.check_call([make], env=env, cwd=src_path)
else: # compilation on windows
shutil.rmtree(src_path / "objs", ignore_errors=True)
is_x64 = platform.architecture()[0] == '64bit'
if platform.machine() == 'ARM64':
msbuild_platform = 'ARM64'
elif is_x64:
msbuild_platform = 'x64'
else:
msbuild_platform = 'Win32'
base_path = Path(
f"build/freetype-{LOCAL_FREETYPE_VERSION}/builds/windows"
)
Expand Down Expand Up @@ -726,6 +713,10 @@ def do_custom_build(self, env):
str(dest),
])
msbuild_path = dest.read_text()
msbuild_platform = (
"ARM64" if platform.machine() == "ARM64" else
"x64" if platform.architecture()[0] == "64bit" else
"Win32")
# Freetype 2.10.0+ support static builds.
msbuild_config = (
"Release Static"
Expand All @@ -738,18 +729,16 @@ def do_custom_build(self, env):
f"/p:Configuration={msbuild_config};"
f"Platform={msbuild_platform}"])
# Move to the corresponding Unix build path.
(src_path / "objs" / ".libs").mkdir()
libfreetype.parent.mkdir()
# Be robust against change of FreeType version.
lib_paths = Path(src_path / "objs").rglob('freetype*.lib')
# Select FreeType library for required platform
lib_path, = [
p for p in lib_paths
if msbuild_platform in p.resolve().as_uri()
]
print(
f"Copying {lib_path} to {src_path}/objs/.libs/libfreetype.lib"
)
shutil.copy2(lib_path, src_path / "objs/.libs/libfreetype.lib")
print(f"Copying {lib_path} to {libfreetype}")
shutil.copy2(lib_path, libfreetype)


class Qhull(SetupPackage):
Expand Down
0