mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 11:26:39 +00:00
[libretiny] Build LN882x with 1-byte enums to match the SDK's WiFi library (#20173)
This commit is contained in:
@@ -526,6 +526,10 @@ async def component_to_code(config):
|
||||
# RAM-executable output section and prints a post-link placement summary.
|
||||
if FAMILY_COMPONENT[config[CONF_FAMILY]] != COMPONENT_BK72XX:
|
||||
cg.add_platformio_option("extra_scripts", ["pre:patch_linker.py"])
|
||||
# Match the 1-byte enums of the LN882H SDK's prebuilt WiFi library.
|
||||
if FAMILY_COMPONENT[config[CONF_FAMILY]] == COMPONENT_LN882X:
|
||||
cg.add_build_unflag("-fno-short-enums")
|
||||
cg.add_build_flag("-fshort-enums")
|
||||
# dummy version code
|
||||
cg.add_define("USE_ARDUINO_VERSION_CODE", cg.RawExpression("VERSION_CODE(0, 0, 0)"))
|
||||
# decrease web server stack size (16k words -> 4k words)
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
// libretiny component's API.
|
||||
namespace esphome::libretiny {} // namespace esphome::libretiny
|
||||
|
||||
#if defined(USE_LN882X) && !defined(CLANG_TIDY) // clang-tidy runs without the PlatformIO flags
|
||||
// Fail the build if the -fshort-enums swap in __init__.py stops working.
|
||||
enum Ln882xEnumSizeCheck { LN882X_ENUM_SIZE_CHECK };
|
||||
static_assert(sizeof(Ln882xEnumSizeCheck) == 1, "LN882x must build with -fshort-enums to match the SDK");
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
|
||||
// yield(), delay(), micros(), millis(), millis_64(), delayMicroseconds(),
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
esphome:
|
||||
name: test
|
||||
|
||||
bk72xx:
|
||||
board: generic-bk7231n-qfn32-tuya
|
||||
@@ -0,0 +1,5 @@
|
||||
esphome:
|
||||
name: test
|
||||
|
||||
ln882x:
|
||||
board: generic-ln882h
|
||||
@@ -0,0 +1,27 @@
|
||||
"""LN882x builds with 1-byte enums to match the SDK's prebuilt libraries;
|
||||
the other LibreTiny families keep LibreTiny's own enum size."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
from esphome.core import CORE
|
||||
|
||||
|
||||
def test_ln882x_swaps_in_short_enums(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
generate_main(component_config_path("ln882x.yaml"))
|
||||
assert "-fno-short-enums" in CORE.build_unflags
|
||||
assert "-fshort-enums" in CORE.build_flags
|
||||
|
||||
|
||||
def test_bk72xx_keeps_libretiny_enums(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
generate_main(component_config_path("bk72xx.yaml"))
|
||||
assert "-fno-short-enums" not in CORE.build_unflags
|
||||
assert "-fshort-enums" not in CORE.build_flags
|
||||
Reference in New Issue
Block a user