diff --git a/bin/create_armv7l_check_exe.sh b/bin/create_armv7l_check_exe.sh new file mode 100755 index 000000000..dc7e0ef03 --- /dev/null +++ b/bin/create_armv7l_check_exe.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +set -eux + +SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)" +RESOURCES_DIR="${SCRIPT_DIR}/../cibuildwheel/resources" + +docker run --platform linux/arm/v7 -i --rm -v "${RESOURCES_DIR}:/resources" alpine:3.21 << "EOFD" +apk add build-base +gcc -s -Os -static -x c -o/resources/linux_armv7l_check - << "EOF" +#include + +int main(int argc, char* argv[]) { + puts("armv7l"); + return 0; +} +EOF +EOFD diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index 43fa4bdb5..5c7f63db4 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -3,7 +3,6 @@ import functools import platform as platform_module import re -import shutil import subprocess import sys from collections.abc import Set @@ -11,6 +10,7 @@ from typing import Final, Literal, assert_never from .typing import PlatformName +from .util.resources import LINUX_ARM7L_CHECK PRETTY_NAMES: Final[dict[PlatformName, str]] = { "linux": "Linux", @@ -32,11 +32,8 @@ def _check_aarch32_el0() -> bool: 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") + check = subprocess.run([LINUX_ARM7L_CHECK], check=False, capture_output=True, text=True) + return check.returncode == 0 and check.stdout.strip() == "armv7l" @functools.total_ordering diff --git a/cibuildwheel/resources/linux_armv7l_check b/cibuildwheel/resources/linux_armv7l_check new file mode 100755 index 000000000..70f2a2fdf Binary files /dev/null and b/cibuildwheel/resources/linux_armv7l_check differ diff --git a/cibuildwheel/util/resources.py b/cibuildwheel/util/resources.py index 781f92db9..5f8f25ad9 100644 --- a/cibuildwheel/util/resources.py +++ b/cibuildwheel/util/resources.py @@ -16,6 +16,7 @@ CONSTRAINTS: Final[Path] = PATH / "constraints.txt" VIRTUALENV: Final[Path] = PATH / "virtualenv.toml" CIBUILDWHEEL_SCHEMA: Final[Path] = PATH / "cibuildwheel.schema.json" +LINUX_ARM7L_CHECK: Final[Path] = PATH / "linux_arm7l_check" def read_python_configs(config: PlatformName) -> list[dict[str, str]]: diff --git a/unit_test/architecture_test.py b/unit_test/architecture_test.py index c1b23a5fd..341555c68 100644 --- a/unit_test/architecture_test.py +++ b/unit_test/architecture_test.py @@ -1,7 +1,7 @@ from __future__ import annotations import platform as platform_module -import shutil +import subprocess import sys import pytest @@ -88,7 +88,9 @@ def test_arch_auto32(platform_machine): 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) + monkeypatch.setattr( + subprocess, "run", lambda args, **kwargs: subprocess.CompletedProcess(args, 1) + ) arch_set = Architecture.parse_config("auto", "linux") assert arch_set == {Architecture.aarch64}