Skip to content

Commit f13a23a

Browse files
committed
fix: universal2 tags computation was incorrect
Signed-off-by: Henry Schreiner <[email protected]>
1 parent a163308 commit f13a23a

File tree

3 files changed

+31
-21
lines changed

3 files changed

+31
-21
lines changed

src/scikit_build_core/builder/builder.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,31 @@ def get_archs(self) -> list[str]:
3939
Example (macOS):
4040
ARCHFLAGS="-arch x86_64" -> ["x86_64"]
4141
ARCHFLAGS="-arch x86_64 -arch arm64" -> ["x86_64", "arm64"]
42-
ARCHFLAGS="-arch universal2" -> ["universal2"]
4342
4443
Returns an empty list otherwise or if ARCHFLAGS is not set.
45-
46-
If the extra_tags setting is True, then the list of platforms is
47-
expanded to include extra matching platforms (universal2 also produces
48-
x86_64 and arm64).
4944
"""
5045

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

6050
return []
6151

52+
def get_arch_tags(self) -> list[str]:
53+
"""
54+
This function returns tags suitable for use in wheels. The main
55+
difference between this method and get_archs() is that this returns
56+
universal2 instead of separate tags for x86_64 and arm64, or all of them
57+
if wheel.expand-macos-universal-tags is true.
58+
"""
59+
60+
archs = self.get_archs()
61+
if sys.platform.startswith("darwin") and set(archs) == {"arm64", "x86_64"}:
62+
if self.settings.wheel.expand_macos_universal_tags:
63+
return ["universal2", "x86_64", "arm64"]
64+
return ["universal2"]
65+
return archs
66+
6267
def configure(
6368
self,
6469
*,

src/scikit_build_core/pyproject/wheel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def build_wheel(
198198

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

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

204204
wheel_filename: str = wheel.filename

tests/test_builder.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
get_python_library,
1616
)
1717
from scikit_build_core.builder.wheel_tag import WheelTag
18+
from scikit_build_core.cmake import CMaker
1819
from scikit_build_core.settings.skbuild_model import ScikitBuildSettings, WheelSettings
1920

2021

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

9899

99100
def test_builder_macos_arch_extra(monkeypatch):
100-
archflags = "-arch universal2"
101+
archflags = "-arch arm64 -arch x86_64"
101102
monkeypatch.setattr(sys, "platform", "darwin")
102103
monkeypatch.setenv("ARCHFLAGS", archflags)
103-
tmpcfg = SimpleNamespace(env=os.environ.copy())
104-
tmpbuilder = typing.cast(
105-
Builder,
106-
SimpleNamespace(
107-
config=tmpcfg,
108-
settings=ScikitBuildSettings(
109-
wheel=WheelSettings(expand_macos_universal_tags=True)
110-
),
104+
tmpcfg = typing.cast(CMaker, SimpleNamespace(env=os.environ.copy()))
105+
106+
tmpbuilder = Builder(
107+
settings=ScikitBuildSettings(wheel=WheelSettings()),
108+
config=tmpcfg,
109+
)
110+
assert tmpbuilder.get_arch_tags() == ["universal2"]
111+
112+
tmpbuilder_ex = Builder(
113+
settings=ScikitBuildSettings(
114+
wheel=WheelSettings(expand_macos_universal_tags=True)
111115
),
116+
config=tmpcfg,
112117
)
113-
assert Builder.get_archs(tmpbuilder) == ["universal2", "x86_64", "arm64"]
118+
assert tmpbuilder_ex.get_arch_tags() == ["universal2", "x86_64", "arm64"]
114119

115120

116121
def test_wheel_tag_with_abi_darwin(monkeypatch):

0 commit comments

Comments
 (0)