Skip to content

Commit

Permalink
custom-check
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut committed Feb 2, 2025
1 parent 70bcd0a commit 6c43d7f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
18 changes: 18 additions & 0 deletions bin/create_armv7l_check_exe.sh
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
int main(int argc, char* argv[]) {
puts("armv7l");
return 0;
}
EOF
EOFD
9 changes: 3 additions & 6 deletions cibuildwheel/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import functools
import platform as platform_module
import re
import shutil
import subprocess
import sys
from collections.abc import Set
from enum import Enum
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",
Expand All @@ -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
Expand Down
Binary file added cibuildwheel/resources/linux_armv7l_check
Binary file not shown.
1 change: 1 addition & 0 deletions cibuildwheel/util/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down
6 changes: 4 additions & 2 deletions unit_test/architecture_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import platform as platform_module
import shutil
import subprocess
import sys

import pytest
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 6c43d7f

Please sign in to comment.