diff --git a/lib-python/2.7/_osx_support.py b/lib-python/2.7/_osx_support.py index d2aaae7986a1787a56ec3376fac538e3d0b28a57..954e0db95b3d7b738a214881b58890234bac9812 100644 --- a/lib-python/2.7/_osx_support.py +++ b/lib-python/2.7/_osx_support.py @@ -301,6 +301,27 @@ def _check_for_unavailable_sdk(_config_vars): return _config_vars +def _set_deployment_target(_config_vars): + """Assign MACOSX_DEPLOYMENT_TARGET translation options. + + The MACOSX_DEPLOYMENT_TARGET environment variable selects which + version of macOS its build system, such as compilers and linkers, + will target. This is commonly set or detected during translation, + similar to CPython we do not allow overriding this with an + environment variable. + + """ + + t = sys.pypy_translation_info.get( + 'translation.macosx_deployment_target', None, + ) + + if t: + _config_vars['MACOSX_DEPLOYMENT_TARGET'] = t + + return _config_vars + + def compiler_fixup(compiler_so, cc_args): """ This function will strip '-isysroot PATH' and '-arch ARCH' from the @@ -390,6 +411,9 @@ def customize_config_vars(_config_vars): Currently called from distutils.sysconfig """ + # Set MACOSX_DEPLOYMENT_TARGET + _set_deployment_target(_config_vars) + if not _supports_universal_builds(): # On Mac OS X before 10.4, check if -arch and -isysroot # are in CFLAGS or LDFLAGS and remove them if they are. diff --git a/lib-python/2.7/distutils/sysconfig_pypy.py b/lib-python/2.7/distutils/sysconfig_pypy.py index ec9f5a31db88236d6d009633c39c92d0bb8448c9..c40d7d86b67ab081ae8101d59989a16c6e9b3aa7 100644 --- a/lib-python/2.7/distutils/sysconfig_pypy.py +++ b/lib-python/2.7/distutils/sysconfig_pypy.py @@ -86,7 +86,11 @@ def _init_posix(): arch = platform.machine() g['LDSHARED'] += ' -undefined dynamic_lookup' g['CC'] += ' -arch %s' % (arch,) - g['MACOSX_DEPLOYMENT_TARGET'] = '10.7' + + if 'translation.macosx_deployment_target' in sys.pypy_translation_info: + g['MACOSX_DEPLOYMENT_TARGET'] = ( + sys.pypy_translation_info['translation.macosx_deployment_target'] + ) # pypy only: give us control over the ABI tag in a wheel name if '__pypy__' in sys.builtin_module_names: diff --git a/lib-python/2.7/sysconfig.py b/lib-python/2.7/sysconfig.py index 724b24e9e7e6b86dff27436aa0bb8df87115fad6..ca860cd6e3fb9876909cc6fcbaf11863b0ff1aaf 100644 --- a/lib-python/2.7/sysconfig.py +++ b/lib-python/2.7/sysconfig.py @@ -525,8 +525,6 @@ def get_config_vars(*args): # multi-architecture, multi-os-version installers if sys.platform == 'darwin': import _osx_support - #PyPy only - hardcode to 10.7, like in distutils/sysconfig_pypy.py - _CONFIG_VARS['MACOSX_DEPLOYMENT_TARGET'] = '10.7' _osx_support.customize_config_vars(_CONFIG_VARS) # PyPy: diff --git a/rpython/config/config.py b/rpython/config/config.py index 049ca40711455fdf0af3014b94028be896d9c670..acc04f0191a821fe30bae8c44dd89986a0cd0e6f 100644 --- a/rpython/config/config.py +++ b/rpython/config/config.py @@ -1,4 +1,5 @@ import optparse +import os from rpython.tool.pairtype import extendabletype SUPPRESS_USAGE = optparse.SUPPRESS_USAGE @@ -29,8 +30,12 @@ class Config(object): def _cfgimpl_build(self, overrides): for child in self._cfgimpl_descr._children: if isinstance(child, Option): - self._cfgimpl_values[child._name] = child.getdefault() - self._cfgimpl_value_owners[child._name] = 'default' + if os.getenv(child.envvar, None) is not None: + self._cfgimpl_values[child._name] = os.getenv(child.envvar) + self._cfgimpl_value_owners[child._name] = 'environment' + else: + self._cfgimpl_values[child._name] = child.getdefault() + self._cfgimpl_value_owners[child._name] = 'default' elif isinstance(child, OptionDescription): self._cfgimpl_values[child._name] = Config(child, parent=self) self.override(overrides) @@ -211,16 +216,20 @@ DEFAULT_OPTION_NAME = object() class Option(object): __metaclass__ = extendabletype - def __init__(self, name, doc, cmdline=DEFAULT_OPTION_NAME): + def __init__(self, name, doc, cmdline=DEFAULT_OPTION_NAME, envvar=None): self._name = name self.doc = doc self.cmdline = cmdline + self.envvar = envvar def validate(self, value): raise NotImplementedError('abstract base class') def getdefault(self): - return self.default + if self.envvar is not None: + return os.getenv(self.envvar, self.default) + else: + return self.default def setoption(self, config, value, who): name = self._name @@ -389,8 +398,8 @@ class FloatOption(Option): class StrOption(Option): opt_type = 'string' - def __init__(self, name, doc, default=None, cmdline=DEFAULT_OPTION_NAME): - super(StrOption, self).__init__(name, doc, cmdline) + def __init__(self, name, doc, default=None, cmdline=DEFAULT_OPTION_NAME, envvar=None): + super(StrOption, self).__init__(name, doc, cmdline, envvar=envvar) self.default = default def validate(self, value): diff --git a/rpython/config/translationoption.py b/rpython/config/translationoption.py index 1231d928e504a6ee3420eb3c51604cc97e0550db..2d2e834b86b9b595726d72be7a1ded9732a82745 100644 --- a/rpython/config/translationoption.py +++ b/rpython/config/translationoption.py @@ -42,8 +42,7 @@ PLATFORMS = [ 'arm', ] -translation_optiondescription = OptionDescription( - "translation", "Translation Options", [ +TRANSLATION_OPTIONS = [ BoolOption("continuation", "enable single-shot continuations", default=False, cmdline="--continuation", requires=[("translation.type_system", "lltype")]), @@ -297,7 +296,29 @@ translation_optiondescription = OptionDescription( BoolOption("rpython_translate", "Set to true by rpython/bin/rpython and translate.py", default=False), -]) +] + + +if sys.platform == 'darwin': + TRANSLATION_OPTIONS += [ + # + # Although Intel 32bit is supported since Apple Mac OS X 10.4, + # (and PPC since, ever) the @rpath handling is only available + # since 10.5, so we use that as minimum requirement. Bumped to + # 10.7 to allow the use of thread-local in __thread in C. + # + # Furthermore, pick up whatever explicitly requested in the + # environment. + # + StrOption("macosx_deployment_target", "Minimum macOS version supported", + cmdline="--macosx-version-min", + default="10.7", + envvar="MACOSX_DEPLOYMENT_TARGET") + ] + +translation_optiondescription = OptionDescription( + "translation", "Translation Options", TRANSLATION_OPTIONS, +) def get_combined_translation_config(other_optdescr=None, existing_config=None, diff --git a/rpython/rlib/rtime.py b/rpython/rlib/rtime.py index 7ddaf365a511a00ec3b7855bbde5788100349fbd..789f43ce8e266f4640afbecaf5236fb58d00883c 100644 --- a/rpython/rlib/rtime.py +++ b/rpython/rlib/rtime.py @@ -184,12 +184,10 @@ if _WIN32: counter_start = 0 state = State() -HAS_CLOCK_GETTIME = (CLOCK_MONOTONIC is not None) -if sys.platform == 'darwin': - HAS_CLOCK_GETTIME = False - # ^^^ issue #2432 and others - # (change it manually if you *know* you want to build and run on - # OS/X 10.12 or later) +HAS_CLOCK_GETTIME = ( + CLOCK_MONOTONIC is not None and + rffi_platform.has('clock_gettime(0, 0)', 'time.h') +) if HAS_CLOCK_GETTIME: # Linux and other POSIX systems with clock_gettime() diff --git a/rpython/translator/platform/darwin.py b/rpython/translator/platform/darwin.py index 73de52c688d3d58fefa4b10990dc35aea174cf68..e4ae10589e7ddcca58f58c880e5a311ad3e5ec15 100644 --- a/rpython/translator/platform/darwin.py +++ b/rpython/translator/platform/darwin.py @@ -3,13 +3,6 @@ from rpython.translator.platform import posix import os -# -# Although Intel 32bit is supported since Apple Mac OS X 10.4, (and PPC since, ever) -# the @rpath handling used in Darwin._args_for_shared is only availabe -# since 10.5, so we use that as minimum requirement. Bumped to 10.7 -# to allow the use of thread-local in __thread in C. -# -DARWIN_VERSION_MIN = '-mmacosx-version-min=10.7' class Darwin(posix.BasePosix): name = "darwin" @@ -17,10 +10,9 @@ class Darwin(posix.BasePosix): standalone_only = ('-mdynamic-no-pic',) shared_only = () - link_flags = (DARWIN_VERSION_MIN,) + link_flags = () cflags = ('-O3', - '-fomit-frame-pointer', - DARWIN_VERSION_MIN,) + '-fomit-frame-pointer') so_ext = 'dylib' DEFAULT_CC = 'clang' @@ -101,6 +93,15 @@ class Darwin(posix.BasePosix): def gen_makefile(self, cfiles, eci, exe_name=None, path=None, shared=False, headers_to_precompile=[], no_precompile_cfiles = [], profopt=False, config=None): + if getattr(config.translation, 'macosx_deployment_target', None): + macosx_version_min = ( + '-mmacosx-version-min=' + + config.translation.macosx_deployment_target + ) + + self.cflags += (macosx_version_min,) + self.link_flags += (macosx_version_min,) + # ensure frameworks are passed in the Makefile fs = self._frameworks(eci.frameworks) extra_libs = self.extra_libs diff --git a/rpython/translator/tool/cbuild.py b/rpython/translator/tool/cbuild.py index 0225f2f948d1082478a98ac8a90e5793ae07b55b..e7efcf91c7f8478c16337ce2119d113fded66b9a 100644 --- a/rpython/translator/tool/cbuild.py +++ b/rpython/translator/tool/cbuild.py @@ -95,6 +95,25 @@ class ExternalCompilationInfo(object): self.use_cpp_linker = use_cpp_linker self._platform = platform + # special handling of Mac OS X target versions + if self.platform.name.startswith('darwin'): + from rpython.config import translationoption + + config = translationoption.get_translation_config() + + if config is not None: + # we're running during a translation + deployment_target = getattr(config, 'macosx_deployment_target', None) + else: + # we're running in a nested environment, such as when + # running tests; in this case, default to the current + # OS for maximum coverage + deployment_target = os.getenv('MACOSX_DEPLOYMENT_TARGET') + + if deployment_target: + self.compile_extra += ('-mmacosx-version-min=' + deployment_target,) + self.link_extra += ('-mmacosx-version-min=' + deployment_target,) + @property def platform(self): if self._platform is None: