Skip to content

Commit d1c9c47

Browse files
authored
Override macOS deployment target (#641)
1 parent 89fe36a commit d1c9c47

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

setup.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,23 @@
1212
import sys
1313
import sysconfig
1414
from wheel.bdist_wheel import bdist_wheel
15+
1516
if sys.platform == 'win32':
1617
# distutils is deprecated in Python 3.10 and removed in 3.12. However, it still works because Python defines a compatibility interface as long as setuptools is installed.
1718
# We don't have an official alternative for distutils.ccompiler as of September 2024. See: https://github.com/pypa/setuptools/issues/2806
1819
# Once that issue is resolved, we can migrate to the official solution.
1920
# For now, restrict distutils to Windows only, where it's needed.
2021
import distutils.ccompiler
2122

23+
# The minimum MACOSX_DEPLOYMENT_TARGET required for the library. If not
24+
# set, the library will use the default value from python
25+
# sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET').
26+
MACOS_DEPLOYMENT_TARGET_MIN = "10.15"
27+
28+
29+
def parse_version(version_string):
30+
return tuple(int(x) for x in version_string.split("."))
31+
2232

2333
def is_64bit():
2434
return sys.maxsize > 2 ** 32
@@ -231,11 +241,15 @@ def _build_dependencies_impl(self, build_dir, install_path, osx_arch=None):
231241
cmake_args.append('-DAWS_USE_LIBCRYPTO_TO_SUPPORT_ED25519_EVERYWHERE=ON')
232242

233243
if sys.platform == 'darwin':
234-
# build lib with same MACOSX_DEPLOYMENT_TARGET that python will ultimately
235-
# use to link everything together, otherwise there will be linker warnings.
244+
# get Python's MACOSX_DEPLOYMENT_TARGET version
236245
macosx_target_ver = sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
237-
if macosx_target_ver and 'MACOSX_DEPLOYMENT_TARGET' not in os.environ:
238-
cmake_args.append(f'-DCMAKE_OSX_DEPLOYMENT_TARGET={macosx_target_ver}')
246+
# If MACOS_DEPLOYMENT_TARGET_MIN is set to a later version than python distribution,
247+
# override MACOSX_DEPLOYMENT_TARGET.
248+
if macosx_target_ver is None or parse_version(
249+
MACOS_DEPLOYMENT_TARGET_MIN) > parse_version(macosx_target_ver):
250+
macosx_target_ver = MACOS_DEPLOYMENT_TARGET_MIN
251+
os.environ['MACOSX_DEPLOYMENT_TARGET'] = macosx_target_ver
252+
cmake_args.append(f'-DCMAKE_OSX_DEPLOYMENT_TARGET={macosx_target_ver}')
239253

240254
if osx_arch:
241255
cmake_args.append(f'-DCMAKE_OSX_ARCHITECTURES={osx_arch}')

0 commit comments

Comments
 (0)