Skip to content

[cmake][common] Adding optional support for --zcl argument in chip_zapgen() cmake function #40537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 20, 2025

Conversation

dinabenamar
Copy link
Contributor

@dinabenamar dinabenamar commented Aug 12, 2025

Summary

The aim of this PR is to introduce optional support for passing "--zcl" argument to the zapgen "generate.py" script, without impacting existing example behavior.

It supports three levels of configuration:
1- Default behavior : No "--zcl" argument is passed, preserving current behavior for all examples.
2- Global opt-in : If the "CHIP_ENABLE_ZCL_ARG" cmake variable is set to ON, the default ZCL path "${CHIP_ROOT}/src/app/zap-templates/zcl/zcl.json" is used.
3- Custom override : Examples can pass a specific "ZCL_PATH" via the "chip_configure_data_model()" API to use a custom "zcl.json".

Example of use to add a custom ZCL_PATH :

chip_configure_data_model(app
INCLUDE_SERVER
ZAP_FILE ${NXP_EXAMPLE_ZAP_DIR}/thermostat_matter_wifi.zap
ZCL_PATH ${CHIP_ROOT}/src/app/zap-templates/zcl/zcl-with-test-extensions.json
)

Context

This change helps address build issues in freestanding examples, where the "generate.py" (called in chip_zapgen) relies on relative paths embedded in the ".zap" files to locate the "zcl.json" file. These paths may be invalid if the ".zap" file is moved or used outside its original context. Explicitly passing the ZCL path ensures consistent and portable builds.

Testing

These changes were tested by building the following configurations :

Example of command used to build:

  • west build -d build_matter -b rdrw612bga examples/thermostat/nxp
  • west build -d build_matter -b rdrw612bga examples/all-clusters-app/nxp

…function

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
…ples to allow default ZCL path to be passed as --zcl argument with chip_zapgen

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces optional support for the --zcl argument in the chip_zapgen() cmake function, which is a valuable addition for handling builds in different environments. The implementation is well-structured, using a new CHIP_ENABLE_ZCL_ARG variable for global control and allowing per-target overrides. The changes in chip_codegen.cmake, app_common.cmake, and chip_data_model.cmake are logical and correctly implement the described feature.

I have one suggestion in build/chip/chip_codegen.cmake to simplify the logic for adding the --zcl argument, which should improve readability. Overall, this is a solid contribution.

Copy link

github-actions bot commented Aug 12, 2025

PR #40537: Size comparison from 0832b19 to 4c1814f

Full report (4 builds for cc32xx, nrfconnect, stm32)
platform target config section 0832b19 4c1814f change % change
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 550754 550754 0 0.0
RAM 205088 205088 0 0.0
lock CC3235SF_LAUNCHXL FLASH 583206 583206 0 0.0
RAM 205296 205296 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 910264 910264 0 0.0
RAM 152836 152836 0 0.0
stm32 light STM32WB5MM-DK FLASH 466588 466588 0 0.0
RAM 141344 141344 0 0.0

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
Copy link

github-actions bot commented Aug 12, 2025

PR #40537: Size comparison from 0832b19 to 21950a6

