Skip to content

Commit

Permalink
Adjust clang version checking to account for other non-vanilla clangs
Browse files Browse the repository at this point in the history
We can no longer make the assumption that all non-vanilla clang versions
are Apple's clang or that all other non vanilla clangs will work with
the given arguments. There are times where additional tools might use non vanilla clang
and the presumed arguments here will break compilation on those
platforms.

We might want to consider adding tooling-specific optimazation functions
long term to fetch desired optimizations on a platform basis.
  • Loading branch information
Eoin-ONeill-Yokai committed Feb 9, 2024
1 parent 36847f6 commit 368f671
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tools/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import subprocess
import sys
from SCons.Script import ARGUMENTS
from SCons.Tool import Tool
from SCons.Variables import *
from SCons.Variables.BoolVariable import _text2bool

Expand All @@ -24,15 +25,15 @@ def using_clang(env):
return "clang" in os.path.basename(env["CC"])


def is_vanilla_clang(env):
def is_clang_type(env, family_string):
if not using_clang(env):
return False
try:
version = subprocess.check_output([env.subst(env["CXX"]), "--version"]).strip().decode("utf-8")
except (subprocess.CalledProcessError, OSError):
print("Couldn't parse CXX environment variable to infer compiler version.")
return False
return not version.startswith("Apple")
return version.startswith(family_string)


# Main tool definition
Expand Down Expand Up @@ -125,10 +126,10 @@ def generate(env):
else:
env.Append(CCFLAGS=["-g2"])
else:
if using_clang(env) and not is_vanilla_clang(env):
if using_clang(env) and is_clang_type(env, "Apple"):
# Apple Clang, its linker doesn't like -s.
env.Append(LINKFLAGS=["-Wl,-S", "-Wl,-x", "-Wl,-dead_strip"])
else:
elif using_clang(env) and is_clang_type(env, "clang"):
env.Append(LINKFLAGS=["-s"])

if env["optimize"] == "speed":
Expand Down

0 comments on commit 368f671

Please sign in to comment.