Skip to content
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

Added compile support for NuttX system #31236

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,7 @@ NTP
nullable
nullptr
NUM
NuttX
NVM
NVS
nwdiag
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/examples-nuttx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Build example - NuttX

on:
push:
pull_request:
merge_group:
workflow_dispatch:

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
cancel-in-progress: true

env:
CHIP_NO_LOG_TIMESTAMPS: true

jobs:
nuttx:
name: NuttX

runs-on: ubuntu-latest
if: github.actor != 'restyled-io[bot]'

container:
image: ghcr.io/project-chip/chip-build-nuttx:51
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout submodules & Bootstrap
uses: ./.github/actions/checkout-submodules-and-bootstrap
with:
platform: nuttx
extra-submodule-parameters: " --recursive"
- name: Build example simulator NuttX Lighting App
run: |
./scripts/run_in_build_env.sh \
"./scripts/build/build_examples.py \
--target nuttx-x64-light \
build \
"
3 changes: 2 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ jobs:
--skip-dir platform/webos \
--skip-dir platform/Zephyr \
--skip-dir test_driver \
--skip-dir platform/NuttX \
--known-failure app/app-platform/ContentApp.cpp \
--known-failure app/app-platform/ContentApp.h \
--known-failure app/app-platform/ContentAppPlatform.cpp \
Expand Down Expand Up @@ -205,7 +206,7 @@ jobs:
# TODO: TLVDebug should ideally not be excluded here.
# TODO: protocol_decoder.cpp should ideally not be excluded here.
# TODO: PersistentStorageMacros.h should ideally not be excluded here.
git grep -I -n "PRI.64" -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)examples/chip-tool' ':(exclude)examples/tv-casting-app' ':(exclude)src/app/MessageDef/MessageDefHelper.cpp' ':(exclude)src/app/tests/integration/chip_im_initiator.cpp' ':(exclude)src/lib/core/TLVDebug.cpp' ':(exclude)src/lib/dnssd/tests/TestTxtFields.cpp' ':(exclude)src/lib/format/protocol_decoder.cpp' ':(exclude)src/lib/support/PersistentStorageMacros.h' ':(exclude)src/messaging/tests/echo/echo_requester.cpp' ':(exclude)src/platform/Linux' ':(exclude)src/platform/Ameba' ':(exclude)src/platform/ESP32' ':(exclude)src/platform/Darwin' ':(exclude)src/darwin' ':(exclude)src/platform/webos' ':(exclude)zzz_generated/chip-tool' ':(exclude)src/tools/chip-cert/Cmd_PrintCert.cpp' && exit 1 || exit 0
git grep -I -n "PRI.64" -- './*' ':(exclude).github/workflows/lint.yml' ':(exclude)examples/chip-tool' ':(exclude)examples/tv-casting-app' ':(exclude)src/app/MessageDef/MessageDefHelper.cpp' ':(exclude)src/app/tests/integration/chip_im_initiator.cpp' ':(exclude)src/lib/core/TLVDebug.cpp' ':(exclude)src/lib/dnssd/tests/TestTxtFields.cpp' ':(exclude)src/lib/format/protocol_decoder.cpp' ':(exclude)src/lib/support/PersistentStorageMacros.h' ':(exclude)src/messaging/tests/echo/echo_requester.cpp' ':(exclude)src/platform/Linux' ':(exclude)src/platform/Ameba' ':(exclude)src/platform/ESP32' ':(exclude)src/platform/Darwin' ':(exclude)src/darwin' ':(exclude)src/platform/webos' ':(exclude)zzz_generated/chip-tool' ':(exclude)src/tools/chip-cert/Cmd_PrintCert.cpp' ':(exclude)src/platform/NuttX' && exit 1 || exit 0

# git grep exits with 0 if it finds a match, but we want
# to fail (exit nonzero) on match. And we want to exclude this file,
Expand Down
5 changes: 5 additions & 0 deletions build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ config("strict_warnings") {

cflags_cc = [ "-Wnon-virtual-dtor" ]

if (current_os == "nuttx") {
cflags -= [ "-Wshadow" ]
cflags_cc -= [ "-Wnon-virtual-dtor" ]
}

configs = []
ldflags = []

Expand Down
29 changes: 29 additions & 0 deletions config/nuttx/chip-gn/.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

# The location of the build configuration file.
buildconfig = "${build_root}/config/BUILDCONFIG.gn"

# CHIP uses angle bracket includes.
check_system_includes = true

default_args = {
target_cpu = ""
target_os = "nuttx"

import("${chip_root}/config/nuttx/chip-gn/args.gni")
}
57 changes: 57 additions & 0 deletions config/nuttx/chip-gn/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

import("${chip_root}/build/chip/tests.gni")

assert(current_os == "nuttx")

declare_args() {
chip_build_example_providers = false
chip_example_lighting = false
}

static_library("nuttx") {
output_name = "libchipnuttx"

public_deps = [
"${chip_root}/examples/platform/linux:app-main",
"${chip_root}/src/lib",
]

if (chip_build_tests) {
public_deps += [ "${chip_root}/src:tests" ]
}

if (chip_build_example_providers) {
public_deps += [ "${chip_root}/examples/providers:device_info_provider" ]
}

if (chip_example_lighting) {
public_deps += [
"${chip_root}/examples/lighting-app/lighting-common",
"${chip_root}/examples/lighting-app/lighting-common:lighting-manager",
]
}

output_dir = "${root_out_dir}/lib"

complete_static_lib = true
}

group("default") {
deps = [ ":nuttx" ]
}
32 changes: 32 additions & 0 deletions config/nuttx/chip-gn/args.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build_overrides/chip.gni")

import("${chip_root}/src/crypto/crypto.gni")

chip_device_platform = "nuttx"

chip_build_tests = false

chip_project_config_include = ""
chip_system_project_config_include = ""
chip_ble_project_config_include = ""

chip_crypto = "mbedtls"
chip_external_mbedtls = true

custom_toolchain = "${chip_root}/config/nuttx/chip-gn/toolchain:nuttx"

pw_build_PIP_CONSTRAINTS = [ "${chip_root}/scripts/setup/constraints.txt" ]
33 changes: 33 additions & 0 deletions config/nuttx/chip-gn/toolchain/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build/toolchain/gcc_toolchain.gni")
import("//build_overrides/build.gni")

declare_args() {
nuttx_ar = ""
nuttx_cc = ""
nuttx_cxx = ""
}

gcc_toolchain("nuttx") {
ar = nuttx_ar
cc = nuttx_cc
cxx = nuttx_cxx

toolchain_args = {
current_os = "nuttx"
is_clang = false
}
}
2 changes: 1 addition & 1 deletion examples/lighting-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void ApplicationShutdown()
}
}

