Skip to content

Commit

Permalink
Add ability to control data-model-interface usage for cmake-based pla…
Browse files Browse the repository at this point in the history
…tforms (project-chip#35559)

* Add data-mode-enabled/disabled variants to all CMAKE builds.

Platforms changed:
  - esp32
  - mbed
  - nrfconnect
  - telink
  - nxp

I tested all these except NXP which I could not compile in TOT
due to missing vscode configuration.

* add options for data model to qpg builds as this can be used to check for size deltas

* Fix unit test

* Restyle

* Fix nxp typo and strip

* Update quoting logic

* Update config/telink/chip-module/CMakeLists.txt

Co-authored-by: Terence Hampson <[email protected]>

* more update on the 'I' text

* Fix nxp build placement of data model interface

* Switch to zephyr KConfig for data model interface setting

* Use bool for DM enabling in places

* Apply review comment

* Fix nxp typo

---------

Co-authored-by: Andrei Litvin <[email protected]>
Co-authored-by: Terence Hampson <[email protected]>
  • Loading branch information
3 people authored Sep 13, 2024
1 parent 7467abc commit bba766b
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 41 deletions.
10 changes: 10 additions & 0 deletions build/chip/esp32/esp32_codegen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

macro(chip_app_component_codegen IDL_NAME)
include("${CHIP_ROOT}/build/chip/chip_codegen.cmake")
include("${CHIP_ROOT}/src/app/codegen-data-model-provider/model.cmake")

# The IDF build system performs a two-pass expansion to determine
# component expansion. The first pass runs in script-mode
Expand Down Expand Up @@ -71,5 +72,14 @@ macro(chip_app_component_zapgen ZAP_NAME)
add_dependencies(${COMPONENT_LIB} app-zapgen)
target_include_directories(${COMPONENT_LIB} PUBLIC "${APP_TEMPLATE_GEN_DIR}")
target_sources(${COMPONENT_LIB} PRIVATE ${APP_TEMPLATE_GEN_FILES})

# When data model interface is used, provide a default code-generation data model as
# part of zapgen. See `chip_data_model.cmake` for similar logic
set(CHIP_DATA_MODEL_INTERFACE "disabled" CACHE STRING "Data model interface option to use: enabled or disabled")

if ("${CHIP_DATA_MODEL_INTERFACE}" STREQUAL "enabled")
target_sources(${COMPONENT_LIB} PRIVATE ${CODEGEN_DATA_MODEL_SOURCES})
endif()

endif()
endmacro()
9 changes: 7 additions & 2 deletions config/common/cmake/chip_gn_args.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ macro(matter_common_gn_args)
LIB_PW_RPC
DEVICE_INFO_EXAMPLE_PROVIDER
PROJECT_CONFIG

DATA_MODEL_INTERFACE
)
set(multiValueArgs
PROJECT_CONFIG_INC_DIR
Expand Down Expand Up @@ -203,6 +203,11 @@ macro(matter_common_gn_args)
if (ARG_DEVICE_INFO_EXAMPLE_PROVIDER)
matter_add_gn_arg_bool ("chip_build_example_providers" ${ARG_DEVICE_INFO_EXAMPLE_PROVIDER})
endif() # ARG_DEVICE_INFO_EXAMPLE_PROVIDER

if (ARG_DATA_MODEL_INTERFACE)
matter_add_gn_arg_string("chip_use_data_model_interface" "${ARG_DATA_MODEL_INTERFACE}")
endif()

if (ARG_PROJECT_CONFIG)
get_filename_component(PROJECT_CONFIG
${ARG_PROJECT_CONFIG}
Expand All @@ -220,4 +225,4 @@ endmacro()
# Generate the temporary GN arguments file from the settings
macro(matter_generate_args_tmp_file)
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/args.tmp" CONTENT ${MATTER_GN_ARGS})
endmacro()
endmacro()
8 changes: 8 additions & 0 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ include(${CMAKE_CURRENT_LIST_DIR}/ota-image.cmake)

set(CHIP_REQUIRE_COMPONENTS esp_eth freertos lwip bt mbedtls fatfs app_update console openthread nvs_flash spi_flash)

set(CHIP_DATA_MODEL_INTERFACE "disabled" CACHE STRING "Data model interface option to use: enabled or disabled")

if(NOT "${IDF_TARGET}" STREQUAL "esp32h2")
list(APPEND CHIP_REQUIRE_COMPONENTS mdns)
endif()
Expand Down Expand Up @@ -64,6 +66,12 @@ macro(chip_gn_arg_bool arg boolean)
endif()
endmacro()

if ("${CHIP_DATA_MODEL_INTERFACE}" STREQUAL "enabled")
chip_gn_arg_append("chip_use_data_model_interface" "\"enabled\"")
else()
chip_gn_arg_append("chip_use_data_model_interface" "\"disabled\"")
endif()

# ESP-IDF lets user set software version string by two ways:
# 1. Project's CMakeLists.txt file and 2. Config option
# It depends on CONFIG_APP_PROJECT_VER_FROM_CONFIG option
Expand Down
4 changes: 4 additions & 0 deletions config/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ if (CONFIG_MBED_BSD_SOCKET_TRACE)
matter_add_flags(-DMBED_BSD_SOCKET_TRACE=1)
endif()

# Option can be set with `-DCHIP_DATA_MODEL_INTERFACE=enabled` or similar on the command line
set(CHIP_DATA_MODEL_INTERFACE "disabled" CACHE STRING "Data model interface option to use: enabled or disabled")

# ==============================================================================
# Generate configuration for CHIP GN build system
# ==============================================================================
Expand All @@ -121,6 +124,7 @@ matter_common_gn_args(
LIB_TESTS CONFIG_CHIP_BUILD_TESTS
LIB_PW_RPC CONFIG_CHIP_PW_RPC
PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG}
DATA_MODEL_INTERFACE ${CHIP_DATA_MODEL_INTERFACE}
)
if (CONFIG_CHIP_PW_RPC)
matter_add_gn_arg_import("${GN_ROOT_TARGET}/lib/pw_rpc/pw_rpc.gni")
Expand Down
8 changes: 8 additions & 0 deletions config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ endif()

get_property(CHIP_COMPILER_LAUNCHER GLOBAL PROPERTY RULE_LAUNCH_COMPILE)


if (CONFIG_USE_CHIP_DATA_MODEL_INTERFACE)
set(DATA_MODEL_INTERFACE "enabled")
else()
set(DATA_MODEL_INTERFACE "disabled")
endif()

# ==============================================================================
# Generate configuration for CHIP GN build system
# ==============================================================================
Expand All @@ -116,6 +123,7 @@ matter_common_gn_args(
LIB_TESTS CONFIG_CHIP_BUILD_TESTS
PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG}
DEVICE_INFO_EXAMPLE_PROVIDER CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER
DATA_MODEL_INTERFACE ${DATA_MODEL_INTERFACE}
)
matter_add_gn_arg_string("zephyr_ar" ${CMAKE_AR})
matter_add_gn_arg_string("zephyr_cc" ${CMAKE_C_COMPILER})
Expand Down
7 changes: 7 additions & 0 deletions config/nxp/chip-cmake-freertos/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,20 @@ matter_add_gn_arg("chip_with_factory_data" ${CONFIG_CHIP_FACTORY_DATA})
matter_add_gn_arg("chip_enable_secure_dac_private_key_storage" ${CONFIG_CHIP_SECURE_DAC_PRIVATE_KEY_STORAGE})
matter_add_gn_arg("chip_enable_secure_whole_factory_data" ${CONFIG_CHIP_ENABLE_SECURE_WHOLE_FACTORY_DATA})

if (CONFIG_USE_CHIP_DATA_MODEL_INTERFACE)
set(DATA_MODEL_INTERFACE "enabled")
else()
set(DATA_MODEL_INTERFACE "disabled")
endif()

matter_common_gn_args(
DEBUG CONFIG_DEBUG
LIB_SHELL CONFIG_CHIP_LIB_SHELL
LIB_TESTS CONFIG_CHIP_BUILD_TESTS
PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG}
PROJECT_CONFIG_INC_DIR ${CONFIG_CHIP_PROJECT_CONFIG_INCLUDE_DIRS}
DEVICE_INFO_EXAMPLE_PROVIDER CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER
DATA_MODEL_INTERFACE ${DATA_MODEL_INTERFACE}
)

matter_generate_args_tmp_file()
Expand Down
8 changes: 8 additions & 0 deletions config/nxp/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ endif()

get_property(CHIP_COMPILER_LAUNCHER GLOBAL PROPERTY RULE_LAUNCH_COMPILE)

if (CONFIG_USE_CHIP_DATA_MODEL_INTERFACE)
set(DATA_MODEL_INTERFACE "enabled")
else()
set(DATA_MODEL_INTERFACE "disabled")
endif()


# ==============================================================================
# Generate configuration for CHIP GN build system
# ==============================================================================
Expand All @@ -101,6 +108,7 @@ matter_common_gn_args(
LIB_TESTS CONFIG_CHIP_BUILD_TESTS
PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG}
DEVICE_INFO_EXAMPLE_PROVIDER CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER
DATA_MODEL_INTERFACE ${DATA_MODEL_INTERFACE}
)
matter_add_gn_arg_string("zephyr_ar" ${CMAKE_AR})
matter_add_gn_arg_string("zephyr_cc" ${CMAKE_C_COMPILER})
Expand Down
7 changes: 7 additions & 0 deletions config/telink/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ if (CONFIG_CHIP_OPENTHREAD_CONFIG)
zephyr_set_openthread_config(${CHIP_OPENTHREAD_CONFIG})
endif()

if (CONFIG_USE_CHIP_DATA_MODEL_INTERFACE)
set(DATA_MODEL_INTERFACE "enabled")
else()
set(DATA_MODEL_INTERFACE "disabled")
endif()

# ==============================================================================
# Generate configuration for CHIP GN build system
# ==============================================================================
Expand All @@ -87,6 +93,7 @@ matter_common_gn_args(
LIB_TESTS CONFIG_CHIP_BUILD_TESTS
PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG}
DEVICE_INFO_EXAMPLE_PROVIDER CONFIG_CHIP_EXAMPLE_DEVICE_INFO_PROVIDER
DATA_MODEL_INTERFACE ${DATA_MODEL_INTERFACE}
)
matter_add_gn_arg_string("zephyr_ar" ${CMAKE_AR})
matter_add_gn_arg_string("zephyr_cc" ${CMAKE_C_COMPILER})
Expand Down
7 changes: 7 additions & 0 deletions config/zephyr/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,11 @@ config CHIP_BLE_ADVERTISING_DURATION
If CHIP_BLE_EXT_ADVERTISING is set to false, the maximum duration time is 15 minutes,
else the maximum duration time can be extended to 2880 minutes (48h).

config USE_CHIP_DATA_MODEL_INTERFACE
bool "Use a DataModel::Provider interface for data access"
help
This enables a level of indiraction in the CHIP interaction model engine in
accessing underlying data and executing operations such as
wildcard-expansion, read, write and invoke.

endif
9 changes: 8 additions & 1 deletion config/zephyr/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ if(CONFIG_CHIP)
zephyr_set_openthread_config(${CHIP_OPENTHREAD_CONFIG})
endif()

if (CONFIG_USE_CHIP_DATA_MODEL_INTERFACE)
set(DATA_MODEL_INTERFACE "enabled")
else()
set(DATA_MODEL_INTERFACE "disabled")
endif()

# ==============================================================================
# Generate configuration for CHIP GN build system
# ==============================================================================
Expand All @@ -78,6 +84,7 @@ if(CONFIG_CHIP)
LIB_SHELL CONFIG_CHIP_LIB_SHELL
LIB_TESTS CONFIG_CHIP_BUILD_TESTS
PROJECT_CONFIG ${CONFIG_CHIP_PROJECT_CONFIG}
DATA_MODEL_INTERFACE ${DATA_MODEL_INTERFACE}
)

matter_add_gn_arg_string("zephyr_ar" ${CMAKE_AR})
Expand Down Expand Up @@ -139,4 +146,4 @@ if(CONFIG_CHIP)
GN_DEPENDENCIES kernel
)
set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS chip)
endif() # CONFIG_CHIP
endif() # CONFIG_CHIP
12 changes: 12 additions & 0 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def BuildEsp32Target():
target.AppendModifier('rpc', enable_rpcs=True)
target.AppendModifier('ipv6only', enable_ipv4=False)
target.AppendModifier('tracing', enable_insights_trace=True).OnlyIfRe("light")
target.AppendModifier('data-model-disabled', data_model_interface="disabled").ExceptIfRe('-data-model-enabled')
target.AppendModifier('data-model-enabled', data_model_interface="enabled").ExceptIfRe('-data-model-disabled')

return target

Expand Down Expand Up @@ -331,6 +333,8 @@ def BuildNrfTarget():
])

target.AppendModifier('rpc', enable_rpcs=True)
target.AppendModifier('data-model-disabled', use_data_model_interface=False).ExceptIfRe('-data-model-enabled')
target.AppendModifier('data-model-enabled', use_data_model_interface=True).ExceptIfRe('-data-model-disabled')

return target

Expand Down Expand Up @@ -416,6 +420,8 @@ def BuildMbedTarget():
'-(release|debug)')
target.AppendModifier('debug', profile=MbedProfile.DEBUG).ExceptIfRe(
'-(release|develop)')
target.AppendModifier('data-model-disabled', data_model_interface="disabled").ExceptIfRe('-data-model-enabled')
target.AppendModifier('data-model-enabled', data_model_interface="enabled").ExceptIfRe('-data-model-disabled')

return target

