Skip to main content

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):

  1. Writes app_default.config in the project (preset replace or menu save).
  2. Merges Kconfig from the project, TuyaOpen/src, and TuyaOpen/boards, and writes generated files under <project>/.build/cache/ (including a catalog of Kconfig inputs and a resolved using.config used 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 name
  • CONFIG_PLATFORM_CHOICE โ€” platform
  • CONFIG_CHIP_CHOICE โ€” chip
  • CONFIG_BOARD_CHOICE โ€” board
  • CONFIG_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โ€‹