Skip to content
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

Handle a quirk when building on MacOS Big Sur. #12857

Merged
merged 2 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions build-support/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ function determine_python() {
function is_macos_arm() {
[[ $(uname -sm) == "Darwin arm64" ]]
}

function is_macos_big_sur() {
[[ $(uname) == "Darwin" && $(sw_vers -productVersion) = 11\.* ]]
}
11 changes: 11 additions & 0 deletions cargo
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ PY="$(determine_python)"
export PY
export PYO3_PYTHON="${PY}"
export PYTHON_SYS_EXECUTABLE="${PY}" # Consumed by the cpython crate.
if is_macos_big_sur; then
# With Big Sur, MacOS changed its versioning scheme from 10.X to 11.X. A pantsbuild.pants
# wheel built on Big Sur will declare its platform (in its name) as macosx_11_0. Unfortunately
# pip does not yet recognize that as a compatible platform for Big Sur.
# Fortunately, Big Sur may also be identified as 10.16, for backwards compatibility with the old
# versioning scheme. Setting MACOSX_DEPLOYMENT_TARGET=10.16 when building the wheel will cause
# that wheel to declare its platform as macosx_10_16, which pip will then happily install.
# However, in order to build the wheel as macosx_10_16 we must also build the native code for
# that platform string, hence this setting here.
export MACOSX_DEPLOYMENT_TARGET=10.16
fi

if ! command -v rustup &> /dev/null; then
die "Please install Rustup and ensure \`rustup\` is on your PATH (usually by adding ~/.cargo/bin). See https://rustup.rs."
Expand Down
10 changes: 9 additions & 1 deletion src/python/pants/backend/python/goals/setup_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from pants.util.memo import memoized_property
from pants.util.meta import frozen_after_init
from pants.util.ordered_set import FrozenOrderedSet
from pants.util.osutil import is_macos_big_sur
from pants.util.strutil import ensure_text

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -410,7 +411,9 @@ async def package_python_dist(


@rule
async def run_setup_py(req: RunSetupPyRequest, setuptools: Setuptools) -> RunSetupPyResult:
async def run_setup_py(
req: RunSetupPyRequest, setuptools: Setuptools, python_setup: PythonSetup
) -> RunSetupPyResult:
"""Run a setup.py command on a single exported target."""
# Note that this pex has no entrypoint. We use it to run our generated setup.py, which
# in turn imports from and invokes setuptools.
Expand Down Expand Up @@ -443,12 +446,17 @@ async def run_setup_py(req: RunSetupPyRequest, setuptools: Setuptools) -> RunSet
setup_script_reldir, setup_script_name = os.path.split(req.chroot.setup_script)
working_directory = os.path.join(chroot_prefix, setup_script_reldir)

if python_setup.macos_big_sur_compatibility and is_macos_big_sur():
extra_env = {"MACOSX_DEPLOYMENT_TARGET": "10.16"}
else:
extra_env = {}
result = await Get(
ProcessResult,
VenvPexProcess(
setuptools_pex,
argv=(setup_script_name, *req.args),
input_digest=prefixed_chroot,
extra_env=extra_env,
working_directory=working_directory,
# setuptools commands that create dists write them to the distdir.
# TODO: Could there be other useful files to capture?
Expand Down
14 changes: 14 additions & 0 deletions src/python/pants/python/python_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ def register_options(cls, register):
help="Tailor pex_binary() targets for Python entry point files.",
)

register(
"--macos-big-sur-compatibility",
type=bool,
default=False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we configure this as True in our pants.toml or in some more specific way such that releases do the right thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, oops, yes we should. It seems like this should usually be True, but I'm not confident enough in that fact for that to be the default.

help="If set, and if running on MacOS Big Sur, use macosx_10_16 as the platform "
"when building wheels. Otherwise, the default of macosx_11_0 will be used. "
"This may be required for pip to be able to install the resulting distribution "
"on Big Sur.",
)

@property
def interpreter_constraints(self) -> Tuple[str, ...]:
return tuple(self.options.interpreter_constraints)
Expand Down Expand Up @@ -271,6 +281,10 @@ def tailor_ignore_solitary_init_files(self) -> bool:
def tailor_pex_binary_targets(self) -> bool:
return cast(bool, self.options.tailor_pex_binary_targets)

@property
def macos_big_sur_compatibility(self) -> bool:
return cast(bool, self.options.macos_big_sur_compatibility)

@property
def scratch_dir(self):
return os.path.join(self.options.pants_workdir, *self.options_scope.split("."))
Expand Down
5 changes: 5 additions & 0 deletions src/python/pants/util/osutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import errno
import logging
import os
import platform
import posix
from functools import reduce
from typing import Optional
Expand Down Expand Up @@ -95,6 +96,10 @@ def get_normalized_arch_name() -> str:
return normalize_arch_name(get_arch_name())


def is_macos_big_sur() -> bool:
return hasattr(platform, "mac_ver") and platform.mac_ver()[0].startswith("11.")


def _values(aliases: dict[str, set[str]]) -> set[str]:
return reduce(set.union, aliases.values())

Expand Down