Skip to content

Commit

Permalink
Move LTO code from SDK logic to general build logic, supports all pro…
Browse files Browse the repository at this point in the history
…jects
  • Loading branch information
maxgerhardt committed Nov 15, 2024
1 parent 18e295e commit cb6636f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 14 additions & 1 deletion builder/frameworks/_bare.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

machine_arch = str(board.get("build.march"))

def get_flag_value(flag_name:str, default_val:bool):
flag_val = board.get("build.%s" % flag_name, default_val)
flag_val = str(flag_val).lower() in ("1", "yes", "true")
return flag_val

lto_flag = ""
if get_flag_value("use_lto", False):
lto_flag = "-flto"
env.Append(LINKFLAGS=["-flto"], CCFLAGS=["-flto"])

env.Append(
ASFLAGS=[
"-march=%s" % machine_arch,
Expand Down Expand Up @@ -48,6 +58,7 @@
"-Wunused",
"-Wuninitialized",
"-Wno-comment",
lto_flag,
"-march=%s" % machine_arch,
"-mabi=%s" % board.get("build.mabi"),
],
Expand All @@ -68,8 +79,10 @@
"-nostartfiles",
'-Wl,-Map="%s"' % os.path.join(
"$BUILD_DIR", os.path.basename(env.subst("${PROJECT_DIR}.map"))),
lto_flag,
]
)
# copy general C/C++ flags to assembler with cpp flags too, except
# would-be-duplicate last two elements
env["ASPPFLAGS"].extend(env["CCFLAGS"][:-2])
env["ASPPFLAGS"].extend(env["CCFLAGS"][:-2])

3 changes: 0 additions & 3 deletions builder/frameworks/noneos_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ def get_startup_filename(board):
env.Exit(-1)
return startup_file

if get_flag_value("use_lto", False):
env.Append(LINKFLAGS=["-flto"], CCFLAGS=["-flto"])

env.Append(
CPPPATH=[
join(FRAMEWORK_DIR, "Core", chip_series),
Expand Down

0 comments on commit cb6636f

Please sign in to comment.