Compilation Guide
Overviewโ
This guide describes the tos.py build pipeline: what runs after you configure a project, how Python in TuyaOpen/tools/cli_command/ drives CMake/Ninja, and where artifacts land. It stays close to the implementation order in cli_build.py.
For changing configuration (choice, menu, app_default.config), use Kconfig and project configuration. For how the SDK CMake graph ties to Kconfig (libtuyaos.a, components, app target), use CMake, Kconfig, and the component model. For CLI usage and screenshots, use tos.py tool guide.
Build pipeline (high level)โ
tos.py build
โ
โโโ Environment check (submodules)
โโโ Configuration data (.build/cache/using.config)
โโโ Platform download (from platform_config.yaml)
โโโ Platform hooks (prepare / build_setup scripts)
โโโ CMake configure (Ninja generator, project .build/)
โโโ Ninja build (e.g. ninja example)
โโโ Output validation (bin under .build/bin/)
1. Configuration phase (cli_config.py)โ
When you run tos.py config choice, tos.py config menu, or equivalent, the config flow (implemented in TuyaOpen/tools/cli_command/cli_config.py):
- Writes
app_default.configin the project (preset replace or menu save). - Merges Kconfig from the project,
TuyaOpen/src, andTuyaOpen/boards, and writes generated files under<project>/.build/cache/(including a catalog of Kconfig inputs and a resolvedusing.configused by the build).
User-facing steps and recovery: Kconfig and project configuration.
2. Build phase (cli_build.py)โ
Implementation reference: TuyaOpen/tools/cli_command/cli_build.py. Below matches the typical order of operations (names may vary slightly by release).
2.1 Environment checkโ
Ensures SDK submodules are present. Equivalent:
git submodule update --init
2.2 Configuration initializationโ
Ensures <project>/.build/cache/using.config reflects the current Kconfig resolution. Key symbols used downstream include:
CONFIG_PROJECT_NAMEโ project nameCONFIG_PLATFORM_CHOICEโ platformCONFIG_CHIP_CHOICEโ chipCONFIG_BOARD_CHOICEโ boardCONFIG_FRAMEWORK_CHOICEโ framework
2.3 Platform downloadโ
Uses TuyaOpen/platform/platform_config.yaml (and git metadata) to clone or update the selected platform repository under TuyaOpen/platform/<platform_name>/ at the pinned revision.
git clone <repository_url> <tuyaopen_root>/platform/<platform_name>
cd <tuyaopen_root>/platform/<platform_name>
git checkout <commit_hash>
2.4 Platform hooks (platform_prepare / build_setup)โ
If present, the platform tree may run platform_prepare.py and/or build_setup.py (toolchain fetch, extra config, and similar). Only one is strictly necessary; historically both may run. Typical invocations:
python <tuyaopen_root>/platform/<platform_name>/platform_prepare.py $CHIP
python <tuyaopen_root>/platform/<platform_name>/build_setup.py $PROJ_NAME $PLATFORM $FRAMEWORK $CHIP
2.5 CMake and Ninjaโ
CMake is configured under <project>/.build/ with Ninja as the generator, passing project root, platform, board, chip, and framework as CMake variables. Conceptually:
mkdir -p <project_root>/.build
cd <project_root>/.build
cmake -G Ninja $CMAKE_VERBOSE $OPEN_SDK_ROOT \
-DTOS_PROJECT_NAME=$PROJ \
-DTOS_PROJECT_ROOT=$PROJECT_ROOT \
-DTOS_PROJECT_PLATFORM=$PROJECT_PLATFORM \
-DTOS_FRAMEWORK=$PROJECT_FRAMEWORK \
-DTOS_PROJECT_CHIP=$PROJECT_CHIP \
-DTOS_PROJECT_BOARD=$PROJECT_BOARD
ninja example
CMake layout (toolchain includes, src/ components, board BSP, app CMakeLists.txt, optional build_example.py): CMake, Kconfig, and the component model.
2.6 Output validationโ
The build checks that expected binaries exist under .build/bin/ (see check_bin_file in cli_build.py).
Project and SDK layout (build-relevant)โ
TuyaOpen/ # SDK root (OPEN_SDK_ROOT in CMake)
โโโ tos.py
โโโ tools/cli_command/ # cli_build.py, cli_config.py, โฆ
โโโ platform/ # Downloaded platform trees
โโโ src/ # SDK components (CMake per module)
โโโ boards/ # Board BSP
โโโ โฆ
<project>/ # App or example (cwd for tos.py)
โโโ CMakeLists.txt
โโโ app_default.config
โโโ Kconfig
โโโ .build/
โโโ bin/ # Firmware output
โโโ lib/
โโโ cache/ # Generated Kconfig / config cache
โโโ build/build_param # Build metadata (when present)
Compilation outputโ
After a successful build:
- Binary:
.build/bin/{app_name}_QIO_{version}.bin(exact pattern may vary by platform). - Libraries:
.build/lib/ - Parameters:
.build/build/build_param(when generated)
Example log excerpt:
====================[ BUILD SUCCESS ]===================
Target : example_QIO_1.0.0.bin
Output : /path/to/project/.build/bin
Platform : T2
Chip : T2-U
Board : t2_evb
Framework : base
========================================================
Summaryโ
- Configure with
tos.py configโ details in Kconfig and project configuration. - Build with
tos.py buildโ environment, platform, CMake/Ninja, validation as above. - CMake structure โ CMake, Kconfig, and the component model.