Full report (57 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, efr32, esp32, linux, nrfconnect, nxp, psoc6, qpg, stm32, telink, tizen)
platform target config section 0832b19 21950a6 change % change
bl602 lighting-app bl602+mfd+littlefs+rpc FLASH 1105032 1105032 0 0.0
RAM 178962 178962 0 0.0
bl702 lighting-app bl702+eth FLASH 657378 657378 0 0.0
RAM 134873 134873 0 0.0
bl702+wifi FLASH 835524 835524 0 0.0
RAM 124437 124437 0 0.0
bl706+mfd+rpc+littlefs FLASH 1067128 1067128 0 0.0
RAM 117293 117293 0 0.0
bl702l contact-sensor-app bl702l+mfd+littlefs FLASH 896566 896566 0 0.0
RAM 105604 105604 0 0.0
lighting-app bl702l+mfd+littlefs FLASH 980280 980280 0 0.0
RAM 109780 109780 0 0.0
cc13x4_26x4 lighting-app LP_EM_CC1354P10_6 FLASH 766944 766944 0 0.0
RAM 103336 103336 0 0.0
lock-ftd LP_EM_CC1354P10_6 FLASH 778532 778532 0 0.0
RAM 108496 108496 0 0.0
pump-app LP_EM_CC1354P10_6 FLASH 724032 724032 0 0.0
RAM 96900 96900 0 0.0
pump-controller-app LP_EM_CC1354P10_6 FLASH 708404 708404 0 0.0
RAM 97100 97100 0 0.0
cc32xx air-purifier CC3235SF_LAUNCHXL FLASH 550754 550754 0 0.0
RAM 205088 205088 0 0.0
lock CC3235SF_LAUNCHXL FLASH 583206 583206 0 0.0
RAM 205296 205296 0 0.0
efr32 lock-app BRD4187C FLASH 958344 958336 -8 -0.0
RAM 122612 122612 0 0.0
BRD4338a FLASH 752864 752856 -8 -0.0
RAM 251864 251864 0 0.0
window-app BRD4187C FLASH 1050748 1050740 -8 -0.0
RAM 118840 118840 0 0.0
esp32 all-clusters-app c3devkit DRAM 102304 102304 0 0.0
FLASH 1751296 1751296 0 0.0
IRAM 83862 83862 0 0.0
m5stack DRAM 121172 121172 0 0.0
FLASH 1699842 1699842 0 0.0
IRAM 117051 117051 0 0.0
linux air-purifier-app debug unknown 4864 4864 0 0.0
FLASH 2589260 2589260 0 0.0
RAM 116696 116696 0 0.0
all-clusters-app debug unknown 5688 5688 0 0.0
FLASH 5980010 5980010 0 0.0
RAM 534792 534792 0 0.0
all-clusters-minimal-app debug unknown 5536 5536 0 0.0
FLASH 5205756 5205756 0 0.0
RAM 228008 228008 0 0.0
bridge-app debug unknown 5568 5568 0 0.0
FLASH 4592190 4592190 0 0.0
RAM 208368 208368 0 0.0
camera-app debug unknown 9008 9008 0 0.0
FLASH 6885435 6885435 0 0.0
RAM 233224 233224 0 0.0
camera-controller debug unknown 9216 9216 0 0.0
FLASH 13643403 13643403 0 0.0
RAM 668960 668960 0 0.0
chip-tool debug unknown 6264 6264 0 0.0
FLASH 13693365 13693365 0 0.0
RAM 655880 655880 0 0.0
chip-tool-ipv6only arm64 unknown 40736 40736 0 0.0
FLASH 12720455 12720455 0 0.0
RAM 690848 690848 0 0.0
closure-app debug unknown 5536 5536 0 0.0
FLASH 4573964 4573964 0 0.0
RAM 200280 200280 0 0.0
fabric-admin debug unknown 5944 5944 0 0.0
FLASH 12038138 12038138 0 0.0
RAM 654888 654888 0 0.0
fabric-bridge-app debug unknown 4816 4816 0 0.0
FLASH 4391100 4391100 0 0.0
RAM 194032 194032 0 0.0
fabric-sync debug unknown 5056 5056 0 0.0
FLASH 5477349 5477349 0 0.0
RAM 493824 493824 0 0.0
lighting-app debug+rpc+ui unknown 6280 6280 0 0.0
FLASH 5478273 5478273 0 0.0
RAM 209680 209680 0 0.0
lock-app debug unknown 5496 5496 0 0.0
FLASH 4620872 4620872 0 0.0
RAM 196824 196824 0 0.0
ota-provider-app debug unknown 4856 4856 0 0.0
FLASH 4249006 4249006 0 0.0
RAM 185488 185488 0 0.0
ota-requestor-app debug unknown 4736 4736 0 0.0
FLASH 4311856 4311856 0 0.0
RAM 188280 188280 0 0.0
shell debug unknown 4312 4312 0 0.0
FLASH 2934419 2934419 0 0.0
RAM 148600 148600 0 0.0
thermostat-no-ble arm64 unknown 9832 9832 0 0.0
FLASH 4228799 4228799 0 0.0
RAM 226536 226536 0 0.0
tv-app debug unknown 5824 5824 0 0.0
FLASH 5806021 5806021 0 0.0
RAM 618184 618184 0 0.0
tv-casting-app debug unknown 5352 5352 0 0.0
FLASH 11834005 11834005 0 0.0
RAM 772496 772496 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 FLASH 910264 910264 0 0.0
RAM 152836 152836 0 0.0
nxp contact mcxw71+release FLASH 630424 630424 0 0.0
RAM 64092 64092 0 0.0
lock mcxw71+release FLASH 740848 740848 0 0.0
RAM 65168 65168 0 0.0
psoc6 all-clusters cy8ckit_062s2_43012 FLASH 1658476 1658476 0 0.0
RAM 211152 211152 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 FLASH 1579828 1579828 0 0.0
RAM 208424 208424 0 0.0
light cy8ckit_062s2_43012 FLASH 1450972 1450972 0 0.0
RAM 197144 197144 0 0.0
lock cy8ckit_062s2_43012 FLASH 1483292 1483292 0 0.0
RAM 224856 224856 0 0.0
qpg lighting-app qpg6200+debug FLASH 819624 819624 0 0.0
RAM 127608 127608 0 0.0
lock-app qpg6200+debug FLASH 756940 756940 0 0.0
RAM 118568 118568 0 0.0
stm32 light STM32WB5MM-DK FLASH 466588 466588 0 0.0
RAM 141344 141344 0 0.0
telink bridge-app tl7218x FLASH 703772 703772 0 0.0
RAM 93552 93552 0 0.0
light-app-ota-compress-lzma-shell-factory-data tl3218x FLASH 795578 795578 0 0.0
RAM 43968 43968 0 0.0
light-app-ota-shell-factory-data tl7218x FLASH 783982 783982 0 0.0
RAM 100856 100856 0 0.0
light-switch-app-ota-compress-lzma-factory-data tl7218x_retention FLASH 711566 711566 0 0.0
RAM 54192 54192 0 0.0
light-switch-app-ota-compress-lzma-shell-factory-data tlsr9528a FLASH 748160 748160 0 0.0
RAM 77348 77348 0 0.0
light-switch-app-ota-factory-data tl3218x_retention FLASH 724888 724888 0 0.0
RAM 36948 36948 0 0.0
lighting-app-ota-factory-data tlsr9118bdk40d FLASH 604926 604926 0 0.0
RAM 112512 112512 0 0.0
lighting-app-ota-rpc-factory-data-4mb tlsr9518adk80d FLASH 819586 819590 4 0.0
RAM 99108 99108 0 0.0
tizen all-clusters-app arm unknown 5112 5112 0 0.0
FLASH 1768976 1768976 0 0.0
RAM 92156 92156 0 0.0
chip-tool-ubsan arm unknown 20772 20772 0 0.0
FLASH 21106282 21106282 0 0.0
RAM 9181704 9181704 0 0.0

Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.71%. Comparing base (0832b19) to head (7e03607).
⚠️ Report is 73 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40537      +/-   ##
==========================================
- Coverage   51.05%   50.71%   -0.34%     
==========================================
  Files        1344     1355      +11     
  Lines       98443    99303     +860     
  Branches    12672    12877     +205     
