Skip to content

Commit

Permalink
feat: native / all archs
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Jan 15, 2021
1 parent b627134 commit 9f6d309
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,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, {}
Choices: auto, 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
25 changes: 17 additions & 8 deletions cibuildwheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import toml

from .environment import ParsedEnvironment
from .typing import PathOrStr, PlatformName
from .typing import PathOrStr, PlatformName, assert_never

if sys.version_info < (3, 9):
from importlib_resources import files
Expand Down Expand Up @@ -169,6 +169,10 @@ def parse_config(config: str, platform: PlatformName) -> 'Set[Architecture]':
for arch_str in re.split(r'[\s,]+', config):
if arch_str == 'auto':
result |= Architecture.auto_archs(platform=platform)
elif arch_str == 'native':
result.add(Architecture(platform_module.machine()))
elif arch_str == 'all':
result |= Architecture.all_archs(platform=platform)
else:
result.add(Architecture(arch_str))
return result
Expand All @@ -184,6 +188,17 @@ def auto_archs(platform: PlatformName) -> 'Set[Architecture]':
result.add(Architecture.x86)
return result

@staticmethod
def all_archs(platform: PlatformName) -> 'Set[Architecture]':
if platform == 'linux':
return {Architecture.x86_64, Architecture.i686, Architecture.aarch64, Architecture.ppc64le, Architecture.s390x}
elif platform == 'macos':
return {Architecture.x86_64}
elif platform == 'windows':
return {Architecture.x86, Architecture.AMD64}
else:
assert_never(platform)


class BuildOptions(NamedTuple):
package_dir: Path
Expand Down Expand Up @@ -255,19 +270,13 @@ def detect_ci_provider() -> Optional[CIProvider]:

PRETTY_NAMES = {'linux': 'Linux', 'macos': 'macOS', 'windows': 'Windows'}

ALLOWED_ARCHITECTURES = {
'linux': {Architecture.x86_64, Architecture.i686, Architecture.aarch64, Architecture.ppc64le, Architecture.s390x},
'macos': {Architecture.x86_64},
'windows': {Architecture.AMD64, Architecture.x86},
}


def allowed_architectures_check(
name: PlatformName,
options: BuildOptions,
) -> None:

allowed_architectures = ALLOWED_ARCHITECTURES[name]
allowed_architectures = Architecture.all_archs(name)

msg = f'{PRETTY_NAMES[name]} only supports {sorted(allowed_architectures)} at the moment.'

Expand Down
30 changes: 30 additions & 0 deletions unit_test/main_tests/main_platform_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,33 @@ def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch):
assert build_options.architectures == {Architecture.x86}
elif platform == 'macos':
assert build_options.architectures == {Architecture.x86_64}


def test_archs_platform_native(platform, intercepted_build_args, monkeypatch):
monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64')
monkeypatch.setenv('CIBW_ARCHS', 'native')

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.x86_64}
elif platform == 'macos':
assert build_options.architectures == {Architecture.x86_64}


def test_archs_platform_all(platform, intercepted_build_args, monkeypatch):
monkeypatch.setattr(platform_module, 'machine', lambda: 'x86_64')
monkeypatch.setenv('CIBW_ARCHS', 'all')

main()
build_options = intercepted_build_args.args[0]

if platform == 'linux':
assert build_options.architectures == {Architecture.x86_64, Architecture.i686, Architecture.aarch64, Architecture.ppc64le, Architecture.s390x}
elif platform == 'windows':
assert build_options.architectures == {Architecture.x86, Architecture.AMD64}
elif platform == 'macos':
assert build_options.architectures == {Architecture.x86_64}

0 comments on commit 9f6d309

Please sign in to comment.