-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add GNU_PROPERTY_X86_ISA_1_NEEDED detection
ISA extensions usage is not defined by a PEP yet. This first implementation fails to repair the wheel if the usage of x86-64-v[2-4] is required. The check can be disabled with `--disable-isa-ext-check`. The detection being related to a declaration when building, it will not detect the requirement for binaries where the declaration is missing. All executables built on a manylinux_2_34 image will be detected as x86-64-v2.
- Loading branch information
Showing
10 changed files
with
542 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from __future__ import annotations | ||
|
||
import functools | ||
import platform | ||
import struct | ||
import sys | ||
from enum import Enum | ||
|
||
|
||
class Architecture(Enum): | ||
value: str | ||
|
||
aarch64 = "aarch64" | ||
armv7l = "armv7l" | ||
i686 = "i686" | ||
loongarch64 = "loongarch64" | ||
ppc64 = "ppc64" | ||
ppc64le = "ppc64le" | ||
riscv64 = "riscv64" | ||
s390x = "s390x" | ||
x86_64 = "x86_64" | ||
x86_64_v2 = "x86_64_v2" | ||
x86_64_v3 = "x86_64_v3" | ||
x86_64_v4 = "x86_64_v4" | ||
|
||
def __str__(self): | ||
return self.value | ||
|
||
@property | ||
def baseline(self): | ||
if self.value.startswith("x86_64"): | ||
return Architecture.x86_64 | ||
return self | ||
|
||
@classmethod | ||
@functools.lru_cache(None) | ||
def _member_list(cls) -> list[Architecture]: | ||
return list(cls) | ||
|
||
def is_subset(self, other: Architecture) -> bool: | ||
if self.baseline != other.baseline: | ||
return False | ||
member_list = Architecture._member_list() | ||
return member_list.index(self) <= member_list.index(other) | ||
|
||
def is_superset(self, other: Architecture) -> bool: | ||
if self.baseline != other.baseline: | ||
return False | ||
return other.is_subset(self) | ||
|
||
@staticmethod | ||
def get_native_architecture(*, bits: int | None = None) -> Architecture: | ||
machine = platform.machine() | ||
if sys.platform.startswith("win"): | ||
machine = {"AMD64": "x86_64", "ARM64": "aarch64", "x86": "i686"}.get( | ||
machine, machine | ||
) | ||
elif sys.platform.startswith("darwin"): | ||
machine = {"arm64": "aarch64"}.get(machine, machine) | ||
|
||
if bits is None: | ||
# c.f. https://github.com/pypa/packaging/pull/711 | ||
bits = 8 * struct.calcsize("P") | ||
|
||
if machine in {"x86_64", "i686"}: | ||
machine = {64: "x86_64", 32: "i686"}[bits] | ||
elif machine in {"aarch64", "armv8l"}: | ||
# use armv7l policy for 64-bit arm kernel in 32-bit mode (armv8l) | ||
machine = {64: "aarch64", 32: "armv7l"}[bits] | ||
|
||
return Architecture(machine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.