==========================================
+ Hits        50257    50366     +109     
- Misses      48186    48937     +751     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@andy31415 andy31415 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add documentation for the added arguments given that documentation already exists.

For the testing section in the PR summary, you included a command that invokes a build script that was not modified by this PR. Could you explain how that works? are there local changes? It was not immediately obvious to me how the changes in this PR translate in the command line you gave working differently ... some explanation/links on how things work would help

@dinabenamar
Copy link
Contributor Author

Please add documentation for the added arguments given that documentation already exists.

For the testing section in the PR summary, you included a command that invokes a build script that was not modified by this PR. Could you explain how that works? are there local changes? It was not immediately obvious to me how the changes in this PR translate in the command line you gave working differently ... some explanation/links on how things work would help

Thank you for the review. I have updated the documentation accordingly.

As for the testing section, I added in the description the changes required for testing each configuration. These changes are applied on application cmake level, and do not require the command line to be changed.

…ip_zapgen() and chip_configure_data_model()

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
… argument with chip_configure_data_model

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
@andy31415
Copy link
Contributor

Please add documentation for the added arguments given that documentation already exists.
For the testing section in the PR summary, you included a command that invokes a build script that was not modified by this PR. Could you explain how that works? are there local changes? It was not immediately obvious to me how the changes in this PR translate in the command line you gave working differently ... some explanation/links on how things work would help

Thank you for the review. I have updated the documentation accordingly.

As for the testing section, I added in the description the changes required for testing each configuration. These changes are applied on application cmake level, and do not require the command line to be changed.

Please describe why these arguments exist, so that people understand their use and intent. It is obvious that an argument ZCL_PATH is the path to the zcl file and if you know a bit about zcl you know it is a json .... tell me something that I do not know.

In particular right now I do not know why this option is needed and why we have it in cmake only?
I have guesses:

  • zcl.json contains extensions and we may want to add different extensions in a build (really?)
  • we did cmake because this is what you needed and you did not need gn support (this is not great ... should we at least add an issue for it?)

So please document things for real:

  • why does this option exist: why do people want a separate ZCL file and in what conditions?
  • what is the usage here
  • why did you have to manually test this and could not automate this? Is this not as simple as picking one example and forcing a ZCL file (even if forcing the default one)?

…ure_data_model to explain the purpose of using ZCL_PATH argument

Signed-off-by: Dina Benamar <dina.benamarelmaaroufi@nxp.com>
@dinabenamar
Copy link
Contributor Author

dinabenamar commented Aug 19, 2025

Please add documentation for the added arguments given that documentation already exists.
For the testing section in the PR summary, you included a command that invokes a build script that was not modified by this PR. Could you explain how that works? are there local changes? It was not immediately obvious to me how the changes in this PR translate in the command line you gave working differently ... some explanation/links on how things work would help

Thank you for the review. I have updated the documentation accordingly.
As for the testing section, I added in the description the changes required for testing each configuration. These changes are applied on application cmake level, and do not require the command line to be changed.

Please describe why these arguments exist, so that people understand their use and intent. It is obvious that an argument ZCL_PATH is the path to the zcl file and if you know a bit about zcl you know it is a json .... tell me something that I do not know.

In particular right now I do not know why this option is needed and why we have it in cmake only? I have guesses:

  • zcl.json contains extensions and we may want to add different extensions in a build (really?)
  • we did cmake because this is what you needed and you did not need gn support (this is not great ... should we at least add an issue for it?)

So please document things for real:

  • why does this option exist: why do people want a separate ZCL file and in what conditions?
  • what is the usage here
  • why did you have to manually test this and could not automate this? Is this not as simple as picking one example and forcing a ZCL file (even if forcing the default one)?

I updated the documentation to clarify why the ZCL_PATH is needed, and also mentioned it in the PR description, in the "context" section.

#                  This maps to the '--zcl' argument in the "scripts/tools/zap/generate.py" script.
#                   By default, generate.py attempts to autodetect the ZCL path from the .zap 
#                   file which is often a relative path. When the .zap file is relocated or symlinked,
#                   these relative paths become invalid, causing the build to fail.
#                   Passing ZCL_PATH explicitly via CMake ensures the build remains robust and portable.
#                   If ZCL_PATH is not provided, the default behavior is preserved unless CHIP_ENABLE_ZCL_ARG
#                   is enabled, in which case the default path "src/app/zap-templates/zcl/zcl.json" is 
#                   automatically injected to simplify usage.

For the testing part, the manual commands were provided as an example to reproduce, but the change is already being covered by the CI workflows of this PR. Specifically, the NXP examples have switched to using these configurations, so the new behavior is exercised automatically. I’ve added this clarification to the PR description as well.

@mergify mergify bot merged commit f8fe491 into project-chip:master Aug 20, 2025
78 of 81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants