From 6b46ebef012bc754c766d8151efbd7555bb86c88 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 20 Sep 2023 23:18:32 +0300 Subject: [PATCH] [macOS, 3.x] Workaround Xcode 15 linker bug. (cherry picked from commit fad3fced8fd848b26e8a1faf9d48efc06e18f674) --- methods.py | 11 +++++++++++ platform/osx/detect.py | 9 ++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/methods.py b/methods.py index a5a4a2fdda5..556795160de 100644 --- a/methods.py +++ b/methods.py @@ -944,6 +944,17 @@ def get_compiler_version(env): return None +def is_vanilla_clang(env): + if not using_clang(env): + return False + try: + version = decode_utf8(subprocess.check_output([env.subst(env["CXX"]), "--version"]).strip()) + except (subprocess.CalledProcessError, OSError): + print("Couldn't parse CXX environment variable to infer compiler version.") + return False + return not version.startswith("Apple") + + def using_gcc(env): return "gcc" in os.path.basename(env["CC"]) diff --git a/platform/osx/detect.py b/platform/osx/detect.py index a553e23e69c..b24a32c9ba0 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -1,6 +1,6 @@ import os import sys -from methods import detect_darwin_sdk_path +from methods import detect_darwin_sdk_path, get_compiler_version, is_vanilla_clang def is_active(): @@ -86,6 +86,13 @@ def configure(env): env.Append(CCFLAGS=["-arch", "x86_64", "-mmacosx-version-min=10.12"]) env.Append(LINKFLAGS=["-arch", "x86_64", "-mmacosx-version-min=10.12"]) + cc_version = get_compiler_version(env) or [-1, -1] + vanilla = is_vanilla_clang(env) + + # Workaround for Xcode 15 linker bug. + if not vanilla and cc_version[0] == 15 and cc_version[1] == 0: + env.Prepend(LINKFLAGS=["-ld_classic"]) + if not "osxcross" in env: # regular native build if env["macports_clang"] != "no": mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local")