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.
This commit is contained in:
Rémi Verschelde 2020-02-23 17:43:15 +01:00
parent a920f9727a
commit 214d852ffd
2 changed files with 34 additions and 2 deletions

View File

@ -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...

View File

@ -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('.')