Skip to content

fix: universal2 tags computation was incorrect #97

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
Nov 17, 2022
Merged
Show file tree
Hide file tree
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
25 changes: 15 additions & 10 deletions src/scikit_build_core/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,31 @@ def get_archs(self) -> list[str]:
Example (macOS):
ARCHFLAGS="-arch x86_64" -> ["x86_64"]
ARCHFLAGS="-arch x86_64 -arch arm64" -> ["x86_64", "arm64"]
ARCHFLAGS="-arch universal2" -> ["universal2"]

Returns an empty list otherwise or if ARCHFLAGS is not set.

If the extra_tags setting is True, then the list of platforms is
expanded to include extra matching platforms (universal2 also produces
x86_64 and arm64).
"""

if sys.platform.startswith("darwin"):
archs = re.findall(r"-arch (\S+)", self.config.env.get("ARCHFLAGS", ""))
if (
self.settings.wheel.expand_macos_universal_tags
and ["universal2"] == archs
):
archs += ["x86_64", "arm64"]
return archs

return []

def get_arch_tags(self) -> list[str]:
"""
This function returns tags suitable for use in wheels. The main
difference between this method and get_archs() is that this returns
universal2 instead of separate tags for x86_64 and arm64, or all of them
if wheel.expand-macos-universal-tags is true.
"""

archs = self.get_archs()
if sys.platform.startswith("darwin") and set(archs) == {"arm64", "x86_64"}:
if self.settings.wheel.expand_macos_universal_tags:
return ["universal2", "x86_64", "arm64"]
return ["universal2"]
return archs

def configure(
self,
*,
Expand Down
2 changes: 1 addition & 1 deletion src/scikit_build_core/pyproject/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def build_wheel(

_write_wheel_metadata(packages_dir=wheel_dirs["platlib"], metadata=metadata)

tags = WheelTag.compute_best(builder.get_archs(), settings.wheel.py_api)
tags = WheelTag.compute_best(builder.get_arch_tags(), settings.wheel.py_api)
wheel.build({k: str(v) for k, v in wheel_dirs.items()}, tags=tags.tags_dict())

wheel_filename: str = wheel.filename
Expand Down
25 changes: 15 additions & 10 deletions tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get_python_library,
)
from scikit_build_core.builder.wheel_tag import WheelTag
from scikit_build_core.cmake import CMaker
from scikit_build_core.settings.skbuild_model import ScikitBuildSettings, WheelSettings


Expand Down Expand Up @@ -97,20 +98,24 @@ def test_wheel_tag(monkeypatch, minver, archs, answer):


def test_builder_macos_arch_extra(monkeypatch):
archflags = "-arch universal2"
archflags = "-arch arm64 -arch x86_64"
monkeypatch.setattr(sys, "platform", "darwin")
monkeypatch.setenv("ARCHFLAGS", archflags)
tmpcfg = SimpleNamespace(env=os.environ.copy())
tmpbuilder = typing.cast(
Builder,
SimpleNamespace(
config=tmpcfg,
settings=ScikitBuildSettings(
wheel=WheelSettings(expand_macos_universal_tags=True)
),
tmpcfg = typing.cast(CMaker, SimpleNamespace(env=os.environ.copy()))

tmpbuilder = Builder(
settings=ScikitBuildSettings(wheel=WheelSettings()),
config=tmpcfg,
)
assert tmpbuilder.get_arch_tags() == ["universal2"]

tmpbuilder_ex = Builder(
settings=ScikitBuildSettings(
wheel=WheelSettings(expand_macos_universal_tags=True)
),
config=tmpcfg,
)
assert Builder.get_archs(tmpbuilder) == ["universal2", "x86_64", "arm64"]
assert tmpbuilder_ex.get_arch_tags() == ["universal2", "x86_64", "arm64"]


def test_wheel_tag_with_abi_darwin(monkeypatch):
Expand Down