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 0d29bf8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
19 changes: 9 additions & 10 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 @@ -185,8 +182,10 @@ def main() -> None:
print('cibuildwheel: Could not find setup.py, setup.cfg or pyproject.toml at root of package', file=sys.stderr)
exit(2)

archs = [Architecture(a) for a in args.archs.split(",")]

if args.print_build_identifiers:
print_build_identifiers(platform, build_selector, args.architectures)
print_build_identifiers(platform, build_selector, archs)
exit(0)

manylinux_images: Optional[Dict[str, str]] = None
Expand Down Expand Up @@ -219,7 +218,7 @@ def main() -> None:
manylinux_images[build_platform] = image

build_options = BuildOptions(
architectures=args.architectures,
architectures=archs,
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 0d29bf8

Please sign in to comment.