Skip to content

Commit

Permalink
Merge pull request #94109 from akien-mga/scons-linker-optflags
Browse files Browse the repository at this point in the history
SCons: Pass optimization flags to the linker too, needed by Emscripten
  • Loading branch information
akien-mga committed Jul 10, 2024
2 parents 73422df + 7d70862 commit 543f694
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -700,12 +700,11 @@ if env.msvc:
else:
env.Append(LINKFLAGS=["/DEBUG:NONE"])

if env["optimize"] == "speed":
if env["optimize"].startswith("speed"):
env.Append(CCFLAGS=["/O2"])
env.Append(LINKFLAGS=["/OPT:REF"])
elif env["optimize"] == "speed_trace":
env.Append(CCFLAGS=["/O2"])
env.Append(LINKFLAGS=["/OPT:REF", "/OPT:NOICF"])
if env["optimize"] == "speed_trace":
env.Append(LINKFLAGS=["/OPT:NOICF"])
elif env["optimize"] == "size":
env.Append(CCFLAGS=["/O1"])
env.Append(LINKFLAGS=["/OPT:REF"])
Expand Down Expand Up @@ -737,17 +736,25 @@ else:
else:
env.Append(LINKFLAGS=["-s"])

# Linker needs optimization flags too, at least for Emscripten.
# For other toolchains, this _may_ be useful for LTO too to disambiguate.

if env["optimize"] == "speed":
env.Append(CCFLAGS=["-O3"])
env.Append(LINKFLAGS=["-O3"])
# `-O2` is friendlier to debuggers than `-O3`, leading to better crash backtraces.
elif env["optimize"] == "speed_trace":
env.Append(CCFLAGS=["-O2"])
env.Append(LINKFLAGS=["-O2"])
elif env["optimize"] == "size":
env.Append(CCFLAGS=["-Os"])
env.Append(LINKFLAGS=["-Os"])
elif env["optimize"] == "debug":
env.Append(CCFLAGS=["-Og"])
env.Append(LINKFLAGS=["-Og"])
elif env["optimize"] == "none":
env.Append(CCFLAGS=["-O0"])
env.Append(LINKFLAGS=["-O0"])

# Needs to happen after configure to handle "auto".
if env["lto"] != "none":
Expand Down

0 comments on commit 543f694

Please sign in to comment.