Expand Down Expand Up @@ -540,6 +546,8 @@ def BuildNxpTarget():
target.AppendModifier(name="wifi", enable_wifi=True).OnlyIfRe('rw61x')
target.AppendModifier(name="thread", enable_thread=True).ExceptIfRe('zephyr')
target.AppendModifier(name="matter-shell", enable_shell=True).ExceptIfRe('k32w0|k32w1')
target.AppendModifier('data-model-disabled', data_model_interface="disabled").ExceptIfRe('-data-model-enabled')
target.AppendModifier('data-model-enabled', data_model_interface="enabled").ExceptIfRe('-data-model-disabled')

return target

Expand Down Expand Up @@ -620,6 +628,8 @@ def BuildQorvoTarget():
])

target.AppendModifier('updateimage', update_image=True)
target.AppendModifier('data-model-disabled', data_model_interface="disabled").ExceptIfRe('-data-model-enabled')
target.AppendModifier('data-model-enabled', data_model_interface="enabled").ExceptIfRe('-data-model-disabled')

return target

Expand Down Expand Up @@ -781,6 +791,8 @@ def BuildTelinkTarget():
target.AppendModifier('4mb', enable_4mb_flash=True)
target.AppendModifier('mars', mars_board_config=True)
target.AppendModifier('usb', usb_board_config=True)
target.AppendModifier('data-model-disabled', use_data_model_interface=False).ExceptIfRe('-data-model-enabled')
target.AppendModifier('data-model-enabled', use_data_model_interface=True).ExceptIfRe('-data-model-disabled')

return target

Expand Down
8 changes: 7 additions & 1 deletion scripts/build/builders/esp32.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import shlex
from enum import Enum, auto
from typing import Optional

from .builder import Builder, BuilderOutput

Expand Down Expand Up @@ -153,14 +154,16 @@ def __init__(self,
app: Esp32App = Esp32App.ALL_CLUSTERS,
enable_rpcs: bool = False,
enable_ipv4: bool = True,
enable_insights_trace: bool = False
enable_insights_trace: bool = False,
data_model_interface: Optional[str] = None,
):
super(Esp32Builder, self).__init__(root, runner)
self.board = board
self.app = app
self.enable_rpcs = enable_rpcs
self.enable_ipv4 = enable_ipv4
self.enable_insights_trace = enable_insights_trace
self.data_model_interface = data_model_interface

if not app.IsCompatible(board):
raise Exception(
Expand Down Expand Up @@ -215,6 +218,9 @@ def generate(self):
cmake_flags.append(
f"-DCHIP_CODEGEN_PREGEN_DIR={shlex.quote(self.options.pregen_dir)}")

if self.data_model_interface:
cmake_flags.append(f'-DCHIP_DATA_MODEL_INTERFACE={self.data_model_interface}')

cmake_args = ['-C', self.ExamplePath, '-B',
shlex.quote(self.output_dir)] + cmake_flags

Expand Down
2 changes: 1 addition & 1 deletion scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
enable_test_event_triggers=None,
enable_dnssd_tests: Optional[bool] = None,
chip_casting_simplified: Optional[bool] = None,
data_model_interface: Optional[bool] = None,
data_model_interface: Optional[str] = None,
chip_data_model_check_die_on_failure: Optional[bool] = None,
):
super(HostBuilder, self).__init__(
Expand Down
9 changes: 8 additions & 1 deletion scripts/build/builders/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import shlex
from enum import Enum, auto
from typing import Optional

from .builder import Builder, BuilderOutput

Expand Down Expand Up @@ -101,7 +102,9 @@ def __init__(self,
runner,
app: MbedApp = MbedApp.LOCK,
board: MbedBoard = MbedBoard.CY8CPROTO_062_4343W,
profile: MbedProfile = MbedProfile.RELEASE):
profile: MbedProfile = MbedProfile.RELEASE,
data_model_interface: Optional[str] = None,
):
super(MbedBuilder, self).__init__(root, runner)
self.app = app
self.board = board
Expand All @@ -111,6 +114,7 @@ def __init__(self,
self.root, 'third_party', 'mbed-os', 'repo')
self.mbed_os_posix_socket_path = os.path.join(
self.root, 'third_party', 'mbed-os-posix-socket', 'repo')
self.data_model_interface = data_model_interface

@property
def ExamplePath(self):
Expand All @@ -131,6 +135,9 @@ def generate(self):
flags.append(f"-DMBED_OS_PATH={shlex.quote(self.mbed_os_path)}")
flags.append(f"-DMBED_OS_POSIX_SOCKET_PATH={shlex.quote(self.mbed_os_posix_socket_path)}")

if self.data_model_interface is not None:
flags.append(f"-DCHIP_DATA_MODEL_INTERFACE={self.data_model_interface}")

if self.options.pregen_dir:
flags.append(f"-DCHIP_CODEGEN_PREGEN_DIR={shlex.quote(self.options.pregen_dir)}")

Expand Down
Loading

0 comments on commit bba766b

Please sign in to comment.