Skip to content

Commit

Permalink
Respect linking order of libraries for PlatformIO (#8263)
Browse files Browse the repository at this point in the history
* Respect linking order of libraries

Now has the same order as the Arduino IDE does with its platform.txt

* Remove double-referenced libs

* Change implementation style

Instead of injecting at magic indices, which might break when some other extra-scripts inject other libraries, let's create the LIBS array at the bottom in easy to understand and correct order.
  • Loading branch information
maxgerhardt committed Sep 1, 2021
1 parent 9f30f24 commit f7951e6
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions tools/platformio-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,8 @@ def scons_patched_match_splitext(path, suffixes=None):
join(FRAMEWORK_DIR, "tools", "sdk", "ld")
],

# A list of one or more libraries that will be linked with any executable programs created by this environment
LIBS=[
"hal", "phy", "pp", "net80211", "wpa", "crypto", "main",
"wps", "bearssl", "espnow", "smartconfig", "airkiss", "wpa2",
"m", "c", "gcc"
],
# LIBS is set at the bottom of the builder script
# where we know about all system libraries to be included

LIBSOURCE_DIRS=[
join(FRAMEWORK_DIR, "libraries")
Expand Down Expand Up @@ -218,43 +214,44 @@ def scons_patched_match_splitext(path, suffixes=None):
#
# lwIP
#
lwip_lib = None
if "PIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_LOW_MEMORY" in flatten_cppdefines:
env.Append(
CPPDEFINES=[("TCP_MSS", 536), ("LWIP_FEATURES", 1), ("LWIP_IPV6", 1)],
CPPPATH=[join(FRAMEWORK_DIR, "tools", "sdk", "lwip2", "include")],
LIBS=["lwip6-536-feat"]
)
lwip_lib = "lwip6-536-feat"
elif "PIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_HIGHER_BANDWIDTH" in flatten_cppdefines:
env.Append(
CPPDEFINES=[("TCP_MSS", 1460), ("LWIP_FEATURES", 1), ("LWIP_IPV6", 1)],
CPPPATH=[join(FRAMEWORK_DIR, "tools", "sdk", "lwip2", "include")],
LIBS=["lwip6-1460-feat"]
)
lwip_lib = "lwip6-1460-feat"
elif "PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH" in flatten_cppdefines:
env.Append(
CPPDEFINES=[("TCP_MSS", 1460), ("LWIP_FEATURES", 1), ("LWIP_IPV6", 0)],
CPPPATH=[join(FRAMEWORK_DIR, "tools", "sdk", "lwip2", "include")],
LIBS=["lwip2-1460-feat"]
)
lwip_lib = "lwip2-1460-feat"
elif "PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY_LOW_FLASH" in flatten_cppdefines:
env.Append(
CPPDEFINES=[("TCP_MSS", 536), ("LWIP_FEATURES", 0), ("LWIP_IPV6", 0)],
CPPPATH=[join(FRAMEWORK_DIR, "tools", "sdk", "lwip2", "include")],
LIBS=["lwip2-536"]
)
lwip_lib = "lwip2-536"
elif "PIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH" in flatten_cppdefines:
env.Append(
CPPDEFINES=[("TCP_MSS", 1460), ("LWIP_FEATURES", 0), ("LWIP_IPV6", 0)],
CPPPATH=[join(FRAMEWORK_DIR, "tools", "sdk", "lwip2", "include")],
LIBS=["lwip2-1460"]
)
lwip_lib = "lwip2-1460"
# PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY (default)
else:
env.Append(
CPPDEFINES=[("TCP_MSS", 536), ("LWIP_FEATURES", 1), ("LWIP_IPV6", 0)],
CPPPATH=[join(FRAMEWORK_DIR, "tools", "sdk", "lwip2", "include")],
LIBS=["lwip2-536-feat"]
)
lwip_lib = "lwip2-536-feat"

#
# Waveform
Expand All @@ -266,17 +263,17 @@ def scons_patched_match_splitext(path, suffixes=None):
#
# Exceptions
#
stdcpp_lib = None
if "PIO_FRAMEWORK_ARDUINO_ENABLE_EXCEPTIONS" in flatten_cppdefines:
env.Append(
CXXFLAGS=["-fexceptions"],
LIBS=["stdc++-exc"]
)
stdcpp_lib = "stdc++-exc"
else:
env.Append(
CXXFLAGS=["-fno-exceptions"],
LIBS=["stdc++"]
)

stdcpp_lib = "stdc++"
#
# VTables
#
Expand Down Expand Up @@ -355,6 +352,15 @@ def scons_patched_match_splitext(path, suffixes=None):
assert mmu_flags
env.Append(CPPDEFINES=mmu_flags)

# A list of one or more libraries that will be linked with any executable programs created by this environment
# We do this at this point so that we can put the libraries in their correct order more easily
env.Append(
LIBS=[
"hal", "phy", "pp", "net80211", lwip_lib, "wpa", "crypto", "main",
"wps", "bearssl", "espnow", "smartconfig", "airkiss", "wpa2",
stdcpp_lib, "m", "c", "gcc"
]
)

# Build the eagle.app.v6.common.ld linker file
app_ld = env.Command(
Expand Down

0 comments on commit f7951e6

Please sign in to comment.