From 214d852ffd864b75564643b49b2c960d469be3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 23 Feb 2020 17:43:15 +0100 Subject: [PATCH] SCons: Add GCC/Clang minimum version check Prevent using GCC 8 as it does not properly support C++17's guaranteed copy elision which we now need. (Upstream bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86521) Follow-up to #36457 and #36436. --- SConstruct | 30 ++++++++++++++++++++++++++++++ methods.py | 6 ++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/SConstruct b/SConstruct index e20499a7560..08a87dbe6c7 100644 --- a/SConstruct +++ b/SConstruct @@ -332,6 +332,36 @@ if selected_platform in platform_list: # We apply it to CCFLAGS (both C and C++ code) in case it impacts C features. env.Prepend(CCFLAGS=['/std:c++17', '/permissive-']) + # Enforce our minimal compiler version requirements + version = methods.get_compiler_version(env) + major = int(version[0]) if version is not None else -1 + if methods.using_gcc(env): + # GCC 8 has a regression in the support of guaranteed copy elision + # which causes a build failure: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86521 + if major == 8: + print("Detected GCC version 8, which is not supported due to a regression " + "in its C++17 guaranteed copy elision support. Use a newer GCC " + "version, or Clang 6 or later by passing \"use_llvm=yes\" to the " + "SCons command line.") + sys.exit(255) + elif major < 7: + print("Detected GCC version older than 7, which does not fully support " + "C++17. Supported versions are GCC 7, 9 and later. Use a newer GCC " + "version, or Clang 6 or later by passing \"use_llvm=yes\" to the " + "SCons command line.") + sys.exit(255) + elif methods.using_clang(env): + # Apple LLVM versions differ from upstream LLVM version \o/, compare + # in https://en.wikipedia.org/wiki/Xcode#Toolchain_versions + if (env["platform"] == "osx" or env["platform"] == "iphone") and major < 10: + print("Detected Apple Clang version older than 10, which does not fully " + "support C++17. Supported versions are Apple Clang 10 and later.") + sys.exit(255) + elif major < 6: + print("Detected Clang version older than 6, which does not fully support " + "C++17. Supported versions are Clang 6 and later.") + sys.exit(255) + # Configure compiler warnings if env.msvc: # Truncations, narrowing conversions, signed/unsigned comparisons... diff --git a/methods.py b/methods.py index f6c9e939c6a..18e1c0bba77 100644 --- a/methods.py +++ b/methods.py @@ -550,11 +550,13 @@ def detect_darwin_sdk_path(platform, env): raise def get_compiler_version(env): - # Not using this method on clang because it returns 4.2.1 # https://reviews.llvm.org/D56803 if using_gcc(env): version = decode_utf8(subprocess.check_output([env['CXX'], '-dumpversion']).strip()) - else: + elif using_clang(env): + # Not using -dumpversion as it used to return 4.2.1: https://reviews.llvm.org/D56803 version = decode_utf8(subprocess.check_output([env['CXX'], '--version']).strip()) + else: # TODO: Implement for MSVC + return None match = re.search('[0-9][0-9.]*', version) if match is not None: return match.group().split('.')