Skip to content

Commit

Permalink
feat: auto32/auto64
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Jan 22, 2021
1 parent d87b589 commit b071603
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) <br> [`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 |
| **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. |
| | [`CIBW_BEFORE_BUILD`](https://cibuildwheel.readthedocs.io/en/stable/options/#before-build) | Execute a shell command preparing each wheel's build |
Expand Down
2 changes: 1 addition & 1 deletion cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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'),
Expand Down
22 changes: 21 additions & 1 deletion cibuildwheel/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}

Expand Down Expand Up @@ -64,6 +64,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,
Expand Down
32 changes: 22 additions & 10 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,28 +155,40 @@ CIBW_SKIP: pp*
}
</style>

### `CIBW_ARCHS_LINUX` {: #archs}
> Build non-native architectures
### `CIBW_ARCHS` {: #archs}
> Control available architectures

A space-separated list of architectures to build. Use this in conjunction with
emulation, such as that provided by [docker/setup-qemu-action][setup-qemu-action]
or [tonistiigi/binfmt][binfmt], to build architectures other than those your
machine natively supports.
A space-separated list of architectures to build; also available as `--archs`
on the command line. On Linux, use this in conjunction with emulation, such as
that provided by [docker/setup-qemu-action][setup-qemu-action] or
[tonistiigi/binfmt][binfmt], to build architectures other than those your
machine natively supports. It is an error to list an architecture that could
not be supported on that platform, like `AMD64` on Unix systems; use the
platform specific variants instead.

Options: `auto` `native` `all` `x86_64` `i686` `aarch64` `ppc64le` `s390x`
Options: `auto` `auto64` `auto32` `native` `all`; macOS and Linux: `x86_64`; Linux only: `x86_64` `i686` `aarch64` `ppc64le` `s390x`; Windows: `x86` `AMD64`

Default: `auto`, meaning the native archs supported on the build machine. For
example, on an `x86_64` machine, `auto` expands to `x86_64` and `i686`.

`auto64` and `auto32` will limit to just 64 or 32 bit versions of the auto
archs; on macOS or a 32-bit machine this might be an empty set, which is an
error unless `--allow-empty` is passed; it is recommended that you exclude
32-bit macOS in your matrix if you are using this.

`native` will only build on the exact architecture you currently are on; it will
not add `i686` for `x86_64`.
not add `i686` for `x86_64`, for example.

`all` will expand to all known architectures; remember to use build selectors
to limit builds for each job; this list could grow in the future.
`all` will expand to all known architectures including potentially emulated
ones on Linux; remember to use build selectors to limit builds for each job;
this list could grow in the future.

[setup-qemu-action]: https://github.com/docker/setup-qemu-action
[binfmt]: https://hub.docker.com/r/tonistiigi/binfmt

Platform-specific variants also available:<br/>
`CIBW_ARCHS_MACOS` | `CIBW_ARCHS_WINDOWS` | `CIBW_ARCHS_LINUX`

#### Examples

```yaml
Expand Down
33 changes: 33 additions & 0 deletions unit_test/main_tests/main_platform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,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')

Expand Down

0 comments on commit b071603

Please sign in to comment.