CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-cibuildwheel

Build Python wheels on CI with minimal configuration.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

architecture.mddocs/

Architecture Management

Cibuildwheel provides comprehensive architecture support with automatic detection, cross-compilation capabilities, and architecture-specific build configuration.

Capabilities

Architecture Enumeration

Complete enumeration of all supported CPU architectures across platforms.

class Architecture(StrEnum):
    # Cross-platform architectures
    x86_64 = "x86_64"
    
    # Linux-specific architectures  
    i686 = "i686"
    aarch64 = "aarch64"
    ppc64le = "ppc64le"
    s390x = "s390x"
    armv7l = "armv7l"
    riscv64 = "riscv64"
    
    # macOS-specific architectures
    universal2 = "universal2"
    arm64 = "arm64"
    
    # Windows-specific architectures
    x86 = "x86"
    AMD64 = "AMD64"
    ARM64 = "ARM64"
    
    # WebAssembly architecture
    wasm32 = "wasm32"
    
    # Android architecture
    arm64_v8a = "arm64_v8a"
    
    # iOS architectures
    arm64_iphoneos = "arm64_iphoneos"
    arm64_iphonesimulator = "arm64_iphonesimulator"
    x86_64_iphonesimulator = "x86_64_iphonesimulator"

Architecture Configuration Parsing

Parse architecture specifications from configuration strings.

@staticmethod
def parse_config(config: str, platform: PlatformName) -> set[Architecture]:
    """
    Parse architecture configuration string for a specific platform.
    
    Args:
        config: Architecture specification string (e.g., "x86_64,aarch64" or "auto")
        platform: Target platform name
        
    Returns:
        Set of Architecture enums matching the specification
        
    Raises:
        ConfigurationError: If architecture specification is invalid
    """

Native Architecture Detection

Detect the native architecture of the current system.

@staticmethod  
def native_arch(platform: PlatformName) -> Architecture | None:
    """
    Get the native architecture for the specified platform.
    
    Args:
        platform: Target platform name
        
    Returns:
        Native Architecture for the platform, or None if not determinable
    """

Automatic Architecture Selection

Get architecture sets based on automatic selection criteria.

@staticmethod
def auto_archs(platform: PlatformName) -> set[Architecture]:
    """
    Get the set of architectures that would be built by default ('auto').
    
    Args:
        platform: Target platform name
        
    Returns:
        Set of architectures for automatic builds on this platform
    """

@staticmethod
def all_archs(platform: PlatformName) -> set[Architecture]:
    """
    Get all supported architectures for a platform.
    
    Args:
        platform: Target platform name
        
    Returns:
        Set of all supported architectures for this platform
    """

@staticmethod
def bitness_archs(platform: PlatformName, bitness: Literal["64", "32"]) -> set[Architecture]:
    """
    Get architectures by bit width for a platform.
    
    Args:
        platform: Target platform name
        bitness: Either "64" for 64-bit or "32" for 32-bit architectures
        
    Returns:
        Set of architectures matching the specified bit width
    """

Architecture Translation

Convert architecture names between different platform naming conventions.

def arch_synonym(arch: str, from_platform: PlatformName, to_platform: PlatformName) -> str | None:
    """
    Translate architecture name from one platform's convention to another's.
    
    Args:
        arch: Architecture name in source platform's convention
        from_platform: Source platform
        to_platform: Target platform
        
    Returns:
        Architecture name in target platform's convention, or None if no translation exists
    """

Architecture Validation

Validate that architectures are supported on the target platform.

def allowed_architectures_check(platform: PlatformName, architectures: set[Architecture]) -> None:
    """
    Validate that all specified architectures are supported on the platform.
    
    Args:
        platform: Target platform name
        architectures: Set of architectures to validate
        
    Raises:
        ValueError: If any architecture is not supported on the platform
    """

Architecture Support by Platform

Linux Architectures

  • x86_64: Primary 64-bit Intel/AMD architecture
  • i686: 32-bit Intel/AMD architecture
  • aarch64: 64-bit ARM architecture (ARMv8)
  • ppc64le: 64-bit PowerPC Little Endian
  • s390x: IBM System z (s390x) 64-bit
  • armv7l: 32-bit ARM architecture (experimental, Ubuntu-based)
  • riscv64: RISC-V 64-bit architecture (experimental)

