From 0c9af0357baaa5b5e34cbaa5ed592a36391582b5 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Sun, 20 Dec 2020 19:42:28 +0000 Subject: [PATCH] Add platform-specific CIBW_ARCHS options. Remove 'auto' as a possible Architecture enum value. This is resolved at option parse time. --- cibuildwheel/__main__.py | 8 ++++++-- cibuildwheel/linux.py | 9 --------- cibuildwheel/util.py | 24 +++++++++++++++++++++++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index a7f77a0b..99e2e0dd 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -71,7 +71,7 @@ def main() -> None: parser.add_argument( '--archs', - default=os.environ.get("CIBW_ARCHS", 'auto'), + default=None, help=''' Comma-separated list of CPU architectures to build for. If unspecified, builds the architectures natively supported @@ -182,7 +182,11 @@ def main() -> None: print('cibuildwheel: Could not find setup.py, setup.cfg or pyproject.toml at root of package', file=sys.stderr) exit(2) - archs = [Architecture(a) for a in args.archs.split(",")] + if args.archs is not None: + archs_config_str = args.archs + else: + archs_config_str = get_option_from_environment('CIBW_ARCHS', platform=platform, default='auto') + archs = Architecture.parse_config(archs_config_str, platform=platform) if args.print_build_identifiers: print_build_identifiers(platform, build_selector, archs) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index a6ae6e46..15932776 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -1,4 +1,3 @@ -import platform import re import subprocess import sys @@ -75,14 +74,6 @@ def get_python_configurations( # skip builds as required target_archs = architectures - if Architecture.auto in architectures: - target_archs.remove(Architecture.auto) - native_architecture = Architecture(platform.machine()) - target_archs.append(native_architecture) - # x86_64 machines can run i686 docker containers - if native_architecture == Architecture.x86_64: - target_archs.append(Architecture.i686) - return [ c for c in python_configurations if matches_platform(c.identifier, target_archs) diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index 5ea02f5b..a4711dd3 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -1,4 +1,6 @@ import os +import platform as platform_module +import re import ssl import textwrap import urllib.request @@ -122,12 +124,32 @@ class DependencyConstraints: class Architecture(str, Enum): - auto = 'auto' # gets expanded to the native arch, possibly 32+64 bit x86_64 = 'x86_64' i686 = 'i686' aarch64 = 'aarch64' ppc64le = 'ppc64le' s390x = 's390x' + win32 = 'win32' + win_amd64 = 'win_amd64' + + @staticmethod + def parse_config(config: str, platform: str) -> 'List[Architecture]': + result = [] + for arch_str in re.split(r'[\s,]+', config): + if arch_str == 'auto': + result += Architecture.auto_archs(platform=platform) + else: + result.append(Architecture(arch_str)) + return result + + @staticmethod + def auto_archs(platform: str) -> 'List[Architecture]': + native_architecture = Architecture(platform_module.machine()) + result = [native_architecture] + # x86_64 machines can run i686 docker containers + if platform == 'linux' and native_architecture == Architecture.x86_64: + result.append(Architecture.i686) + return result class BuildOptions(NamedTuple):