From 42722847f4a6cdfd624a2ac2f026cb800f1ca7b6 Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Tue, 22 Sep 2020 14:17:31 +0200 Subject: [PATCH 1/4] config: allow filling in translation options, etc., with environment variable --HG-- branch : macosx-deployment-target-2.7 --- rpython/config/config.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/rpython/config/config.py b/rpython/config/config.py index 049ca40711..acc04f0191 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): -- GitLab From 4d0f1e553ad4607c316a8871c03f44636298a185 Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Sun, 27 Sep 2020 11:13:22 +0200 Subject: [PATCH 2/4] darwin: use and save MACOSX_DEPLOYMENT_TARGET from environment, if set --HG-- branch : macosx-deployment-target-2.7 --- lib-python/2.7/distutils/sysconfig_pypy.py | 6 ++++- rpython/config/translationoption.py | 27 +++++++++++++++++++--- rpython/translator/platform/darwin.py | 21 +++++++++-------- rpython/translator/tool/cbuild.py | 19 +++++++++++++++ 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/lib-python/2.7/distutils/sysconfig_pypy.py b/lib-python/2.7/distutils/sysconfig_pypy.py index ec9f5a31db..c40d7d86b6 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/rpython/config/translationoption.py b/rpython/config/translationoption.py index 1231d928e5..2d2e834b86 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/translator/platform/darwin.py b/rpython/translator/platform/darwin.py index 2df648f157..971d8c4631 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,11 +10,10 @@ class Darwin(posix.BasePosix): standalone_only = ('-mdynamic-no-pic',) shared_only = () - link_flags = (DARWIN_VERSION_MIN,) + link_flags = () cflags = ('-O3', '-fomit-frame-pointer', - '-fno-stack-check', - DARWIN_VERSION_MIN,) + '-fno-stack-check') so_ext = 'dylib' DEFAULT_CC = 'clang' @@ -102,6 +94,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 0225f2f948..e7efcf91c7 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: -- GitLab From 57d5a196dbffc63f51aa68fba18e0089d190ae81 Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Wed, 23 Sep 2020 19:18:29 +0200 Subject: [PATCH 3/4] rtime: now that MACOSX_DEPLOYMENT_TARGET works, use proper check for clock_gettime() --HG-- branch : macosx-deployment-target-2.7 --- rpython/rlib/rtime.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/rpython/rlib/rtime.py b/rpython/rlib/rtime.py index 7ddaf365a5..789f43ce8e 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() -- GitLab From 43ab87d3efb68d84658af5f4430d136a09ae1f49 Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Thu, 1 Oct 2020 11:23:32 +0200 Subject: [PATCH 4/4] set MACOSX_DEPLOYMENT_TARGET to whatever detected during translation disutils yields an error if you set it to something other than that configured, and I tested that error --HG-- branch : macosx-deployment-target-2.7 --- lib-python/2.7/_osx_support.py | 24 ++++++++++++++++++++++++ lib-python/2.7/sysconfig.py | 2 -- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib-python/2.7/_osx_support.py b/lib-python/2.7/_osx_support.py index d2aaae7986..954e0db95b 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/sysconfig.py b/lib-python/2.7/sysconfig.py index 724b24e9e7..ca860cd6e3 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: -- GitLab