Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add GNU_PROPERTY_X86_ISA_1_NEEDED detection #535

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions scripts/create-arch-wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

# This script is used to create wheels for unsupported architectures
# in order to extend coverage and check errors with those.

set -eux

SCRIPT_DIR="$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd -P)"
INTEGRATION_TEST_DIR="${SCRIPT_DIR}/../tests/integration"
mkdir -p "${INTEGRATION_TEST_DIR}/arch-wheels"

# "mips64le" built with buildpack-deps:bookworm and renamed cp313-cp313
# "386" "amd64" "arm/v5" "arm/v7" "arm64/v8"
for ARCH in "ppc64le" "riscv64" "s390x"; do
docker run --platform linux/${ARCH} -i --rm -v "${INTEGRATION_TEST_DIR}:/tests" debian:trixie-20250203 << "EOF"
# for, "arm/v5" QEMU will report armv7l, running on aarch64 will report aarch64, force armv5l/armv7l
case "$(dpkg --print-architecture)" in
armel) export _PYTHON_HOST_PLATFORM="linux-armv5l";;
armhf) export _PYTHON_HOST_PLATFORM="linux-armv7l";;
*) ;;
esac
DEBIAN_FRONTEND=noninteractive apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends gcc python3-pip python3-dev
python3 -m pip wheel --no-deps -w /tests/arch-wheels /tests/testsimple
EOF

done
71 changes: 71 additions & 0 deletions src/auditwheel/architecture.py
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)
19 changes: 19 additions & 0 deletions src/auditwheel/json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import dataclasses
import json
from enum import Enum
from typing import Any


def _encode_value(value: Any) -> Any:
if dataclasses.is_dataclass(value) and not isinstance(value, type):
return dataclasses.asdict(value)
if isinstance(value, frozenset):
return sorted(value)
if isinstance(value, Enum):
return repr(value)
msg = f"object of type {value.__class__.__name__!r} can't be encoded to JSON"
raise TypeError(msg)


def dumps(obj: Any):
return json.dumps(obj, indent=4, default=_encode_value)
Loading