macOS Architectures

  • x86_64: Intel-based Macs (64-bit)
  • arm64: Apple Silicon Macs (M1, M2, etc.)
  • universal2: Universal binary containing both x86_64 and arm64

Windows Architectures

  • AMD64: 64-bit Windows (x86_64 equivalent)
  • x86: 32-bit Windows
  • ARM64: Windows on ARM 64-bit (experimental)

WebAssembly Architectures

  • wasm32: WebAssembly 32-bit target for Pyodide

Mobile Architectures

  • arm64_v8a: Android 64-bit ARM
  • arm64_iphoneos: iOS devices (ARM64)
  • arm64_iphonesimulator: iOS Simulator on Apple Silicon
  • x86_64_iphonesimulator: iOS Simulator on Intel Macs

Configuration Examples

Architecture Selection

# Configuration string parsing
from cibuildwheel.architecture import Architecture

# Parse specific architectures
archs = Architecture.parse_config("x86_64,aarch64", "linux")
# Returns: {Architecture.x86_64, Architecture.aarch64}

# Parse automatic selection
archs = Architecture.parse_config("auto", "linux") 
# Returns: {Architecture.x86_64} (on x86_64 host)

# Parse all architectures
archs = Architecture.parse_config("all", "linux")
# Returns: {Architecture.x86_64, Architecture.i686, Architecture.aarch64, ...}

Platform-Specific Defaults

# Get default architectures for each platform
linux_auto = Architecture.auto_archs("linux")       # {x86_64} on x86_64 host
macos_auto = Architecture.auto_archs("macos")        # {x86_64} on Intel, {arm64} on Apple Silicon
windows_auto = Architecture.auto_archs("windows")   # {AMD64} on 64-bit, {x86} on 32-bit

Cross-Compilation Setup

# Linux cross-compilation (requires emulation)
CIBW_ARCHS_LINUX = "x86_64 aarch64 ppc64le"

# macOS universal binaries
CIBW_ARCHS_MACOS = "universal2"

# Windows cross-compilation
CIBW_ARCHS_WINDOWS = "AMD64 ARM64"

Architecture Validation

from cibuildwheel.architecture import allowed_architectures_check, Architecture

# Validate architecture support
try:
    allowed_architectures_check("linux", {Architecture.x86_64, Architecture.aarch64})
    # Success - both architectures supported on Linux
except ValueError as e:
    print(f"Architecture validation failed: {e}")

# This would raise an error
try:
    allowed_architectures_check("windows", {Architecture.aarch64})
    # ValueError - aarch64 not supported on Windows (use ARM64 instead)
except ValueError:
    pass

Architecture Translation

from cibuildwheel.architecture import arch_synonym

# Translate between platform conventions
windows_arch = arch_synonym("x86_64", "linux", "windows")
# Returns: "AMD64"

linux_arch = arch_synonym("AMD64", "windows", "linux") 
# Returns: "x86_64"

ios_arch = arch_synonym("arm64", "macos", "ios")
# Returns: "arm64_iphoneos"

Advanced Architecture Features

Emulation Support

Cibuildwheel supports cross-compilation through emulation on Linux:

  • QEMU/binfmt_misc: Automatic emulation of foreign architectures
  • Docker Buildx: Multi-architecture container builds
  • Performance: Emulated builds are slower but provide full compatibility

Universal Binaries (macOS)

The universal2 architecture creates fat binaries containing both Intel and Apple Silicon code:

# Build universal binaries
CIBW_ARCHS_MACOS = "universal2"

# Or build separate architectures and combine later
CIBW_ARCHS_MACOS = "x86_64 arm64"

Architecture-Specific Configuration

Different configurations can be applied per architecture:

[tool.cibuildwheel.linux]
archs = ["x86_64", "aarch64"]

[tool.cibuildwheel.windows]  
archs = ["AMD64"]
skip = ["*-win32"]  # Skip 32-bit builds

[tool.cibuildwheel.macos]
archs = ["universal2"]

Install with Tessl CLI

npx tessl i tessl/pypi-cibuildwheel

docs

architecture.md

build-selection.md

ci-integration.md

cli.md

configuration.md

environment.md

errors.md

index.md

platforms.md

utilities.md

tile.json