Skip to content

Commit 62b8121

Browse files
committed
Replace small C lib with std C lib if not supported for a given target
1 parent 03dab7f commit 62b8121

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

tools/build_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from .libraries import Library
4949
from .toolchains import TOOLCHAIN_CLASSES, TOOLCHAIN_PATHS
5050
from .toolchains.arm import UARM_TOOLCHAIN_WARNING
51+
from .toolchains.mbed_toolchain import is_std_c_lib_supported_instead_small_c_lib
5152
from .config import Config
5253

5354
RELEASE_VERSIONS = ['2', '5']
@@ -205,6 +206,7 @@ def get_toolchain_name(target, toolchain_name):
205206

206207
return toolchain_name
207208

209+
208210
def find_valid_toolchain(target, toolchain):
209211
"""Given a target and toolchain, get the names for the appropriate
210212
toolchain to use. The environment is also checked to see if the corresponding
@@ -250,6 +252,15 @@ def find_valid_toolchain(target, toolchain):
250252
and "uARM" in {toolchain_name, target.default_toolchain}
251253
):
252254
end_warnings.append(UARM_TOOLCHAIN_WARNING)
255+
256+
if is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
257+
warning = (
258+
"Warning: We noticed that you are using target.c_lib set to small.\n"
259+
"As the {} target does not support a small C library for the {} toolchain,\n"
260+
"we are using the standard C library instead. "
261+
).format(target.name, toolchain)
262+
end_warnings.append(warning)
263+
253264
return toolchain_name, internal_tc_name, end_warnings
254265
else:
255266
if last_error:

tools/toolchains/arm.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
from shutil import rmtree
2727
from distutils.version import LooseVersion
2828

29-
from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS
29+
from tools.toolchains.mbed_toolchain import (
30+
mbedToolchain, TOOLCHAIN_PATHS, is_std_c_lib_supported_instead_small_c_lib
31+
)
3032
from tools.utils import mkdir, NotSupportedException, run_cmd
3133
from tools.resources import FileRef
3234

@@ -70,7 +72,13 @@ def __init__(self, target, notify=None, macros=None,
7072
raise NotSupportedException(
7173
"this compiler does not support the core %s" % target.core)
7274

73-
self.check_c_lib_supported(target, "arm")
75+
toolchain = "arm"
76+
77+
if is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
78+
# Replace small C lib with std if there is no small C lib support
79+
target.c_lib = "std"
80+
81+
self.check_c_lib_supported(target, toolchain)
7482

7583
if (
7684
getattr(target, "default_toolchain", "ARM") == "uARM"
@@ -562,7 +570,13 @@ def __init__(self, target, *args, **kwargs):
562570
"ARM/ARMC6 compiler support is required for ARMC6 build"
563571
)
564572

565-
self.check_c_lib_supported(target, "arm")
573+
toolchain = "arm"
574+
575+
if is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
576+
# Replace small C lib with std if there is no small C lib support
577+
target.c_lib = "std"
578+
579+
self.check_c_lib_supported(target, toolchain)
566580

567581
if (
568582
getattr(target, "default_toolchain", "ARMC6") == "uARM"

tools/toolchains/gcc.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
from distutils.spawn import find_executable
2323
from distutils.version import LooseVersion
2424

25-
from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS
25+
from tools.toolchains.mbed_toolchain import (
26+
mbedToolchain, TOOLCHAIN_PATHS, is_std_c_lib_supported_instead_small_c_lib
27+
)
2628
from tools.utils import run_cmd
2729

2830

@@ -54,7 +56,13 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
5456
# Add flags for current size setting
5557
c_lib = "std"
5658
if hasattr(target, "c_lib"):
57-
self.check_c_lib_supported(target, "gcc_arm")
59+
toolchain = "gcc_arm"
60+
61+
if is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
62+
# Replace small C lib with std if there is no small C lib support
63+
target.c_lib = "std"
64+
65+
self.check_c_lib_supported(target, toolchain)
5866
c_lib = target.c_lib
5967
elif hasattr(target, "default_build"):
6068
c_lib = target.default_build

tools/toolchains/iar.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
from os.path import join, splitext, exists
2121
from distutils.version import LooseVersion
2222

23-
from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS
23+
from tools.toolchains.mbed_toolchain import (
24+
mbedToolchain, TOOLCHAIN_PATHS, is_std_c_lib_supported_instead_small_c_lib
25+
)
2426
from tools.utils import run_cmd
2527

2628
class IAR(mbedToolchain):
@@ -54,6 +56,12 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
5456
build_profile=build_profile
5557
)
5658

59+
toolchain = "iar"
60+
61+
if is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
62+
# Replace small C lib with std if there is no small C lib support
63+
target.c_lib = "std"
64+
5765
self.check_c_lib_supported(target, "iar")
5866

5967
if target.is_TrustZone_secure_target:

tools/toolchains/mbed_toolchain.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,3 +1393,20 @@ def report(self):
13931393
to_ret['linker'] = {'flags': copy(self.flags['ld'])}
13941394
to_ret.update(self.config.report)
13951395
return to_ret
1396+
1397+
def is_std_c_lib_supported_instead_small_c_lib(target, toolchain):
1398+
"""
1399+
Check if the standard C lib should be used instead of the small C lib.
1400+
Return True if the target does not support a small C lib for a given
1401+
toolchain but supports the standard C library instead.
1402+
"""
1403+
if (
1404+
hasattr(target, "c_lib")
1405+
and target.c_lib.lower() == "small"
1406+
and hasattr(target, "supported_c_libs")
1407+
and toolchain.lower() in target.supported_c_libs
1408+
):
1409+
return (
1410+
"small" not in target.supported_c_libs[toolchain.lower()]
1411+
and "std" in target.supported_c_libs[toolchain.lower()]
1412+
)

0 commit comments

Comments
 (0)