Skip to content

Commit 80bb036

Browse files
committed
f
1 parent 3f72fa1 commit 80bb036

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

cibuildwheel/architecture.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@
2626
]
2727

2828

29+
def _check_aarch32_el0() -> bool:
30+
"""Check if running armv7l natively on aarch64 is supported"""
31+
if not sys.platform.startswith("linux"):
32+
return False
33+
if platform_module.machine() != "aarch64":
34+
return False
35+
executable = shutil.which("linux32")
36+
if executable is None:
37+
return False
38+
check = subprocess.run([executable, "uname", "-m"], check=False, capture_output=True, text=True)
39+
return check.returncode == 0 and check.stdout.startswith("armv")
40+
41+
2942
@functools.total_ordering
3043
class Architecture(Enum):
3144
value: str
@@ -120,18 +133,8 @@ def auto_archs(platform: PlatformName) -> set[Architecture]:
120133
if Architecture.x86_64 in result:
121134
# x86_64 machines can run i686 containers
122135
result.add(Architecture.i686)
123-
elif Architecture.aarch64 in result and sys.platform.startswith("linux"):
124-
# check aarch32 EL0 support
125-
executable = shutil.which("linux32")
126-
if executable is not None:
127-
check = subprocess.run(
128-
[executable, "uname", "-m"],
129-
check=False,
130-
capture_output=True,
131-
text=True,
132-
)
133-
if check.returncode == 0 and check.stdout.startswith("armv"):
134-
result.add(Architecture.armv7l)
136+
elif Architecture.aarch64 in result and _check_aarch32_el0():
137+
result.add(Architecture.armv7l)
135138

136139
if platform == "windows" and Architecture.AMD64 in result:
137140
result.add(Architecture.x86)

unit_test/architecture_test.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import annotations
22

33
import platform as platform_module
4+
import shutil
45
import sys
56

67
import pytest
78

9+
import cibuildwheel.architecture
810
from cibuildwheel.architecture import Architecture
911

1012

@@ -24,6 +26,7 @@ def platform_machine(request, monkeypatch):
2426
platform_name, platform_value, machine_value, machine_name = request.param
2527
monkeypatch.setattr(sys, "platform", platform_value)
2628
monkeypatch.setattr(platform_module, "machine", lambda: machine_value)
29+
monkeypatch.setattr(cibuildwheel.architecture, "_check_aarch32_el0", lambda: True)
2730
return platform_name, machine_name
2831

2932

@@ -34,7 +37,7 @@ def test_arch_auto(platform_machine):
3437
expected = {
3538
"32": {Architecture.i686},
3639
"64": {Architecture.x86_64, Architecture.i686},
37-
"arm": {Architecture.aarch64},
40+
"arm": {Architecture.aarch64, Architecture.armv7l},
3841
}
3942
assert arch_set == expected[machine_name]
4043

@@ -71,7 +74,7 @@ def test_arch_auto32(platform_machine):
7174
platform_name, machine_name = platform_machine
7275

7376
arch_set = Architecture.parse_config("auto32", "linux")
74-
expected = {"32": {Architecture.i686}, "64": {Architecture.i686}, "arm": set()}
77+
expected = {"32": {Architecture.i686}, "64": {Architecture.i686}, "arm": {Architecture.armv7l}}
7578
assert arch_set == expected[machine_name]
7679

7780
arch_set = Architecture.parse_config("auto32", "macos")
@@ -80,3 +83,18 @@ def test_arch_auto32(platform_machine):
8083
arch_set = Architecture.parse_config("auto32", "windows")
8184
expected = {"32": {Architecture.x86}, "64": {Architecture.x86}, "arm": set()}
8285
assert arch_set == expected[machine_name]
86+
87+
88+
def test_arch_auto_no_aarch32(monkeypatch):
89+
monkeypatch.setattr(sys, "platform", "linux")
90+
monkeypatch.setattr(platform_module, "machine", lambda: "aarch64")
91+
monkeypatch.setattr(shutil, "which", lambda *args, **kwargs: None)
92+
93+
arch_set = Architecture.parse_config("auto", "linux")
94+
assert arch_set == {Architecture.aarch64}
95+
96+
arch_set = Architecture.parse_config("auto64", "linux")
97+
assert arch_set == {Architecture.aarch64}
98+
99+
arch_set = Architecture.parse_config("auto32", "linux")
100+
assert len(arch_set) == 0

unit_test/main_tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pytest
1010

11-
from cibuildwheel import __main__, linux, macos, pyodide, windows
11+
from cibuildwheel import __main__, architecture, linux, macos, pyodide, windows
1212
from cibuildwheel.util import file
1313

1414

@@ -44,8 +44,8 @@ def ignore_call(*args, **kwargs):
4444
monkeypatch.setattr(linux, "build", fail_on_call)
4545
monkeypatch.setattr(macos, "build", fail_on_call)
4646
monkeypatch.setattr(pyodide, "build", fail_on_call)
47-
4847
monkeypatch.setattr(Path, "mkdir", ignore_call)
48+
monkeypatch.setattr(architecture, "_check_aarch32_el0", lambda: True)
4949

5050

5151
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)