Skip to content

Commit f4d874d

Browse files
committed
Enable build with IAR when c_lib is set to small
1 parent 03dab7f commit f4d874d

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

tools/build_api.py

Lines changed: 8 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.iar import IAR_SMALL_LIB_WARNING
5152
from .config import Config
5253

5354
RELEASE_VERSIONS = ['2', '5']
@@ -250,6 +251,13 @@ def find_valid_toolchain(target, toolchain):
250251
and "uARM" in {toolchain_name, target.default_toolchain}
251252
):
252253
end_warnings.append(UARM_TOOLCHAIN_WARNING)
254+
255+
if (
256+
toolchain_name == "IAR"
257+
and target.c_lib.lower() == "small"
258+
):
259+
end_warnings.append(IAR_SMALL_LIB_WARNING)
260+
253261
return toolchain_name, internal_tc_name, end_warnings
254262
else:
255263
if last_error:

tools/test/toolchains/test_toolchains.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,16 @@ def test_iar_c_lib_std_exception(self):
209209
with self.assertRaisesRegexp(NotSupportedException, UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib)):
210210
IAR(mock_target)
211211

212-
def test_iar_c_lib_small_exception(self):
213-
"""Test that an exception is raised if the small C library is not supported for a target on the IAR toolchain."""
212+
def test_iar_c_lib_small(self):
213+
"""Test that no exception is raised if the small C library is used with the IAR toolchain."""
214214
mock_target = mock.MagicMock()
215215
mock_target.core = "Cortex-M4"
216216
mock_target.c_lib = "small"
217217
del mock_target.default_lib
218218
mock_target.supported_c_libs = {"iar": ["std"]}
219219
mock_target.supported_toolchains = ["IAR"]
220-
with self.assertRaisesRegexp(NotSupportedException, UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib)):
220+
mock_target.is_TrustZone_secure_target = False
221+
try:
221222
IAR(mock_target)
223+
except NotSupportedException:
224+
self.fail(UNSUPPORTED_C_LIB_EXCEPTION_STRING.format(mock_target.c_lib))

tools/toolchains/iar.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
from tools.toolchains.mbed_toolchain import mbedToolchain, TOOLCHAIN_PATHS
2424
from tools.utils import run_cmd
2525

26+
27+
IAR_SMALL_LIB_WARNING = (
28+
"Warning: We noticed that you are using IAR toolchain with target.c_lib set to small. "
29+
"As there is no small C library for the IAR toolchain, we are using the standard C library instead. "
30+
)
31+
2632
class IAR(mbedToolchain):
2733
OFFICIALLY_SUPPORTED = True
2834
LIBRARY_EXT = '.a'
@@ -54,7 +60,10 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
5460
build_profile=build_profile
5561
)
5662

57-
self.check_c_lib_supported(target, "iar")
63+
# Build with the standard C lib if c_lib is set to small as there
64+
# is no small lib for the IAR toolchain
65+
if target.c_lib.lower() != "small":
66+
self.check_c_lib_supported(target, "iar")
5867

5968
if target.is_TrustZone_secure_target:
6069
# Enable compiler security extensions

0 commit comments

Comments
 (0)