Bug 1670197: "Universal" python binaries shouldn't cause setup.py fails r=firefox-build-system-reviewers,rstewart

"distutils" builds packages to fit the architectures of the active
python.
However, the system Mac SDK doesn't always support all the same
architectures as the local Python binary.
To resolve this, we explicitly influence the build to only compile for
the specific architecture that the system runs on.

Assumes that "platform.machine()" will always line up with the "-arch"
flag of compilers.

Differential Revision: https://phabricator.services.mozilla.com/D96276
This commit is contained in:
Mitchell Hentges 2020-11-09 18:00:58 +00:00
parent 7a92a1e5ef
commit d73b2e2be9

View file

@ -9,6 +9,7 @@ from __future__ import absolute_import, print_function, unicode_literals
import argparse import argparse
import os import os
import platform
import shutil import shutil
import subprocess import subprocess
import sys import sys
@ -493,9 +494,13 @@ class VirtualenvManager(VirtualenvHelper):
# havoc. While this may work, invoking a new process is safer. # havoc. While this may work, invoking a new process is safer.
try: try:
env = os.environ.copy()
env.setdefault("ARCHFLAGS", get_archflags())
env = ensure_subprocess_env(env)
output = subprocess.check_output( output = subprocess.check_output(
program, program,
cwd=directory, cwd=directory,
env=env,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
universal_newlines=True, universal_newlines=True,
) )
@ -649,6 +654,10 @@ class VirtualenvManager(VirtualenvHelper):
return self._run_pip(args) return self._run_pip(args)
def _run_pip(self, args): def _run_pip(self, args):
env = os.environ.copy()
env.setdefault("ARCHFLAGS", get_archflags())
env = ensure_subprocess_env(env)
# It's tempting to call pip natively via pip.main(). However, # It's tempting to call pip natively via pip.main(). However,
# the current Python interpreter may not be the virtualenv python. # the current Python interpreter may not be the virtualenv python.
# This will confuse pip and cause the package to attempt to install # This will confuse pip and cause the package to attempt to install
@ -661,10 +670,20 @@ class VirtualenvManager(VirtualenvHelper):
[pip] + args, [pip] + args,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
cwd=self.topsrcdir, cwd=self.topsrcdir,
env=env,
universal_newlines=PY3, universal_newlines=PY3,
) )
def get_archflags():
# distutils will use the architecture of the running Python instance when building packages.
# However, it's possible for the Xcode Python to be a universal binary (x86_64 and
# arm64) without the associated macOS SDK supporting arm64, thereby causing a build
# failure. To avoid this, we explicitly influence the build to only target a single
# architecture - our current architecture.
return "-arch {}".format(platform.machine())
def verify_python_version(log_handle): def verify_python_version(log_handle):
"""Ensure the current version of Python is sufficient.""" """Ensure the current version of Python is sufficient."""
from distutils.version import LooseVersion from distutils.version import LooseVersion