From 0bdafc56497f77a081e54c0f2482cbed77c6fc7c Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Sun, 5 Apr 2020 12:12:42 +0100 Subject: [PATCH 1/5] Set MACOSX_DEPLOYMENT_TARGET to 10.9, if not set by the user --- cibuildwheel/macos.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 59106262..c867dc53 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -162,16 +162,17 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes exit(1) call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate'], env=env) - # setup target platform, only required for python 3.5 + # Set MACOSX_DEPLOYMENT_TARGET to 10.9, if the user didn't set it. + # CPython 3.5 defaults to 10.6, and pypy defaults to 10.3, causing + # warnings and potential problems if it's left unset. + env.setdefault('MACOSX_DEPLOYMENT_TARGET', '10.9') + if config.version == '3.5': - if '_PYTHON_HOST_PLATFORM' not in env: - # cross-compilation platform override - env['_PYTHON_HOST_PLATFORM'] = 'macosx-10.9-x86_64' - if 'ARCHFLAGS' not in env: - # https://github.com/python/cpython/blob/a5ed2fe0eedefa1649aa93ee74a0bafc8e628a10/Lib/_osx_support.py#L260 - env['ARCHFLAGS'] = '-arch x86_64' - if 'MACOSX_DEPLOYMENT_TARGET' not in env: - env['MACOSX_DEPLOYMENT_TARGET'] = '10.9' + # Cross-compilation platform override - CPython 3.5 has an + # i386/x86_64 version of Python, but we only want a x64_64 build + env.setdefault('_PYTHON_HOST_PLATFORM', 'macosx-10.9-x86_64') + # https://github.com/python/cpython/blob/a5ed2fe0eedefa1649aa93ee74a0bafc8e628a10/Lib/_osx_support.py#L260 + env.setdefault('ARCHFLAGS', '-arch x86_64') # run the before_build command if before_build: From 93df99e43be08997f3e12ce066974c046b15c2e8 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Sun, 5 Apr 2020 12:20:07 +0100 Subject: [PATCH 2/5] Remove potentially confusing line in docs --- docs/cpp_standards.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/cpp_standards.md b/docs/cpp_standards.md index 39666c66..88ff6578 100644 --- a/docs/cpp_standards.md +++ b/docs/cpp_standards.md @@ -7,7 +7,7 @@ Building Python wheels with modern C++ standards (C++11 and later) requires a fe ## Python 2.7 and C++17 -The Python 2.7 header files use the `register` keyword, which is [reserved and unused from C+17 onwards](https://en.cppreference.com/w/cpp/keyword/register). Compiling a wheel for Python 2.7 with the C++17 standard is still possible to allow usage of `register` using proper flag `-Wno-register` for gcc/clang and `/wd5033` for MSVC. +The Python 2.7 header files use the `register` keyword, which is [reserved and unused from C+17 onwards](https://en.cppreference.com/w/cpp/keyword/register). Compiling a wheel for Python 2.7 with the C++17 standard is still possible to allow usage of `register` using proper flag `-Wno-register` for gcc/clang and `/wd5033` for MSVC. ## manylinux1 and C++14 The default `manylinux1` image (based on CentOS 5) contains a version of GCC and libstdc++ that only supports C++11 and earlier standards. There are however ways to compile wheels with the C++14 standard (and later): https://github.com/pypa/manylinux/issues/118 @@ -16,7 +16,7 @@ The default `manylinux1` image (based on CentOS 5) contains a version of GCC and ## macOS and deployment target versions -OS X/macOS allows you to specify a so-called "deployment target" version that will ensure backwards compatibility with older versions of macOS. One way to do this is by setting the `MACOSX_DEPLOYMENT_TARGET` environment variable. If not set, Python will set this variable to the version the Python distribution itself was compiled on (10.6 or 10.9, for the python.org packages), when creating the wheel. +OS X/macOS allows you to specify a so-called "deployment target" version that will ensure backwards compatibility with older versions of macOS. One way to do this is by setting the `MACOSX_DEPLOYMENT_TARGET` environment variable. However, to enable modern C++ standards, the deploment target needs to be set high enough (since older OS X/macOS versions did not have the necessary modern C++ standard library). From 27b79f8616784a45c6faa990e069e9422c175a85 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Sun, 5 Apr 2020 12:34:52 +0100 Subject: [PATCH 3/5] Fix tests to always default to 10.9 --- test/shared/utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/shared/utils.py b/test/shared/utils.py index 862d4466..fe7937ff 100644 --- a/test/shared/utils.py +++ b/test/shared/utils.py @@ -72,7 +72,7 @@ def cibuildwheel_run(project_path, env=None, add_env=None, output_dir=None): def expected_wheels(package_name, package_version, manylinux_versions=None, - macosx_deployment_target=None): + macosx_deployment_target='10.9'): ''' Returns a list of expected wheels from a run of cibuildwheel. ''' @@ -117,8 +117,7 @@ def expected_wheels(package_name, package_version, manylinux_versions=None, python_abi_tags += extra_x86_python_abi_tags def get_platform_tags(python_abi_tag): - default_version = '10.7' if python_abi_tag.startswith('pp') else '10.9' - return ['macosx_{}_x86_64'.format((macosx_deployment_target or default_version).replace('.', '_'))] + return ['macosx_{}_x86_64'.format(macosx_deployment_target.replace('.', '_'))] else: raise Exception('unsupported platform') From b52edf89eff15f93b94148950ef71a4b33dcb2b5 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Sun, 5 Apr 2020 12:40:35 +0100 Subject: [PATCH 4/5] Tidy up cpp_standards tests, removing 10.9 references as this is default --- test/10_cpp_standards/cibuildwheel_test.py | 38 ++++++++++------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/test/10_cpp_standards/cibuildwheel_test.py b/test/10_cpp_standards/cibuildwheel_test.py index cf838800..72a8f676 100644 --- a/test/10_cpp_standards/cibuildwheel_test.py +++ b/test/10_cpp_standards/cibuildwheel_test.py @@ -10,35 +10,30 @@ project_dir = os.path.dirname(__file__) def test_cpp11(tmp_path): # This test checks that the C++11 standard is supported - add_env = {'CIBW_SKIP': 'cp27-win* pp27-win32', 'CIBW_ENVIRONMENT': 'STANDARD=11'} # VC++ for Python 2.7 does not support modern standards - if utils.platform == 'macos': - add_env['MACOSX_DEPLOYMENT_TARGET'] = '10.9' + add_env = {'CIBW_SKIP': 'cp27-win* pp27-win32', 'CIBW_ENVIRONMENT': 'STANDARD=11'} actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env) - expected_wheels = [w for w in utils.expected_wheels( - 'spam', '0.1.0', macosx_deployment_target='10.9') - if 'cp27-cp27m-win' not in w - and 'pp27-pypy_73-win32' not in w] + expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0') + if 'cp27-cp27m-win' not in w and 'pp27-pypy_73-win32' not in w] + assert set(actual_wheels) == set(expected_wheels) def test_cpp14(): # This test checks that the C++14 standard is supported - add_env = {'CIBW_SKIP': 'cp27-win* pp27-win32 cp35-win*', 'CIBW_ENVIRONMENT': 'STANDARD=14'} # VC++ for Python 2.7 does not support modern standards # The manylinux1 docker image does not have a compiler which supports C++11 # Python 3.4 and 3.5 are compiled with MSVC 10, which does not support C++14 - if utils.platform == 'macos': - add_env['MACOSX_DEPLOYMENT_TARGET'] = '10.9' + add_env = {'CIBW_SKIP': 'cp27-win* pp27-win32 cp35-win*', 'CIBW_ENVIRONMENT': 'STANDARD=14'} actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env) - expected_wheels = [w for w in utils.expected_wheels( - 'spam', '0.1.0', macosx_deployment_target='10.9') - if 'cp27-cp27m-win' not in w - and 'pp27-pypy_73-win32' not in w - and 'cp35-cp35m-win' not in w] + expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0') + if 'cp27-cp27m-win' not in w + and 'pp27-pypy_73-win32' not in w + and 'cp35-cp35m-win' not in w] + assert set(actual_wheels) == set(expected_wheels) @@ -52,14 +47,15 @@ def test_cpp17(): pytest.skip('Visual Studio 2015 does not support C++17') add_env = {'CIBW_SKIP': 'cp27-win* pp27-win32 cp35-win* pp36-win32', 'CIBW_ENVIRONMENT': 'STANDARD=17'} + if utils.platform == 'macos': add_env['MACOSX_DEPLOYMENT_TARGET'] = '10.13' actual_wheels = utils.cibuildwheel_run(project_dir, add_env=add_env) - expected_wheels = [w for w in utils.expected_wheels( - 'spam', '0.1.0', macosx_deployment_target='10.13') - if 'cp27-cp27m-win' not in w - and 'pp27-pypy_73-win32' not in w - and 'cp35-cp35m-win' not in w - and 'pp36-pypy36_pp73-win32' not in w] + expected_wheels = [w for w in utils.expected_wheels('spam', '0.1.0', macosx_deployment_target='10.13') + if 'cp27-cp27m-win' not in w + and 'pp27-pypy_73-win32' not in w + and 'cp35-cp35m-win' not in w + and 'pp36-pypy36_pp73-win32' not in w] + assert set(actual_wheels) == set(expected_wheels) From 2b4bd815edf07be0645b66740a7a81711904740f Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Tue, 7 Apr 2020 18:50:16 +0100 Subject: [PATCH 5/5] Fix some whitespace problems with the merge --- cibuildwheel/macos.py | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index b62b1e83..6caf6060 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -115,7 +115,7 @@ def setup_python(python_configuration, dependency_constraint_flags, environment) installation_bin_path = install_pypy(python_configuration.version, python_configuration.url) else: raise ValueError("Unknown Python implementation") - + env = os.environ.copy() env['PATH'] = os.pathsep.join([ SYMLINKS_DIR, @@ -139,29 +139,29 @@ def setup_python(python_configuration, dependency_constraint_flags, environment) if which_python != '/tmp/cibw_bin/python': print("cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", file=sys.stderr) exit(1) - - # install pip & wheel - call(['python', get_pip_script] + dependency_constraint_flags, env=env, cwd="/tmp") - assert os.path.exists(os.path.join(installation_bin_path, 'pip')) - call(['which', 'pip'], env=env) - call(['pip', '--version'], env=env) - which_pip = subprocess.check_output(['which', 'pip'], env=env, universal_newlines=True).strip() - if which_pip != '/tmp/cibw_bin/pip': - print("cibuildwheel: pip available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it.", file=sys.stderr) - exit(1) - call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate'] + dependency_constraint_flags, env=env) -# Set MACOSX_DEPLOYMENT_TARGET to 10.9, if the user didn't set it. -# CPython 3.5 defaults to 10.6, and pypy defaults to 10.3, causing -# warnings and potential problems if it's left unset. -env.setdefault('MACOSX_DEPLOYMENT_TARGET', '10.9') - - if config.version == '3.5': + # install pip & wheel + call(['python', get_pip_script] + dependency_constraint_flags, env=env, cwd="/tmp") + assert os.path.exists(os.path.join(installation_bin_path, 'pip')) + call(['which', 'pip'], env=env) + call(['pip', '--version'], env=env) + which_pip = subprocess.check_output(['which', 'pip'], env=env, universal_newlines=True).strip() + if which_pip != '/tmp/cibw_bin/pip': + print("cibuildwheel: pip available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it.", file=sys.stderr) + exit(1) + call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate'] + dependency_constraint_flags, env=env) + + # Set MACOSX_DEPLOYMENT_TARGET to 10.9, if the user didn't set it. + # CPython 3.5 defaults to 10.6, and pypy defaults to 10.7, causing + # inconsistencies if it's left unset. + env.setdefault('MACOSX_DEPLOYMENT_TARGET', '10.9') + + if python_configuration.version == '3.5': # Cross-compilation platform override - CPython 3.5 has an # i386/x86_64 version of Python, but we only want a x64_64 build env.setdefault('_PYTHON_HOST_PLATFORM', 'macosx-10.9-x86_64') - # https://github.com/python/cpython/blob/a5ed2fe0eedefa1649aa93ee74a0bafc8e628a10/Lib/_osx_support.py#L260 - env.setdefault('ARCHFLAGS', '-arch x86_64') + # https://github.com/python/cpython/blob/a5ed2fe0eedefa1649aa93ee74a0bafc8e628a10/Lib/_osx_support.py#L260 + env.setdefault('ARCHFLAGS', '-arch x86_64') return env @@ -181,9 +181,8 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes dependency_constraint_flags = [ '-c', dependency_constraints.get_for_python_version(config.version) ] - - env = setup_python(config, dependency_constraint_flags, environment) + env = setup_python(config, dependency_constraint_flags, environment) # run the before_build command if before_build: