Skip to content

Commit

Permalink
💻 Override platform tags and correct ABI tag
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal committed Mar 22, 2024
1 parent d53774d commit 4d85e34
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pooch
from setuptools import Command, Extension, setup
from setuptools.command.build_ext import build_ext
from wheel.bdist_wheel import bdist_wheel, get_platform
from wheel.bdist_wheel import bdist_wheel

# Has to be kept in sync with the version in hugo/cli.py
HUGO_VERSION = "0.124.1"
Expand Down Expand Up @@ -142,7 +142,8 @@ def run(self):
]

# Check for compilers, toolchains, etc. and raise helpful errors if they
# are not found.
# are not found. These are essentially smoke tests to ensure that the
# build environment is set up correctly.
try:
subprocess.check_call(["go", "version"])
except OSError as err:
Expand Down Expand Up @@ -269,36 +270,32 @@ def initialize_options(self):
super().initialize_options()

def finalize_options(self):
# plat_name is essentially the {platform tag} at the end of the wheel name.
# Note to self: the wheel name will look like this:
# {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl
# # on macOS, if GOARCH is set to arm64 on an x86_64 machine, or if GOARCH is set to
# amd64 on an arm64 machine, we need to set the platform tag to macosx_X_Y_arm64 or
# macosx_X_Y_x86_64 respectively.
#
# TODO: FIXME: look at how Linux and Windows tags are set later
super().finalize_options()

def get_tag(self):
python_tag, abi_tag, platform_tag = bdist_wheel.get_tag(self)
# Build for all Python versions and set ABI tag to "none" because
# the Hugo binary is not a CPython extension, it is self-contained
python_tag, abi_tag = "py3", "none"

# Handle cross-compilation on macOS via the Xcode toolchain
# =========================================================
# Also, ensure correct platform tags for macOS arm64 and macOS x86_64
# since macOS 3.12 Python runners are mislabelling the platform tag to be
# universal2, see: https://github.com/pypa/wheel/issues/57
if sys.platform == "darwin":
platform_tag = get_platform("_")
# ensure correct platform tag for macOS arm64 and macOS x86_64
# macOS 3.12 Python runners are mislabelling the platform tag to be
# universal2
# see: https://github.com/pypa/wheel/issues/573. we will explicitly rename
# the universal2 tag to macosx_X_Y_arm64 or macosx_X_Y_x86_64 respectively,
# since we fuse the wheels together later anyway.
if (("arm64" in platform_tag) or ("univeral2" in platform_tag)) and (
os.environ.get("GOARCH") == "amd64"
if (os.environ.get("GOARCH") == "arm64") and (
("x86_64" in platform_tag) or ("universal2" in platform_tag)
):
self.plat_name = platform_tag.replace("arm64", "x86_64").replace(
"universal2", "x86_64"
)
if (("x86_64" in platform_tag) or ("universal2" in platform_tag)) and (
os.environ.get("GOARCH") == "arm64"
# replace x86_64 or universal2 in plat with arm64
plat = platform_tag.replace("x86_64", "arm64").replace("universal2", "arm64")
elif (os.environ.get("GOARCH") == "amd64") and (
("arm64" in platform_tag) or ("universal2" in platform_tag)
):
self.plat_name = platform_tag.replace("x86_64", "arm64").replace(
"universal2", "arm64"
)
super().finalize_options()
# Replace arm64 or universal2 in plat with x86_64
platform_tag = platform_tag.replace("arm64", "x86_64").replace("universal2", "x86_64")

return python_tag, abi_tag, platform_tag

def run(self):
self.root_is_pure = False # ensure that the wheel is tagged as a binary wheel
Expand Down

0 comments on commit 4d85e34

Please sign in to comment.