int main(int argc, char * argv[])
extern "C" int main(int argc, char * argv[])
{
if (ChipLinuxAppInit(argc, argv) != 0)
{
Expand Down
18 changes: 18 additions & 0 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from builders.mbed import MbedApp, MbedBoard, MbedBuilder, MbedProfile
from builders.mw320 import MW320App, MW320Builder
from builders.nrf import NrfApp, NrfBoard, NrfConnectBuilder
from builders.nuttx import NuttXApp, NuttXBoard, NuttXBuilder
from builders.nxp import NxpApp, NxpBoard, NxpBuilder
from builders.openiotsdk import OpenIotSdkApp, OpenIotSdkBuilder, OpenIotSdkCryptoBackend
from builders.qpg import QpgApp, QpgBoard, QpgBuilder
Expand Down Expand Up @@ -324,6 +325,22 @@ def BuildNrfTarget():
return target


def BuildNuttXTarget():
target = BuildTarget('nuttx', NuttXBuilder)

# Boards
target.AppendFixedTargets([
TargetPart('x64', board=NuttXBoard.SIM),
])

# Apps
target.AppendFixedTargets([
TargetPart('light', app=NuttXApp.LIGHT),
])

return target


def BuildAndroidTarget():
target = BuildTarget('android', AndroidBuilder)

Expand Down Expand Up @@ -795,6 +812,7 @@ def BuildOpenIotSdkTargets():
BuildMW320Target(),
BuildNrfTarget(),
BuildNrfNativeTarget(),
BuildNuttXTarget(),
BuildQorvoTarget(),
BuildStm32Target(),
BuildTizenTarget(),
Expand Down
98 changes: 98 additions & 0 deletions scripts/build/builders/nuttx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
from enum import Enum, auto

from .gn import Builder


class NuttXApp(Enum):
LIGHT = auto()

def ExampleName(self):
if self == NuttXApp.LIGHT:
return 'lighting-app'
else:
raise Exception('Unknown app type: %r' % self)

def AppNamePrefix(self, chip_name):
if self == NuttXApp.LIGHT:
return ('chip-%s-lighting-example' % chip_name)
else:
raise Exception('Unknown app type: %r' % self)


class NuttXBoard(Enum):
SIM = auto()


def NuttXTarget(board, app):
if board == NuttXBoard.SIM:
if app == NuttXApp.LIGHT:
return 'sim:matter'
zhhyu7 marked this conversation as resolved.
Show resolved Hide resolved
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
return 'none'


class NuttXBuilder(Builder):

def __init__(self,
root,
runner,
app: NuttXApp = NuttXApp.LIGHT,
board: NuttXBoard = NuttXBoard.SIM,
):

nuttx_chip = 'nuttx'

super(NuttXBuilder, self).__init__(
root=os.path.join(root, 'examples',
app.ExampleName(), nuttx_chip),
runner=runner
)

self.chip_name = nuttx_chip
self.app = app
self.board = board

def generate(self):
self._Execute(['mkdir', '-p', self.output_dir],
title='Generating ' + self.identifier)

def _build(self):
logging.info('Compiling NuttX %s at %s, ',
NuttXTarget(self.board, self.app), self.output_dir)
nuttx_dir = os.path.join(os.sep, 'opt', 'nuttx', 'nuttx')

self._Execute(['cmake', '-S', nuttx_dir, '-B', self.output_dir, '-DCHIP_ROOT=' + os.getenv('PW_PROJECT_ROOT'),
'-DBOARD_CONFIG=' + NuttXTarget(self.board, self.app),
'-DCMAKE_C_COMPILER=/opt/nuttx/gcc-13/bin/gcc',
'-DCMAKE_CXX_COMPILER=/opt/nuttx/gcc-13/bin/g++',
'-GNinja'],
title='Building ' + self.identifier)
self._Execute(['cmake', '--build', self.output_dir])

def build_outputs(self):
logging.info('Compiling outputs NuttX at %s', self.output_dir)
items = {
'%s.out' % self.app.AppNamePrefix(self.chip_name):
os.path.join(self.output_dir, '%s.out' %
self.app.AppNamePrefix(self.chip_name)),
'%s.out.map' % self.app.AppNamePrefix(self.chip_name):
os.path.join(self.output_dir,
'%s.out.map' % self.app.AppNamePrefix(self.chip_name)),
}

return items
Loading
Loading