From 36a6b3c2d036c37347d5a81f9e07c98fdc90cb62 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 4 Oct 2021 18:20:24 -0400 Subject: [PATCH 1/2] Ensure *full* compiler config is passed to FreeType Using just `CC` from the `distutils` compiler can break universal2 wheels on macOS, but passing all compiler and linker settings appears to work. Plus grabbing this information from `sysconfig` is better than hacking the `distutils` compiler into working. --- setupext.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/setupext.py b/setupext.py index 80cce3ade3fa..35a612243922 100644 --- a/setupext.py +++ b/setupext.py @@ -605,16 +605,18 @@ def do_custom_build(self, env): if (src_path / 'objs' / '.libs' / libfreetype).is_file(): return # Bail out because we have already built FreeType. - cc = get_ccompiler() - print(f"Building freetype in {src_path}") if sys.platform != 'win32': # compilation on non-windows env = { **env, - "CC": (shlex.join(cc.compiler) if sys.version_info >= (3, 8) - else " ".join(shlex.quote(x) for x in cc.compiler)), - "CFLAGS": "{} -fPIC".format(env.get("CFLAGS", "")), + **{ + var: value + for var, value in sysconfig.get_config_vars().items() + if var in {"CC", "CFLAGS", "CXX", "CXXFLAGS", "LD", + "LDFLAGS"} + }, } + env["CFLAGS"] = env.get("CFLAGS", "") + " -fPIC" subprocess.check_call( ["./configure", "--with-zlib=no", "--with-bzip2=no", "--with-png=no", "--with-harfbuzz=no", "--enable-static", @@ -668,6 +670,7 @@ def do_custom_build(self, env): f.truncate() f.write(vcxproj) + cc = get_ccompiler() cc.initialize() # Get msbuild in the %PATH% of cc.spawn. cc.spawn(["msbuild", str(sln_path), "/t:Clean;Build", From 81730f7c69b85ce95d54d53e5e8a059c982ae023 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Mon, 4 Oct 2021 22:13:43 -0400 Subject: [PATCH 2/2] Fix FreeType build PyPy PyPy doesn't have a host type, so don't pass `--host` in that case, and hope it is correct (which has been how it was since forever anyway.) --- setupext.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/setupext.py b/setupext.py index 35a612243922..5320ee3a518b 100644 --- a/setupext.py +++ b/setupext.py @@ -617,12 +617,15 @@ def do_custom_build(self, env): }, } env["CFLAGS"] = env.get("CFLAGS", "") + " -fPIC" - subprocess.check_call( - ["./configure", "--with-zlib=no", "--with-bzip2=no", - "--with-png=no", "--with-harfbuzz=no", "--enable-static", - "--disable-shared", - "--host=" + sysconfig.get_config_var('BUILD_GNU_TYPE')], - env=env, cwd=src_path) + configure = [ + "./configure", "--with-zlib=no", "--with-bzip2=no", + "--with-png=no", "--with-harfbuzz=no", "--enable-static", + "--disable-shared" + ] + host = sysconfig.get_config_var('BUILD_GNU_TYPE') + if host is not None: # May be unset on PyPy. + configure.append(f"--host={host}") + subprocess.check_call(configure, env=env, cwd=src_path) if 'GNUMAKE' in env: make = env['GNUMAKE'] elif 'MAKE' in env: