Skip to content

Commit

Permalink
feat: add armv7l in auto_archs when running on aarch64
Browse files Browse the repository at this point in the history
This depends on aarch32 EL0 support and thus is done conditionally.
  • Loading branch information
mayeut committed Feb 2, 2025
1 parent b656a82 commit 70bcd0a
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 16 deletions.
24 changes: 21 additions & 3 deletions cibuildwheel/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import functools
import platform as platform_module
import re
import shutil
import subprocess
import sys
from collections.abc import Set
from enum import Enum
Expand All @@ -24,6 +26,19 @@
]


def _check_aarch32_el0() -> bool:
"""Check if running armv7l natively on aarch64 is supported"""
if not sys.platform.startswith("linux"):
return False
if platform_module.machine() != "aarch64":
return False
executable = shutil.which("linux32")
if executable is None:
return False
check = subprocess.run([executable, "uname", "-m"], check=False, capture_output=True, text=True)
return check.returncode == 0 and check.stdout.startswith("armv")


@functools.total_ordering
class Architecture(Enum):
value: str
Expand Down Expand Up @@ -114,9 +129,12 @@ def auto_archs(platform: PlatformName) -> set[Architecture]:
return set() # can't build anything on this platform
result = {native_arch}

if platform == "linux" and Architecture.x86_64 in result:
# x86_64 machines can run i686 containers
result.add(Architecture.i686)
if platform == "linux":
if Architecture.x86_64 in result:
# x86_64 machines can run i686 containers
result.add(Architecture.i686)
elif Architecture.aarch64 in result and _check_aarch32_el0():
result.add(Architecture.armv7l)

if platform == "windows" and Architecture.AMD64 in result:
result.add(Architecture.x86)
Expand Down
5 changes: 1 addition & 4 deletions examples/github-with-qemu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ jobs:
# configure cibuildwheel on Linux to build native archs ('auto'),
# and to split the remaining architectures between the x86_64 and
# ARM runners
# armv7l can be built without QEMU on GitHub Actions ARM runners but that's
# not the case on all ARM64 hardware hence 'auto armv7l' for native archs
# on the GHA ARM64 runner
CIBW_ARCHS_LINUX: ${{ runner.arch == 'X64' && 'auto ppc64le s390x' || 'auto armv7l' }}
CIBW_ARCHS_LINUX: ${{ runner.arch == 'X64' && 'auto ppc64le s390x' || 'auto' }}

- uses: actions/upload-artifact@v4
with:
Expand Down
7 changes: 7 additions & 0 deletions test/test_manylinuxXXXX_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def test(manylinux_image, tmp_path):
if manylinux_image in {"manylinux_2_28", "manylinux_2_34"} and platform.machine() == "x86_64":
# We don't have a manylinux_2_28+ image for i686
add_env["CIBW_ARCHS"] = "x86_64"
if platform.machine() == "aarch64":
# We just have a manylinux_2_31 image for armv7l
add_env["CIBW_ARCHS"] = "aarch64"

actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env)

Expand Down Expand Up @@ -150,4 +153,8 @@ def test(manylinux_image, tmp_path):
# We don't have a manylinux_2_28+ image for i686
expected_wheels = [w for w in expected_wheels if "i686" not in w]

if platform.machine() == "aarch64":
# We just have a manylinux_2_31 image for armv7l
expected_wheels = [w for w in expected_wheels if "armv7l" not in w]

assert set(actual_wheels) == set(expected_wheels)
3 changes: 2 additions & 1 deletion test/test_musllinux_X_Y_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test(musllinux_image, tmp_path):

# build the wheels
add_env = {
"CIBW_SKIP": "*-manylinux*",
"CIBW_SKIP": "*-manylinux* *_armv7l",
"CIBW_MUSLLINUX_X86_64_IMAGE": musllinux_image,
"CIBW_MUSLLINUX_I686_IMAGE": musllinux_image,
"CIBW_MUSLLINUX_AARCH64_IMAGE": musllinux_image,
Expand All @@ -54,4 +54,5 @@ def test(musllinux_image, tmp_path):
musllinux_versions=[musllinux_image],
single_python=True,
)
expected_wheels = [w for w in expected_wheels if "armv7l" not in w]
assert set(actual_wheels) == set(expected_wheels)
2 changes: 1 addition & 1 deletion test/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_uname(self):
# See #336 for more info.
bits = struct.calcsize("P") * 8
if bits == 32:
self.assertIn(platform.machine(), ["i686", "wasm32"])
self.assertIn(platform.machine(), ["i686", "armv7l","armv8l", "wasm32"])
'''


Expand Down
15 changes: 12 additions & 3 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def expected_wheels(
machine_arch = "aarch64"

if manylinux_versions is None:
if machine_arch == "armv7l":
if machine_arch in ("armv7l", "aarch64"):
manylinux_versions = ["manylinux_2_17", "manylinux2014", "manylinux_2_31"]
elif machine_arch == "x86_64":
manylinux_versions = [
Expand Down Expand Up @@ -250,14 +250,23 @@ def expected_wheels(
if platform == "linux":
architectures = [arch_name_for_linux(machine_arch)]

if machine_arch == "x86_64" and not single_arch:
architectures.append("i686")
if not single_arch:
if machine_arch == "x86_64":
architectures.append("i686")
elif (
machine_arch == "aarch64"
and sys.platform.startswith("linux")
and not python_abi_tag.startswith("pp")
):
# we assume all CI providers are able to run aarch32 EL0 on aarch64
architectures.append("armv7l")

if len(manylinux_versions) > 0:
platform_tags = [
".".join(
f"{manylinux_version}_{architecture}"
for manylinux_version in manylinux_versions
if (manylinux_version, architecture) != ("manylinux_2_31", "aarch64")
)
for architecture in architectures
]
Expand Down
22 changes: 20 additions & 2 deletions unit_test/architecture_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import platform as platform_module
import shutil
import sys

import pytest

import cibuildwheel.architecture
from cibuildwheel.architecture import Architecture


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


Expand All @@ -34,7 +37,7 @@ def test_arch_auto(platform_machine):
expected = {
"32": {Architecture.i686},
"64": {Architecture.x86_64, Architecture.i686},
"arm": {Architecture.aarch64},
"arm": {Architecture.aarch64, Architecture.armv7l},
}
assert arch_set == expected[machine_name]

Expand Down Expand Up @@ -71,7 +74,7 @@ def test_arch_auto32(platform_machine):
platform_name, machine_name = platform_machine

arch_set = Architecture.parse_config("auto32", "linux")
expected = {"32": {Architecture.i686}, "64": {Architecture.i686}, "arm": set()}
expected = {"32": {Architecture.i686}, "64": {Architecture.i686}, "arm": {Architecture.armv7l}}
assert arch_set == expected[machine_name]

arch_set = Architecture.parse_config("auto32", "macos")
Expand All @@ -80,3 +83,18 @@ def test_arch_auto32(platform_machine):
arch_set = Architecture.parse_config("auto32", "windows")
expected = {"32": {Architecture.x86}, "64": {Architecture.x86}, "arm": set()}
assert arch_set == expected[machine_name]


def test_arch_auto_no_aarch32(monkeypatch):
monkeypatch.setattr(sys, "platform", "linux")
monkeypatch.setattr(platform_module, "machine", lambda: "aarch64")
monkeypatch.setattr(shutil, "which", lambda *args, **kwargs: None)

arch_set = Architecture.parse_config("auto", "linux")
assert arch_set == {Architecture.aarch64}

arch_set = Architecture.parse_config("auto64", "linux")
assert arch_set == {Architecture.aarch64}

arch_set = Architecture.parse_config("auto32", "linux")
assert len(arch_set) == 0
4 changes: 2 additions & 2 deletions unit_test/main_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import pytest

from cibuildwheel import __main__, linux, macos, pyodide, windows
from cibuildwheel import __main__, architecture, linux, macos, pyodide, windows
from cibuildwheel.util import file


Expand Down Expand Up @@ -44,8 +44,8 @@ def ignore_call(*args, **kwargs):
monkeypatch.setattr(linux, "build", fail_on_call)
monkeypatch.setattr(macos, "build", fail_on_call)
monkeypatch.setattr(pyodide, "build", fail_on_call)

monkeypatch.setattr(Path, "mkdir", ignore_call)
monkeypatch.setattr(architecture, "_check_aarch32_el0", lambda: True)


@pytest.fixture(autouse=True)
Expand Down

0 comments on commit 70bcd0a

Please sign in to comment.