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 21, 2021
1 parent fba65a6 commit 8e8935b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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
26 changes: 25 additions & 1 deletion cibuildwheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import toml

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

if sys.version_info < (3, 9):
from importlib_resources import files
Expand Down Expand Up @@ -192,6 +192,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
Expand All @@ -218,6 +222,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 should work here
raise RuntimeError("Cannot be reached")


class BuildOptions(NamedTuple):
package_dir: Path
Expand Down

0 comments on commit 8e8935b

Please sign in to comment.