Skip to content

Commit

Permalink
refactor: --archs, CIBW_ARCHS, "auto"
Browse files Browse the repository at this point in the history
Using `--archs` for the flag, comma separated, also accepting CIBW_ARCHS.
Supports "auto" as the default that can also expand, matching
CIBW_PLATFORM.
  • Loading branch information
henryiii committed Dec 18, 2020
1 parent ec99c01 commit 78501f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
15 changes: 6 additions & 9 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,16 @@ def main() -> None:
''')

parser.add_argument(
'-a',
'--architectures',
choices=[arch.value for arch in Architecture],
default=[],
'--archs',
default=os.environ.get("CIBW_ARCHS", 'auto'),
help='''
Comma-separated list of CPU architectures to build for.
If unspecified, builds the architectures natively supported
on this machine. Set this option to build an architecture
via emulation, for example, using binfmt_misc and qemu.
''',
action="extend",
nargs="+",
type=Architecture,
Default: auto
Choices: auto, {}
'''.format(", ".join(a.name for a in Architecture)),
)
parser.add_argument('--output-dir',
default=os.environ.get('CIBW_OUTPUT_DIR', 'wheelhouse'),
Expand Down Expand Up @@ -219,7 +216,7 @@ def main() -> None:
manylinux_images[build_platform] = image

build_options = BuildOptions(
architectures=args.architectures,
architectures=[Architecture(a) for a in args.archs.split(",")],
package_dir=package_dir,
output_dir=output_dir,
test_command=test_command,
Expand Down
18 changes: 12 additions & 6 deletions cibuildwheel/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
re_pattern = re.compile(r'[cp]p\d{2}-manylinux_(\w*)')


def matches_platform(identifier: str, supported_platforms: List[Architecture]) -> bool:
def matches_platform(identifier: str, architectures: List[Architecture]) -> bool:
matched_architecture = re_pattern.search(identifier)
id_architecture = matched_architecture.group(1) if matched_architecture else ''
return id_architecture in supported_platforms
return id_architecture in architectures


class PythonConfiguration(NamedTuple):
Expand Down Expand Up @@ -73,10 +73,16 @@ def get_python_configurations(
]

# skip builds as required
target_archs = architectures or [Architecture(platform.machine())]
# x86_64 machines can run i686 docker containers
if Architecture.i686 not in target_archs and Architecture.x86_64 in target_archs:
target_archs.append(Architecture.i686)
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)

print("matching platforms to architectures: ", target_archs)
return [
c for c in python_configurations
Expand Down
1 change: 1 addition & 0 deletions cibuildwheel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __repr__(self):


class Architecture(str, Enum):
auto = 'auto' # gets expanded to the native arch, possibly 32+64 bit
x86_64 = 'x86_64'
i686 = 'i686'
aarch64 = 'aarch64'
Expand Down

0 comments on commit 78501f4

Please sign in to comment.