From 9ae127206d675936ff5c80b11bf5c5e81cedc617 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Thu, 21 Jan 2021 12:55:42 -0500 Subject: [PATCH 1/3] feat: auto32/auto64 --- README.md | 2 +- cibuildwheel/__main__.py | 2 +- cibuildwheel/architecture.py | 26 ++++++++++++++++- docs/options.md | 5 ++++ unit_test/main_tests/main_platform_test.py | 33 ++++++++++++++++++++++ 5 files changed, 65 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 841b4f3ac..46144fc77 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Options |---|--------|-------------| | **Build selection** | [`CIBW_PLATFORM`](https://cibuildwheel.readthedocs.io/en/stable/options/#platform) | Override the auto-detected target platform | | | [`CIBW_BUILD`](https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip)
[`CIBW_SKIP`](https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip) | Choose the Python versions to build | -| | [`CIBW_ARCHS_LINUX`](https://cibuildwheel.readthedocs.io/en/stable/options/#archs) | Build non-native architectures | +| | [`CIBW_ARCHS`](https://cibuildwheel.readthedocs.io/en/stable/options/#archs) | Control available architectures | | | [`CIBW_PROJECT_REQUIRES_PYTHON`](https://cibuildwheel.readthedocs.io/en/stable/options/#requires-python) | Manually set the Python compatibility of your project | | **Build customization** | [`CIBW_ENVIRONMENT`](https://cibuildwheel.readthedocs.io/en/stable/options/#environment) | Set environment variables needed during the build | | | [`CIBW_BEFORE_ALL`](https://cibuildwheel.readthedocs.io/en/stable/options/#before-all) | Execute a shell command on the build system before any wheels are built. | diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 33a570c7f..bebaf1eb0 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -80,7 +80,7 @@ def main() -> None: on this machine. Set this option to build an architecture via emulation, for example, using binfmt_misc and QEMU. Default: auto. - Choices: auto, native, all, {} + Choices: auto, auto64, auto32, native, all, {} '''.format(", ".join(a.name for a in Architecture))) parser.add_argument('--output-dir', default=os.environ.get('CIBW_OUTPUT_DIR', 'wheelhouse'), diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index 63e3a8bc4..3846410cc 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -4,7 +4,7 @@ from enum import Enum from typing import Set -from .typing import PlatformName, assert_never +from .typing import Literal, PlatformName, assert_never PRETTY_NAMES = {'linux': 'Linux', 'macos': 'macOS', 'windows': 'Windows'} @@ -44,6 +44,10 @@ def parse_config(config: str, platform: PlatformName) -> 'Set[Architecture]': result.add(Architecture(platform_module.machine())) elif arch_str == 'all': result |= Architecture.all_archs(platform=platform) + elif arch_str == 'auto64': + result |= Architecture.bitiness_archs(platform=platform, bitiness="64") + elif arch_str == 'auto32': + result |= Architecture.bitiness_archs(platform=platform, bitiness="32") else: result.add(Architecture(arch_str)) return result @@ -77,6 +81,26 @@ def all_archs(platform: PlatformName) -> 'Set[Architecture]': else: assert_never(platform) + @staticmethod + def bitiness_archs(platform: PlatformName, bitiness: Literal["64", "32"]) -> 'Set[Architecture]': + native_architecture = Architecture(platform_module.machine()) + + if native_architecture in {Architecture.x86_64, Architecture.aarch64, Architecture.ppc64le, Architecture.s390x, Architecture.AMD64}: + if bitiness == "64": + return {native_architecture} + else: + if native_architecture == Architecture.x86_64 and platform != "macos": + return {Architecture.i686} + elif native_architecture == Architecture.AMD64: + return {Architecture.x86} + else: + return set() + elif native_architecture in {Architecture.i686, Architecture.x86}: + return {native_architecture} if bitiness == "32" else set() + else: + # assert_never doesn't work here, oddly, maybe due to set checking above + raise RuntimeError("Cannot be reached") + def allowed_architectures_check( platform: PlatformName, diff --git a/docs/options.md b/docs/options.md index 78ffce929..fdc03fae0 100644 --- a/docs/options.md +++ b/docs/options.md @@ -172,6 +172,8 @@ Options: - macOS: `x86_64` `arm64` `universal2` - Windows: `AMD64` `x86` - `auto`: The default archs for your machine - see the table below. + - `auto64`: Just the 64-bit auto archs (will result in an empty set on a 32-bit runner) + - `auto32`: Just the 32-bit auto archs (will result in an empty set on macOS) - `native`: the native arch of the build machine - Matches [`platform.machine()`](https://docs.python.org/3/library/platform.html#platform.machine). - `all` : expands to all the architectures supported on this OS. You may want to use [CIBW_BUILD](#build-skip) with this option to target specific @@ -191,6 +193,9 @@ If not listed above, `auto` is the same as `native`. [setup-qemu-action]: https://github.com/docker/setup-qemu-action [binfmt]: https://hub.docker.com/r/tonistiigi/binfmt +Platform-specific variants also available:
+ `CIBW_ARCHS_MACOS` | `CIBW_ARCHS_WINDOWS` | `CIBW_ARCHS_LINUX` + #### Examples ```yaml diff --git a/unit_test/main_tests/main_platform_test.py b/unit_test/main_tests/main_platform_test.py index 98bcfcdd9..1b37663eb 100644 --- a/unit_test/main_tests/main_platform_test.py +++ b/unit_test/main_tests/main_platform_test.py @@ -131,6 +131,39 @@ def test_archs_platform_native(platform, intercepted_build_args, monkeypatch): assert build_options.architectures == {Architecture.x86_64} +def test_archs_platform_auto64(platform, intercepted_build_args, monkeypatch): + monkeypatch.setenv('CIBW_ARCHS', 'auto64') + + main() + build_options = intercepted_build_args.args[0] + + if platform == 'linux': + assert build_options.architectures == {Architecture.x86_64} + elif platform == 'windows': + assert build_options.architectures == {Architecture.AMD64} + elif platform == 'macos': + assert build_options.architectures == {Architecture.x86_64} + + +def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch): + monkeypatch.setenv('CIBW_ARCHS', 'auto32') + + if platform == 'macos': + with pytest.raises(SystemExit) as exit: + main() + assert exit.value.args == (4,) + + else: + main() + + build_options = intercepted_build_args.args[0] + + if platform == 'linux': + assert build_options.architectures == {Architecture.i686} + elif platform == 'windows': + assert build_options.architectures == {Architecture.x86} + + def test_archs_platform_all(platform, intercepted_build_args, monkeypatch): monkeypatch.setenv('CIBW_ARCHS', 'all') From e14d13d7b7affa285fc339d071043d614912656a Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Sun, 31 Jan 2021 17:10:25 -0500 Subject: [PATCH 2/3] refactor: cleanup from @joerick --- README.md | 2 +- cibuildwheel/architecture.py | 26 +++++++++----------------- docs/options.md | 22 ++++++++++------------ 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 46144fc77..6b46c70eb 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Options |---|--------|-------------| | **Build selection** | [`CIBW_PLATFORM`](https://cibuildwheel.readthedocs.io/en/stable/options/#platform) | Override the auto-detected target platform | | | [`CIBW_BUILD`](https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip)
[`CIBW_SKIP`](https://cibuildwheel.readthedocs.io/en/stable/options/#build-skip) | Choose the Python versions to build | -| | [`CIBW_ARCHS`](https://cibuildwheel.readthedocs.io/en/stable/options/#archs) | Control available architectures | +| | [`CIBW_ARCHS`](https://cibuildwheel.readthedocs.io/en/stable/options/#archs) | Change the architectures built on your machine by default | | | [`CIBW_PROJECT_REQUIRES_PYTHON`](https://cibuildwheel.readthedocs.io/en/stable/options/#requires-python) | Manually set the Python compatibility of your project | | **Build customization** | [`CIBW_ENVIRONMENT`](https://cibuildwheel.readthedocs.io/en/stable/options/#environment) | Set environment variables needed during the build | | | [`CIBW_BEFORE_ALL`](https://cibuildwheel.readthedocs.io/en/stable/options/#before-all) | Execute a shell command on the build system before any wheels are built. | diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index 3846410cc..08e5061d3 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -82,24 +82,16 @@ def all_archs(platform: PlatformName) -> 'Set[Architecture]': assert_never(platform) @staticmethod - def bitiness_archs(platform: PlatformName, bitiness: Literal["64", "32"]) -> 'Set[Architecture]': - native_architecture = Architecture(platform_module.machine()) - - if native_architecture in {Architecture.x86_64, Architecture.aarch64, Architecture.ppc64le, Architecture.s390x, Architecture.AMD64}: - if bitiness == "64": - return {native_architecture} - else: - if native_architecture == Architecture.x86_64 and platform != "macos": - return {Architecture.i686} - elif native_architecture == Architecture.AMD64: - return {Architecture.x86} - else: - return set() - elif native_architecture in {Architecture.i686, Architecture.x86}: - return {native_architecture} if bitiness == "32" else set() + def bitiness_archs(platform: PlatformName, bitiness: Literal['64', '32']) -> 'Set[Architecture]': + archs_32 = {Architecture.i686, Architecture.x86} + auto_archs = Architecture.auto_archs(platform) + + if bitiness == '64': + return auto_archs - archs_32 + elif bitiness == '32': + return auto_archs & archs_32 else: - # assert_never doesn't work here, oddly, maybe due to set checking above - raise RuntimeError("Cannot be reached") + assert_never(bitiness) def allowed_architectures_check( diff --git a/docs/options.md b/docs/options.md index fdc03fae0..e55facafa 100644 --- a/docs/options.md +++ b/docs/options.md @@ -172,8 +172,8 @@ Options: - macOS: `x86_64` `arm64` `universal2` - Windows: `AMD64` `x86` - `auto`: The default archs for your machine - see the table below. - - `auto64`: Just the 64-bit auto archs (will result in an empty set on a 32-bit runner) - - `auto32`: Just the 32-bit auto archs (will result in an empty set on macOS) + - `auto64`: Just the 64-bit auto archs + - `auto32`: Just the 32-bit auto archs - `native`: the native arch of the build machine - Matches [`platform.machine()`](https://docs.python.org/3/library/platform.html#platform.machine). - `all` : expands to all the architectures supported on this OS. You may want to use [CIBW_BUILD](#build-skip) with this option to target specific @@ -181,12 +181,12 @@ Options: Default: `auto` -| Runner | `native` | `auto` -|---|---|--- -| Linux / Intel | `x86_64` | `x86_64` `i686` -| Windows / Intel | `AMD64` | `AMD64` `x86` -| macOS / Intel | `x86_64` | `x86_64` -| macOS / AppleĀ Silicon | `arm64` | `arm64` `universal2` +| Runner | `native` | `auto` | `auto64` | `auto32` | +|---|---|---|---|---| +| Linux / Intel | `x86_64` | `x86_64` `i686` | `x86_64` | `i686` | +| Windows / Intel | `AMD64` | `AMD64` `x86` | `AMD64` | `x86` | +| macOS / Intel | `x86_64` | `x86_64` | `x86_64` | | +| macOS / AppleĀ Silicon | `arm64` | `arm64` `universal2` | `arm64` `universal2`| | If not listed above, `auto` is the same as `native`. @@ -196,6 +196,8 @@ If not listed above, `auto` is the same as `native`. Platform-specific variants also available:
`CIBW_ARCHS_MACOS` | `CIBW_ARCHS_WINDOWS` | `CIBW_ARCHS_LINUX` +This option can also be set using the [command-line option](#command-line) `--archs`. + #### Examples ```yaml @@ -208,10 +210,6 @@ CIBW_ARCHS_MACOS: "x86_64 universal2 arm64" CIBW_ARCHS_LINUX: "auto aarch64" ``` -Platform-specific variants also available:
-`CIBW_ARCHS_MACOS` | `CIBW_ARCHS_WINDOWS` | `CIBW_ARCHS_LINUX` - -This option can also be set using the [command-line option](#command-line) `--archs`. ### `CIBW_PROJECT_REQUIRES_PYTHON` {: #requires-python} > Manually set the Python compatibility of your project From 729f32bb63ae9434cdb800624a3568aff921898a Mon Sep 17 00:00:00 2001 From: Henry Fredrick Schreiner Date: Sun, 31 Jan 2021 17:35:17 -0500 Subject: [PATCH 3/3] refactor: spelling fix --- cibuildwheel/architecture.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cibuildwheel/architecture.py b/cibuildwheel/architecture.py index 08e5061d3..7aeb7be30 100644 --- a/cibuildwheel/architecture.py +++ b/cibuildwheel/architecture.py @@ -45,9 +45,9 @@ def parse_config(config: str, platform: PlatformName) -> 'Set[Architecture]': elif arch_str == 'all': result |= Architecture.all_archs(platform=platform) elif arch_str == 'auto64': - result |= Architecture.bitiness_archs(platform=platform, bitiness="64") + result |= Architecture.bitness_archs(platform=platform, bitness="64") elif arch_str == 'auto32': - result |= Architecture.bitiness_archs(platform=platform, bitiness="32") + result |= Architecture.bitness_archs(platform=platform, bitness="32") else: result.add(Architecture(arch_str)) return result @@ -82,16 +82,16 @@ def all_archs(platform: PlatformName) -> 'Set[Architecture]': assert_never(platform) @staticmethod - def bitiness_archs(platform: PlatformName, bitiness: Literal['64', '32']) -> 'Set[Architecture]': + def bitness_archs(platform: PlatformName, bitness: Literal['64', '32']) -> 'Set[Architecture]': archs_32 = {Architecture.i686, Architecture.x86} auto_archs = Architecture.auto_archs(platform) - if bitiness == '64': + if bitness == '64': return auto_archs - archs_32 - elif bitiness == '32': + elif bitness == '32': return auto_archs & archs_32 else: - assert_never(bitiness) + assert_never(bitness) def allowed_architectures_check(