Skip to content

Commit

Permalink
Merge pull request #484 from joerick/macos-universal2
Browse files Browse the repository at this point in the history
Universal2 wheels on macOS
  • Loading branch information
joerick authored Jan 31, 2021
2 parents 0de4608 + 2def20d commit b95dca5
Show file tree
Hide file tree
Showing 22 changed files with 554 additions and 99 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ jobs:
run: |
python bin/sample_build.py
- name: Get some sample wheels
run: |
python -m test.test_projects test.test_0_basic.basic_project sample_proj
cibuildwheel --output-dir wheelhouse sample_proj
env:
CIBW_ARCHS_MACOS: x86_64 universal2 arm64

- uses: actions/upload-artifact@v2
with:
name: sample_wheels
path: wheelhouse

- name: Test cibuildwheel
run: |
python ./bin/run_tests.py
Expand Down
2 changes: 1 addition & 1 deletion bin/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
subprocess.check_call(unit_test_args)

# run the integration tests
subprocess.check_call([sys.executable, '-m', 'pytest', '-x', '--durations', '0', '--timeout=1200', 'test'])
subprocess.check_call([sys.executable, '-m', 'pytest', '-x', '--durations', '0', '--timeout=2400', 'test'])
2 changes: 1 addition & 1 deletion bin/sample_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
options.project_python_path, project_dir
], check=True)

sys.exit(subprocess.run(['cibuildwheel'], cwd=project_dir).returncode)
sys.exit(subprocess.run([sys.executable, '-m', 'cibuildwheel'], cwd=project_dir).returncode)
4 changes: 2 additions & 2 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def main() -> None:
if platform == 'linux':
repair_command_default = 'auditwheel repair -w {dest_dir} {wheel}'
elif platform == 'macos':
repair_command_default = 'delocate-listdeps {wheel} && delocate-wheel --require-archs x86_64 -w {dest_dir} {wheel}'
repair_command_default = 'delocate-listdeps {wheel} && delocate-wheel --require-archs {delocate_archs} -w {dest_dir} {wheel}'
elif platform == 'windows':
repair_command_default = ''
else:
Expand Down Expand Up @@ -339,7 +339,7 @@ def get_build_identifiers(
elif platform == 'windows':
python_configurations = cibuildwheel.windows.get_python_configurations(build_selector, architectures)
elif platform == 'macos':
python_configurations = cibuildwheel.macos.get_python_configurations(build_selector)
python_configurations = cibuildwheel.macos.get_python_configurations(build_selector, architectures)
else:
assert_never(platform)

Expand Down
15 changes: 14 additions & 1 deletion cibuildwheel/architecture.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ class Architecture(Enum):

# mac/linux archs
x86_64 = 'x86_64'

# linux archs
i686 = 'i686'
aarch64 = 'aarch64'
ppc64le = 'ppc64le'
s390x = 's390x'

# mac archs
universal2 = 'universal2'
arm64 = 'arm64'

# windows archs
x86 = 'x86'
AMD64 = 'AMD64'
Expand All @@ -46,19 +52,26 @@ def parse_config(config: str, platform: PlatformName) -> 'Set[Architecture]':
def auto_archs(platform: PlatformName) -> 'Set[Architecture]':
native_architecture = Architecture(platform_module.machine())
result = {native_architecture}

if platform == 'linux' and native_architecture == Architecture.x86_64:
# x86_64 machines can run i686 docker containers
result.add(Architecture.i686)

if platform == 'windows' and native_architecture == Architecture.AMD64:
result.add(Architecture.x86)

if platform == 'macos' and native_architecture == Architecture.arm64:
# arm64 can build and test both archs of a universal2 wheel.
result.add(Architecture.universal2)

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}
return {Architecture.x86_64, Architecture.arm64, Architecture.universal2}
elif platform == 'windows':
return {Architecture.x86, Architecture.AMD64}
else:
Expand Down
3 changes: 2 additions & 1 deletion cibuildwheel/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def build(options: BuildOptions) -> None:

env = docker.get_environment()
env['PATH'] = f'/opt/python/cp38-cp38/bin:{env["PATH"]}'
env['PIP_DISABLE_PIP_VERSION_CHECK'] = '1'
env = options.environment.as_dictionary(env, executor=docker.environment_executor)

before_all_prepared = prepare_command(options.before_all, project=container_project_path, package=container_package_dir)
Expand Down Expand Up @@ -228,7 +229,7 @@ def build(options: BuildOptions) -> None:
docker.copy_out(container_output_dir, options.output_dir)
log.step_end()
except subprocess.CalledProcessError as error:
log.error(f'Command {error.cmd} failed with code {error.returncode}. {error.stdout}')
log.step_end_with_error(f'Command {error.cmd} failed with code {error.returncode}. {error.stdout}')
troubleshoot(options.package_dir, error)
sys.exit(1)

Expand Down
18 changes: 14 additions & 4 deletions cibuildwheel/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
'win32': 'Windows 32bit',
'win_amd64': 'Windows 64bit',
'macosx_x86_64': 'macOS x86_64',
'macosx_universal2': 'macOS Universal 2 - x86_64 and arm64',
'macosx_arm64': 'macOS arm64 - Apple Silicon',
}


Expand Down Expand Up @@ -109,15 +111,23 @@ def step_end(self, success: bool = True) -> None:

self.step_start_time = None

def error(self, error: Union[BaseException, str]) -> None:
def step_end_with_error(self, error: Union[BaseException, str]) -> None:
self.step_end(success=False)
print()
self.error(error)

def warning(self, message: str) -> None:
if self.fold_mode == 'github':
print(f'::warning::{message}\n', file=sys.stderr)
else:
c = self.colors
print(f'{c.yellow}Warning{c.end}: {message}\n', file=sys.stderr)

def error(self, error: Union[BaseException, str]) -> None:
if self.fold_mode == 'github':
print(f'::error::{error}')
print(f'::error::{error}\n', file=sys.stderr)
else:
c = self.colors
print(f'{c.bright_red}Error{c.end} {error}')
print(f'{c.bright_red}Error{c.end}: {error}\n', file=sys.stderr)

def _start_fold_group(self, name: str) -> None:
self._end_fold_group()
Expand Down
Loading

0 comments on commit b95dca5

Please sign in to comment.