From efa630b58e514fa7a3240dcbeb2ffebd5adc68c4 Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Wed, 8 Jul 2020 22:23:08 -0400 Subject: [PATCH] Support building CHIP with GN (#1456) * Add nlunit-test to GN build * Add nlassert to GN build * Add nlfaultinjection to GN build * Add nlio to GN build * Add GN files to gitignore * Add GN build support using pw_toolchain & pw_build This uses build infrastructure from pigweed to enable building CHIP with GN. * Add lwIP to GN build * Add Mbed TLS to GN build * Add SystemConfig to GN build * Add CHIPConfig to GN build * Add src/lib/support to GN build * Add src/system to GN build * Add src/inet to GN build * Add BLE to GN build * Add src/lib/core to GN build * Add src/controller to GN build * Add libCHIP.a to GN build * Add src/system/tests to GN build * Add CHIPVersion.h generation to GN build * Add src/lib/support/tests to GN build * Add src/inet/tests to GN build * Add src/ble/tests to GN build * Add src/lib/core/tests to GN build * Add src/crypto to GN build * Add src/app to GN build * Add src/crypto/tests to GN build * Add support for building nRF5 lock app * Run unit tests with some help from pigweed This enables running tests during the build. Just run gn gen out/debug ninja -C out/debug check * Add qrcodetool to GN build * Add transport to GN build * Add src/setup_payout/tests to GN build * Add src/setup_payload to GN build * Add ARM toolchain support * Make the build relocatable * Add nRF5 lock example superproject build * Add support for combined build via target_os="all" This configures host_clang, host_gcc, and nRF5 lock app. To run a maximal build: gn gen out/debug --args='target_os="all"' ninja -C out/debug check * Make bootstrap display cleaner * Add GN build wrapper script This script does an end to end bootstrap & build with GN from a fresh clone. Usage: ./gn_build.sh * Add examples/chip-tool to GN build * Remove shared imports Importing everything from chip.gni will require some dependencies to be present even if they are not used. Import overrides separately. Also add args to disable various builds at the top level. * Add transport tests to GN build * Add examples/shell to GN build * Add tips to gn_build.sh To run a GN build of chip: ./gn_build.sh * Enable building with homebrew openssl on Mac via pkg-config * Add mbedtls build to top level build * Add nRF5 lock app back to example build But only if NRF5_SDK_ROOT is set in the environment. * Harmonize library outputs with automake This changes most libraries to match the names used by automake. * Restyled by shfmt * Move the GN build files to //gn And use the secondary_source feature to still allow loading them via //build. This breaks using ${chip_root} in superproject builds, but that was unnecessary anyway. We should try to unwind this later as it causes some confusion about what path to specify. * Fix lint warning "Except block directly handles BaseException" * Move activate above bootstrap The usual case is to source activate.sh, not bootstrap.sh, so move that first. bootstrap.sh is only needed after an update. * Add github actions for GN * Move project specific build logic to gn/chip * Add comments to GN build GitHub workflow helpers * Fix the nRF5 lock app CI build Remove a broken link that was left behind after moving build files to //gn. * Updating Build Version * Re-merge repos.conf with .gitmodules This was unmerged by a recent commit. * Move bootstrap.sh & activate.sh to scripts * Fixup activate.sh & bootstrap.sh after moving Co-authored-by: Keir Mierle Co-authored-by: Restyled.io Co-authored-by: Justin Wood --- .github/workflows/gn_build.yaml | 48 ++ .gitignore | 3 + .gitmodules | 2 +- .gn | 28 ++ BUILD.gn | 163 +++++++ examples/chip-tool/BUILD.gn | 31 ++ examples/lock-app/nrf5/.gn | 26 ++ examples/lock-app/nrf5/BUILD.gn | 88 ++++ examples/lock-app/nrf5/args.gni | 24 + .../lock-app/nrf5/build_overrides/chip.gni | 18 + .../lock-app/nrf5/build_overrides/lwip.gni | 18 + .../lock-app/nrf5/build_overrides/mbedtls.gni | 18 + .../nrf5/build_overrides/nlassert.gni | 18 + .../nrf5/build_overrides/nlfaultinjection.gni | 19 + .../lock-app/nrf5/build_overrides/nlio.gni | 18 + .../nrf5/build_overrides/nlunit_test.gni | 18 + .../nrf5/build_overrides/nrf5_lock_app.gni | 18 + .../nrf5/build_overrides/nrf5_sdk.gni | 18 + .../lock-app/nrf5/build_overrides/pigweed.gni | 20 + examples/lock-app/nrf5/common_args.gni | 45 ++ examples/lock-app/nrf5/toolchain/BUILD.gn | 22 + examples/shell/BUILD.gn | 35 ++ gn/build/config/BUILDCONFIG.gn | 93 ++++ gn/build/config/arm.gni | 40 ++ gn/build/config/compiler/BUILD.gn | 240 ++++++++++ gn/build/config/compiler/compiler.gni | 27 ++ gn/build/config/custom_toolchain.gni | 20 + gn/build/config/defaults.gni | 96 ++++ gn/build/config/linux/pkg-config.py | 266 ++++++++++++ gn/build/config/linux/pkg_config.gni | 115 +++++ gn/build/toolchain/arm_gcc/BUILD.gn | 19 + gn/build/toolchain/arm_gcc/arm_toolchain.gni | 44 ++ gn/build/toolchain/host_clang/BUILD.gn | 23 + gn/build/toolchain/host_clang/toolchains.gni | 116 +++++ gn/build/toolchain/host_gcc/BUILD.gn | 23 + gn/build/toolchain/host_gcc/toolchains.gni | 98 +++++ gn/build_overrides/chip.gni | 18 + gn/build_overrides/lwip.gni | 18 + gn/build_overrides/mbedtls.gni | 18 + gn/build_overrides/nlassert.gni | 18 + gn/build_overrides/nlfaultinjection.gni | 18 + gn/build_overrides/nlio.gni | 18 + gn/build_overrides/nlunit_test.gni | 18 + gn/build_overrides/nrf5_lock_app.gni | 18 + gn/build_overrides/nrf5_sdk.gni | 18 + gn/build_overrides/pigweed.gni | 20 + gn/chip/chip_build.gni | 32 ++ gn/chip/chip_test.gni | 48 ++ gn/chip/chip_test_group.gni | 34 ++ gn/chip/chip_test_suite.gni | 73 ++++ gn/chip/chip_version.gni | 29 ++ gn/chip/device.gni | 28 ++ gn/chip/tests.gni | 21 + gn/chip/tools.gni | 18 + gn_build.sh | 92 ++++ repos.conf | 46 +- activate.sh => scripts/activate.sh | 4 +- bootstrap.sh => scripts/bootstrap.sh | 2 +- scripts/build/gn_bootstrap.sh | 26 ++ scripts/build/gn_build.sh | 29 ++ scripts/build/gn_gen.sh | 29 ++ scripts/gen_chip_version.py | 231 ++++++++++ scripts/tests/gn_tests.sh | 29 ++ src/BUILD.gn | 25 ++ src/app/BUILD.gn | 88 ++++ src/app/plugin/tests/BUILD.gn | 45 ++ src/ble/BUILD.gn | 79 ++++ src/ble/ble.gni | 18 + src/ble/tests/BUILD.gn | 34 ++ src/controller/BUILD.gn | 30 ++ src/crypto/BUILD.gn | 65 +++ src/crypto/crypto.gni | 29 ++ src/crypto/tests/BUILD.gn | 39 ++ src/inet/BUILD.gn | 156 +++++++ src/inet/inet.gni | 38 ++ src/inet/tests/BUILD.gn | 57 +++ src/lib/BUILD.gn | 40 ++ src/lib/core/BUILD.gn | 153 +++++++ src/lib/core/core.gni | 65 +++ src/lib/core/tests/BUILD.gn | 42 ++ src/lib/shell/BUILD.gn | 34 ++ src/lib/support/BUILD.gn | 112 +++++ src/lib/support/tests/BUILD.gn | 44 ++ src/lwip/BUILD.gn | 88 ++++ src/lwip/efr32/lwipopts.h | 5 +- src/lwip/nrf5/lwipopts.h | 3 + src/lwip/tests/BUILD.gn | 27 ++ src/platform/BUILD.gn | 98 +++++ src/qrcodetool/BUILD.gn | 33 ++ src/setup_payload/BUILD.gn | 47 ++ src/setup_payload/tests/BUILD.gn | 42 ++ src/system/BUILD.gn | 160 +++++++ src/system/system.gni | 54 +++ src/system/tests/BUILD.gn | 45 ++ src/transport/BUILD.gn | 41 ++ src/transport/tests/BUILD.gn | 51 +++ third_party/lwip/lwip.gni | 411 ++++++++++++++++++ third_party/mbedtls/BUILD.gn | 102 +++++ third_party/nlassert/BUILD.gn | 23 + third_party/nlfaultinjection/BUILD.gn | 30 ++ third_party/nlio/BUILD.gn | 39 ++ third_party/nlunit-test/BUILD.gn | 28 ++ third_party/nrf5_sdk/BUILD.gn | 28 ++ third_party/nrf5_sdk/nrf5_sdk.gni | 183 ++++++++ 104 files changed, 5552 insertions(+), 50 deletions(-) create mode 100644 .github/workflows/gn_build.yaml create mode 100644 .gn create mode 100644 BUILD.gn create mode 100644 examples/chip-tool/BUILD.gn create mode 100644 examples/lock-app/nrf5/.gn create mode 100644 examples/lock-app/nrf5/BUILD.gn create mode 100644 examples/lock-app/nrf5/args.gni create mode 100644 examples/lock-app/nrf5/build_overrides/chip.gni create mode 100644 examples/lock-app/nrf5/build_overrides/lwip.gni create mode 100644 examples/lock-app/nrf5/build_overrides/mbedtls.gni create mode 100644 examples/lock-app/nrf5/build_overrides/nlassert.gni create mode 100644 examples/lock-app/nrf5/build_overrides/nlfaultinjection.gni create mode 100644 examples/lock-app/nrf5/build_overrides/nlio.gni create mode 100644 examples/lock-app/nrf5/build_overrides/nlunit_test.gni create mode 100644 examples/lock-app/nrf5/build_overrides/nrf5_lock_app.gni create mode 100644 examples/lock-app/nrf5/build_overrides/nrf5_sdk.gni create mode 100644 examples/lock-app/nrf5/build_overrides/pigweed.gni create mode 100644 examples/lock-app/nrf5/common_args.gni create mode 100644 examples/lock-app/nrf5/toolchain/BUILD.gn create mode 100644 examples/shell/BUILD.gn create mode 100644 gn/build/config/BUILDCONFIG.gn create mode 100644 gn/build/config/arm.gni create mode 100644 gn/build/config/compiler/BUILD.gn create mode 100644 gn/build/config/compiler/compiler.gni create mode 100644 gn/build/config/custom_toolchain.gni create mode 100644 gn/build/config/defaults.gni create mode 100755 gn/build/config/linux/pkg-config.py create mode 100644 gn/build/config/linux/pkg_config.gni create mode 100644 gn/build/toolchain/arm_gcc/BUILD.gn create mode 100644 gn/build/toolchain/arm_gcc/arm_toolchain.gni create mode 100644 gn/build/toolchain/host_clang/BUILD.gn create mode 100644 gn/build/toolchain/host_clang/toolchains.gni create mode 100644 gn/build/toolchain/host_gcc/BUILD.gn create mode 100644 gn/build/toolchain/host_gcc/toolchains.gni create mode 100644 gn/build_overrides/chip.gni create mode 100644 gn/build_overrides/lwip.gni create mode 100644 gn/build_overrides/mbedtls.gni create mode 100644 gn/build_overrides/nlassert.gni create mode 100644 gn/build_overrides/nlfaultinjection.gni create mode 100644 gn/build_overrides/nlio.gni create mode 100644 gn/build_overrides/nlunit_test.gni create mode 100644 gn/build_overrides/nrf5_lock_app.gni create mode 100644 gn/build_overrides/nrf5_sdk.gni create mode 100644 gn/build_overrides/pigweed.gni create mode 100644 gn/chip/chip_build.gni create mode 100644 gn/chip/chip_test.gni create mode 100644 gn/chip/chip_test_group.gni create mode 100644 gn/chip/chip_test_suite.gni create mode 100644 gn/chip/chip_version.gni create mode 100644 gn/chip/device.gni create mode 100644 gn/chip/tests.gni create mode 100644 gn/chip/tools.gni create mode 100755 gn_build.sh mode change 100644 => 120000 repos.conf rename activate.sh => scripts/activate.sh (91%) rename bootstrap.sh => scripts/bootstrap.sh (96%) create mode 100755 scripts/build/gn_bootstrap.sh create mode 100755 scripts/build/gn_build.sh create mode 100755 scripts/build/gn_gen.sh create mode 100755 scripts/gen_chip_version.py create mode 100755 scripts/tests/gn_tests.sh create mode 100644 src/BUILD.gn create mode 100644 src/app/BUILD.gn create mode 100644 src/app/plugin/tests/BUILD.gn create mode 100644 src/ble/BUILD.gn create mode 100644 src/ble/ble.gni create mode 100644 src/ble/tests/BUILD.gn create mode 100644 src/controller/BUILD.gn create mode 100644 src/crypto/BUILD.gn create mode 100644 src/crypto/crypto.gni create mode 100644 src/crypto/tests/BUILD.gn create mode 100644 src/inet/BUILD.gn create mode 100644 src/inet/inet.gni create mode 100644 src/inet/tests/BUILD.gn create mode 100644 src/lib/BUILD.gn create mode 100644 src/lib/core/BUILD.gn create mode 100644 src/lib/core/core.gni create mode 100644 src/lib/core/tests/BUILD.gn create mode 100644 src/lib/shell/BUILD.gn create mode 100644 src/lib/support/BUILD.gn create mode 100644 src/lib/support/tests/BUILD.gn create mode 100644 src/lwip/BUILD.gn create mode 100644 src/lwip/tests/BUILD.gn create mode 100644 src/platform/BUILD.gn create mode 100644 src/qrcodetool/BUILD.gn create mode 100644 src/setup_payload/BUILD.gn create mode 100644 src/setup_payload/tests/BUILD.gn create mode 100644 src/system/BUILD.gn create mode 100644 src/system/system.gni create mode 100644 src/system/tests/BUILD.gn create mode 100644 src/transport/BUILD.gn create mode 100644 src/transport/tests/BUILD.gn create mode 100644 third_party/lwip/lwip.gni create mode 100644 third_party/mbedtls/BUILD.gn create mode 100644 third_party/nlassert/BUILD.gn create mode 100644 third_party/nlfaultinjection/BUILD.gn create mode 100644 third_party/nlio/BUILD.gn create mode 100644 third_party/nlunit-test/BUILD.gn create mode 100644 third_party/nrf5_sdk/BUILD.gn create mode 100644 third_party/nrf5_sdk/nrf5_sdk.gni diff --git a/.github/workflows/gn_build.yaml b/.github/workflows/gn_build.yaml new file mode 100644 index 00000000000000..94c7fe49e1a04c --- /dev/null +++ b/.github/workflows/gn_build.yaml @@ -0,0 +1,48 @@ +name: GN Builds + +on: + push: + pull_request: + +jobs: + build: + name: GN Build + + strategy: + matrix: + type: [main, clang, mbedtls] + env: + BUILD_TYPE: ${{ matrix.type }} + BUILD_VERSION: 0.2.18 + BUILD_IMAGE: chip-build-openssl + BUILD_ORG: connectedhomeip + + runs-on: ubuntu-latest + + container: + image: "connectedhomeip/chip-build-openssl:0.2.18" + volumes: + - "/tmp/log_output:/tmp/test_logs" + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Checkout Submodules + run: make -f Makefile-bootstrap repos + - name: Bootstrap + run: scripts/build/gn_bootstrap.sh + - name: Setup Build + run: | + case $BUILD_TYPE in + "main") GN_ARGS='';; + "clang") GN_ARGS='is_clang=true';; + "linux-embedded") GN_ARGS='device_platform="linux"';; + "mbedtls") GN_ARGS='chip_crypto="mbedtls"';; + *) ;; + esac + + scripts/build/gn_gen.sh --args="$GN_ARGS" + - name: Run Build + run: scripts/build/gn_build.sh + - name: Run Tests + run: scripts/tests/gn_tests.sh diff --git a/.gitignore b/.gitignore index ee7662752d2ef9..73d0f2863e686b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,9 @@ configure src/include/BuildConfig.h.in src/include/BuildConfig.h.in~ +# GN build system +out/ + # Repos stuff .repos-warning-stamp diff --git a/.gitmodules b/.gitmodules index 220f560519b95e..ec96bf28415e29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -52,7 +52,7 @@ branch = master ignore = dirty commit = 5f0e36eeb236a507631e9c822e43f742b7b6738a -[submodule "third_party/ot-br-posix/repo"] +[submodule "ot-br-posix"] path = third_party/ot-br-posix/repo url = https://github.com/openthread/ot-br-posix.git branch = master diff --git a/.gn b/.gn new file mode 100644 index 00000000000000..f0756bebc97d29 --- /dev/null +++ b/.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2020 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. + +# The location of the build configuration file. +buildconfig = "//build/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +# Allow loading paths relative to //gn. +secondary_source = "//gn/" + +import("//gn/build_overrides/pigweed.gni") + +default_args = { + pw_unit_test_AUTOMATIC_RUNNER = "$dir_pigweed/targets/host/run_test" +} diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 00000000000000..76facff41b6d78 --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,163 @@ +# Copyright (c) 2020 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("//build_overrides/mbedtls.gni") +import("//build_overrides/nlassert.gni") +import("//build_overrides/nlio.gni") +import("//build_overrides/nlunit_test.gni") +import("//build_overrides/pigweed.gni") + +# This build file should not be used in superproject builds. +assert(chip_root == "//") + +import("${chip_root}/gn/chip/tests.gni") +import("${chip_root}/gn/chip/tools.gni") + +if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { + # This is a real toolchain. Build CHIP. + group("default") { + deps = [ ":all" ] + } + + group("all") { + deps = [ + "${chip_root}/src/app", + "${chip_root}/src/ble", + "${chip_root}/src/controller", + "${chip_root}/src/crypto", + "${chip_root}/src/inet", + "${chip_root}/src/lib", + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + "${chip_root}/src/lwip:all", + "${chip_root}/src/system", + "${chip_root}/src/transport", + "${mbedtls_root}:mbedtls", + "${nlassert_root}:nlassert", + "${nlio_root}:nlio", + "${nlunit_test_root}:nlunit-test", + ] + + if (chip_build_tests) { + deps += [ ":tests" ] + } + + if (chip_build_tools) { + deps += [ + "${chip_root}/examples/chip-tool", + "${chip_root}/examples/shell", + "${chip_root}/src/lib/shell", + "${chip_root}/src/qrcodetool", + "${chip_root}/src/setup_payload", + ] + } + } + + if (chip_build_tests) { + import("${chip_root}/gn/chip/chip_test_group.gni") + + chip_test_group("tests") { + deps = [ + "${chip_root}/src/app/plugin/tests", + "${chip_root}/src/ble/tests", + "${chip_root}/src/crypto/tests", + "${chip_root}/src/inet/tests", + "${chip_root}/src/lib/core/tests", + "${chip_root}/src/lib/support/tests", + "${chip_root}/src/lwip/tests", + "${chip_root}/src/setup_payload/tests", + "${chip_root}/src/system/tests", + "${chip_root}/src/transport/tests", + ] + } + + group("check") { + deps = [ ":tests_run" ] + } + } +} else { + # This is the dummy toolchain. Configure various real toolchains. + import("${chip_root}/gn/chip/chip_build.gni") + declare_args() { + # Set this to false to disable all builds by default. + enable_default_builds = true + } + + declare_args() { + # Enable building chip with clang. + enable_host_clang_build = enable_default_builds + + # Enable building chip with gcc. + enable_host_gcc_build = enable_default_builds + + # Build building chip with gcc & mbedtls. + enable_host_gcc_mbdtls_build = enable_default_builds + + # Build the nRF5 lock app example. + enable_nrf5_lock_app_build = false + } + + if (enable_nrf5_lock_app_build) { + import("//build_overrides/nrf5_lock_app.gni") + } + + import("//build/toolchain/host_clang/toolchains.gni") + import("//build/toolchain/host_gcc/toolchains.gni") + chip_build("host_clang") { + toolchain = "//build/toolchain/host_clang:${host_os}_${host_cpu}_clang" + } + + chip_build("host_gcc") { + toolchain = "//build/toolchain/host_gcc:${host_os}_${host_cpu}_gcc" + } + + chip_build("host_gcc_mbedtls") { + toolchain = "//build/toolchain/host_gcc:${host_os}_${host_cpu}_gcc_mbedtls" + } + + group("default") { + deps = [] + if (enable_host_clang_build) { + deps += [ ":all_host_clang" ] + } + if (enable_host_gcc_build) { + deps += [ ":all_host_gcc" ] + } + if (enable_host_gcc_mbdtls_build) { + deps += [ ":all_host_gcc_mbedtls" ] + } + if (enable_nrf5_lock_app_build) { + deps += [ "${nrf5_lock_app_root}:nrf5(${nrf5_lock_app_root}/toolchain:nrf5_lock_app)" ] + } + } + + if (chip_build_tests) { + group("check") { + deps = [] + if (enable_host_clang_build) { + deps += [ ":check_host_clang" ] + } + if (enable_host_gcc_build) { + deps += [ ":check_host_gcc" ] + } + if (enable_host_gcc_mbdtls_build) { + deps += [ ":check_host_gcc_mbedtls" ] + } + if (enable_nrf5_lock_app_build) { + deps += [ ":default" ] + } + } + } +} diff --git a/examples/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn new file mode 100644 index 00000000000000..c935610a527f00 --- /dev/null +++ b/examples/chip-tool/BUILD.gn @@ -0,0 +1,31 @@ +# Copyright (c) 2020 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}/gn/chip/tools.gni") + +assert(chip_build_tools) + +executable("chip-standalone-demo") { + sources = [ "main.cpp" ] + + public_deps = [ "${chip_root}/src/lib" ] + + output_dir = "${root_out_dir}/bin" +} + +group("chip-tool") { + deps = [ ":chip-standalone-demo" ] +} diff --git a/examples/lock-app/nrf5/.gn b/examples/lock-app/nrf5/.gn new file mode 100644 index 00000000000000..2129e6fa50ebaa --- /dev/null +++ b/examples/lock-app/nrf5/.gn @@ -0,0 +1,26 @@ +# Copyright (c) 2020 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. + +# The location of the build configuration file. +buildconfig = "//build/config/BUILDCONFIG.gn" + +# CHIP uses angle bracket includes. +check_system_includes = true + +# Allow loading paths relative to //gn. +secondary_source = "//third_party/connectedhomeip/gn/" + +default_args = { + import("//args.gni") +} diff --git a/examples/lock-app/nrf5/BUILD.gn b/examples/lock-app/nrf5/BUILD.gn new file mode 100644 index 00000000000000..0ec33ac7d53b0d --- /dev/null +++ b/examples/lock-app/nrf5/BUILD.gn @@ -0,0 +1,88 @@ +# Copyright (c) 2020 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("//build_overrides/nrf5_sdk.gni") + +import("${nrf5_sdk_build_root}/nrf5_sdk.gni") + +assert(current_os == "freertos") + +nrf5_platform_dir = "${chip_root}/examples/platform/nrf528xx" + +nrf5_sdk("sdk") { + include_dirs = [ + "main/include", + "main", + "${chip_root}/src/include", + "${nrf5_platform_dir}/app/project_include", + "${nrf5_platform_dir}/util/include", + "${nrf5_platform_dir}/app/include", + ] + + sources = [ + "${nrf5_platform_dir}/app/project_include/CHIPProjectConfig.h", + "${nrf5_platform_dir}/app/project_include/FreeRTOSConfig.h", + "${nrf5_platform_dir}/app/project_include/OpenThreadConfig.h", + "${nrf5_platform_dir}/app/project_include/freertos_tasks_c_additions.h", + "${nrf5_platform_dir}/app/project_include/nrf_log_ctrl_internal.h", + "main/include/app_config.h", + ] + + defines = [] + if (is_debug) { + defines += [ "BUILD_RELEASE=0" ] + } else { + defines += [ "BUILD_RELEASE=1" ] + } + + defines += [ "USE_APP_CONFIG" ] +} + +executable("lock_app") { + public_deps = [ + ":sdk", + "${chip_root}/src/lib", + ] + + sources = [ + "${nrf5_platform_dir}/app/Server.cpp", + "${nrf5_platform_dir}/app/chipinit.cpp", + "${nrf5_platform_dir}/app/include/Server.h", + "${nrf5_platform_dir}/app/include/chipinit.h", + "${nrf5_platform_dir}/app/support/CXXExceptionStubs.cpp", + "${nrf5_platform_dir}/app/support/FreeRTOSNewlibLockSupport.c", + "${nrf5_platform_dir}/app/support/nRF5Sbrk.c", + "${nrf5_platform_dir}/util/LEDWidget.cpp", + "${nrf5_platform_dir}/util/include/LEDWidget.h", + "main/AppTask.cpp", + "main/BoltLockManager.cpp", + "main/DataModelHandler.cpp", + "main/include/AppEvent.h", + "main/include/AppTask.h", + "main/include/BoltLockManager.h", + "main/include/DataModelHandler.h", + "main/main.cpp", + ] + + output_dir = root_out_dir + + ldscript = "${nrf5_platform_dir}/app/ldscripts/chip-nrf52840-example.ld" + + ldflags = [ "-T" + rebase_path(ldscript, root_build_dir) ] +} + +group("nrf5") { + deps = [ ":lock_app" ] +} diff --git a/examples/lock-app/nrf5/args.gni b/examples/lock-app/nrf5/args.gni new file mode 100644 index 00000000000000..a8291bec008034 --- /dev/null +++ b/examples/lock-app/nrf5/args.gni @@ -0,0 +1,24 @@ +# Copyright (c) 2020 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/nrf5_lock_app.gni") +import("${nrf5_lock_app_root}/common_args.gni") + +# These values help set up the default toolchain in standalone sample app +# builds. They must be in a separate file to avoid namespace conflicts in +# multi target builds. +custom_toolchain = "${nrf5_lock_app_root}/toolchain:nrf5_lock_app" +target_cpu = "arm" +target_os = "freertos" +# Don't add more args here, add them to common_args.gni. diff --git a/examples/lock-app/nrf5/build_overrides/chip.gni b/examples/lock-app/nrf5/build_overrides/chip.gni new file mode 100644 index 00000000000000..23aafc1df7b3cd --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides/chip.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for CHIP. + chip_root = "//third_party/connectedhomeip" +} diff --git a/examples/lock-app/nrf5/build_overrides/lwip.gni b/examples/lock-app/nrf5/build_overrides/lwip.gni new file mode 100644 index 00000000000000..9a50a46bae6a8b --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides/lwip.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for lwIP. + lwip_root = "//third_party/connectedhomeip/third_party/lwip" +} diff --git a/examples/lock-app/nrf5/build_overrides/mbedtls.gni b/examples/lock-app/nrf5/build_overrides/mbedtls.gni new file mode 100644 index 00000000000000..fff24c4f29f01f --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides/mbedtls.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for mbedTLS. + mbedtls_root = "//third_party/connectedhomeip/third_party/mbedtls" +} diff --git a/examples/lock-app/nrf5/build_overrides/nlassert.gni b/examples/lock-app/nrf5/build_overrides/nlassert.gni new file mode 100644 index 00000000000000..30e8c701634664 --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides/nlassert.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nlassert. + nlassert_root = "//third_party/connectedhomeip/third_party/nlassert" +} diff --git a/examples/lock-app/nrf5/build_overrides/nlfaultinjection.gni b/examples/lock-app/nrf5/build_overrides/nlfaultinjection.gni new file mode 100644 index 00000000000000..155d765597d110 --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides/nlfaultinjection.gni @@ -0,0 +1,19 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nlfaultinjection. + nlfaultinjection_root = + "//third_party/connectedhomeip/third_party/nlfaultinjection" +} diff --git a/examples/lock-app/nrf5/build_overrides/nlio.gni b/examples/lock-app/nrf5/build_overrides/nlio.gni new file mode 100644 index 00000000000000..f7d5ee6117e826 --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides/nlio.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nlio. + nlio_root = "//third_party/connectedhomeip/third_party/nlio" +} diff --git a/examples/lock-app/nrf5/build_overrides/nlunit_test.gni b/examples/lock-app/nrf5/build_overrides/nlunit_test.gni new file mode 100644 index 00000000000000..ed017adc65f04a --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides/nlunit_test.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nlunit-test. + nlunit_test_root = "//third_party/connectedhomeip/third_party/nlunit-test" +} diff --git a/examples/lock-app/nrf5/build_overrides/nrf5_lock_app.gni b/examples/lock-app/nrf5/build_overrides/nrf5_lock_app.gni new file mode 100644 index 00000000000000..3f8857c41f9ba7 --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides/nrf5_lock_app.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nRF5 lock app example. + nrf5_lock_app_root = "//" +} diff --git a/examples/lock-app/nrf5/build_overrides/nrf5_sdk.gni b/examples/lock-app/nrf5/build_overrides/nrf5_sdk.gni new file mode 100644 index 00000000000000..6729e7f082cfb6 --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides/nrf5_sdk.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nRF5 SDK. + nrf5_sdk_build_root = "//third_party/connectedhomeip/third_party/nrf5_sdk" +} diff --git a/examples/lock-app/nrf5/build_overrides/pigweed.gni b/examples/lock-app/nrf5/build_overrides/pigweed.gni new file mode 100644 index 00000000000000..ff0fb6516d9604 --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides/pigweed.gni @@ -0,0 +1,20 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Location of the Pigweed repository. + dir_pigweed = "//third_party/connectedhomeip/third_party/pigweed" +} + +import("$dir_pigweed/modules.gni") diff --git a/examples/lock-app/nrf5/common_args.gni b/examples/lock-app/nrf5/common_args.gni new file mode 100644 index 00000000000000..b3426f5cba12e8 --- /dev/null +++ b/examples/lock-app/nrf5/common_args.gni @@ -0,0 +1,45 @@ +# Copyright (c) 2020 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/nrf5_lock_app.gni") + +device_platform = "nrf5" + +arm_arch = "armv7e-m" +arm_float_abi = "hard" +arm_cpu = "cortex-m4" +arm_fpu = "fpv4-sp-d16" + +lwip_platform = "nrf5" +lwip_ipv6 = true +lwip_ipv4 = false +lwip_api = true + +inet_config_enable_ipv4 = false +inet_config_enable_dns_resolver = false + +chip_build_tests = false +nrf5_sdk_target = "${nrf5_lock_app_root}:sdk" + +ble_platform_config_include = "" +ble_project_config_include = "" +chip_device_platform_config_include = + "" +chip_device_project_config_include = "" +chip_platform_config_include = "" +chip_project_config_include = "" +inet_platform_config_include = "" +inet_project_config_include = "" +system_platform_config_include = "" +system_project_config_include = "" diff --git a/examples/lock-app/nrf5/toolchain/BUILD.gn b/examples/lock-app/nrf5/toolchain/BUILD.gn new file mode 100644 index 00000000000000..b311daa63968ab --- /dev/null +++ b/examples/lock-app/nrf5/toolchain/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright (c) 2020 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/nrf5_lock_app.gni") + +import("//build/toolchain/arm_gcc/arm_toolchain.gni") + +arm_toolchain("nrf5_lock_app") { + toolchain_args_file = "${nrf5_lock_app_root}/common_args.gni" + current_os = "freertos" +} diff --git a/examples/shell/BUILD.gn b/examples/shell/BUILD.gn new file mode 100644 index 00000000000000..da409f3c0e9c0e --- /dev/null +++ b/examples/shell/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2020 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}/gn/chip/tools.gni") + +assert(chip_build_tools) + +executable("chip-shell") { + sources = [ + "cmd_base64.cpp", + "cmd_misc.cpp", + "main.cpp", + ] + + public_deps = [ "${chip_root}/src/lib/shell" ] + + output_dir = "${root_out_dir}/bin" +} + +group("shell") { + deps = [ ":chip-shell" ] +} diff --git a/gn/build/config/BUILDCONFIG.gn b/gn/build/config/BUILDCONFIG.gn new file mode 100644 index 00000000000000..ac573c4353e3e5 --- /dev/null +++ b/gn/build/config/BUILDCONFIG.gn @@ -0,0 +1,93 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Debug build. Set this to false to remove development features. + is_debug = true +} + +if (target_os == "") { + target_os = host_os +} + +if (target_cpu == "") { + target_cpu = host_cpu +} + +if (current_cpu == "") { + current_cpu = target_cpu +} +if (current_os == "") { + current_os = target_os +} + +_chip_overrides = { + import("//build_overrides/chip.gni") +} + +_pigweed_overrides = { + import("//build_overrides/pigweed.gni") +} + +_chip_defaults = { + import("//build/config/defaults.gni") +} + +declare_args() { + # Toolchain to use for host. This is usually set by default. + host_toolchain = "" +} + +if (host_toolchain == "") { + if (_chip_defaults.is_clang) { + host_toolchain = "${_chip_overrides.chip_root}/build/toolchain/host_clang:${host_os}_${host_cpu}_clang" + } else { + host_toolchain = "${_chip_overrides.chip_root}/build/toolchain/host_gcc:${host_os}_${host_cpu}_gcc" + } +} + +if (_chip_defaults.custom_toolchain != "") { + _default_toolchain = _chip_defaults.custom_toolchain +} else if (target_os == host_os) { + _default_toolchain = host_toolchain +} else if (target_os == "all") { + _default_toolchain = "${_pigweed_overrides.dir_pw_toolchain}/dummy" +} else if (target_os == "freertos") { + if (target_cpu == "arm") { + _default_toolchain = "//build/toolchain/arm_gcc" + } else { + assert(false, "Unsupported target_cpu: ${target_cpu}") + } +} else { + assert(false, "No toolchain specified, please specify custom_toolchain") +} + +set_default_toolchain(_default_toolchain) + +set_defaults("static_library") { + configs = _chip_defaults.default_configs +} +set_defaults("source_set") { + configs = _chip_defaults.default_configs +} +set_defaults("executable") { + configs = + _chip_defaults.default_configs + _chip_defaults.executable_default_configs +} +set_defaults("shared_library") { + configs = _chip_defaults.default_configs +} +set_defaults("loadable_module") { + configs = _chip_defaults.default_configs +} diff --git a/gn/build/config/arm.gni b/gn/build/config/arm.gni new file mode 100644 index 00000000000000..7a7b2d3405e913 --- /dev/null +++ b/gn/build/config/arm.gni @@ -0,0 +1,40 @@ +# Copyright (c) 2020 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. + +assert(current_cpu == "arm" || current_cpu == "arm64") + +if (current_cpu == "arm") { + declare_args() { + # ARM architecture (value for -march flag). + arm_arch = "" + + # ARM CPU (value for -mcpu flag). + arm_cpu = "" + + # ARM tuning (value for -mtune flag). + arm_tune = "" + + # ARM FPU (value for -mfpu flag). + arm_fpu = "" + + # ARM float ABI (value for -mfloat-api flag). + arm_float_abi = "" + + # ARM ABI (value for -mapi flag). + arm_abi = "" + + # ARM thumb instruction set (value for -mthumb flag). + arm_use_thumb = true + } +} diff --git a/gn/build/config/compiler/BUILD.gn b/gn/build/config/compiler/BUILD.gn new file mode 100644 index 00000000000000..fc50a216ab1d19 --- /dev/null +++ b/gn/build/config/compiler/BUILD.gn @@ -0,0 +1,240 @@ +# Copyright (c) 2020 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("//build_overrides/pigweed.gni") + +import("//build/config/compiler/compiler.gni") + +if (current_cpu == "arm") { + import("//build/config/arm.gni") +} + +config("release") { + defines = [ "NDEBUG" ] +} + +config("debug_default") { + if (!is_debug) { + configs = [ ":release" ] + } +} + +config("abi_default") { + cflags = [] + if (current_cpu == "arm") { + if (arm_arch != "") { + cflags += [ "-march=${arm_arch}" ] + } + if (arm_cpu != "") { + cflags += [ "-mcpu=${arm_cpu}" ] + } + if (arm_tune != "") { + cflags += [ "-mtune=${arm_tune}" ] + } + if (arm_abi != "") { + cflags += [ "-mabi=${arm_abi}" ] + } + if (arm_fpu != "") { + cflags += [ "-mfpu=${arm_fpu}" ] + } + if (arm_float_abi != "") { + cflags += [ "-mfloat-abi=${arm_float_abi}" ] + } + if (arm_use_thumb) { + cflags += [ "-mthumb" ] + } + } + ldflags = cflags +} + +config("optimize_zero") { + cflags = [ "-O0" ] + ldflags = cflags +} + +config("optimize_default") { + if (is_debug) { + if (optimize_debug) { + configs = [ "$dir_pw_build:optimize_debugging" ] + } else { + configs = [ ":optimize_zero" ] + } + } else { + if (optimize_for_size) { + configs = [ "$dir_pw_build:optimize_size" ] + } else { + configs = [ "$dir_pw_build:optimize_speed" ] + } + + if (current_os != "mac") { + ldflags = [ + "-Wl,-O2", + "-Wl,--gc-sections", + ] + } + } +} + +config("disabled_warnings") { + cflags = [ + "-Wno-unused-parameter", + "-Wno-unused-function", + "-Wno-unused-variable", + "-Wno-format", + "-Wno-missing-field-initializers", + "-Wno-expansion-to-defined", + "-Wno-implicit-fallthrough", + "-Wno-deprecated-declarations", + ] + cflags_cc = [ + "-Wno-non-virtual-dtor", + "-Wno-deprecated-copy", + ] + if (!is_clang) { + cflags += [ + "-Wno-cast-function-type", + "-Wno-maybe-uninitialized", + "-Wno-unknown-warning-option", + ] + } +} + +config("strict_warnings") { + cflags = [ + "-Wall", + "-Werror", + ] +} + +config("warnings_default") { + configs = [ + ":strict_warnings", + ":disabled_warnings", + ] + + if (current_os != "mac") { + ldflags = [ "-Wl,--fatal-warnings" ] + } +} + +config("symbols_default") { + cflags = [ "-g${symbol_level}" ] +} + +config("gnu11") { + cflags_c = [ "-std=gnu11" ] + cflags_cc = [ "-std=gnu++11" ] +} + +config("std_default") { + configs = [ ":gnu11" ] +} + +config("cosmetic_default") { + configs = [ "$dir_pw_build:colorize_output" ] +} + +config("runtime_default") { + if (is_clang) { + configs = [ + "$dir_pw_toolchain/host_clang:no_system_libcpp", + "$dir_pw_toolchain/host_clang:xcode_sysroot", + ] + } + if (current_os == "linux") { + libs = [ + "dl", + "pthread", + "rt", + ] + } +} + +config("sanitize_default") { +} + +config("fuzzing_default") { +} + +config("no_rtti") { + cflags_cc = [ "-fno-rtti" ] +} + +config("rtti") { + cflags_cc = [ "-frtti" ] +} + +config("rtti_default") { + configs = [ ":no_rtti" ] +} + +config("no_exceptions") { + cflags = [ "-fno-exceptions" ] +} + +config("exceptions") { + cflags = [ "-fexceptions" ] +} + +config("exceptions_default") { + configs = [ ":no_exceptions" ] +} + +config("unwind_tables_default") { + cflags = [ + "-fno-unwind-tables", + "-fno-asynchronous-unwind-tables", + ] +} + +config("size_default") { + cflags = [ + "-fno-common", + "-ffunction-sections", + "-fdata-sections", + ] +} + +config("stack_protector_default") { + cflags = [ "-fno-stack-protector" ] +} + +config("pic_default") { + cflags = [ "-fPIC" ] + ldflags = cflags +} + +config("pie_default") { + if (current_os == "linux") { + ldflags = [ "-pie" ] + } +} + +config("aliasing_default") { + cflags = [ "-fno-strict-aliasing" ] +} + +config("specs_default") { + if (current_cpu == "arm" && current_os == "freertos") { + cflags = [ + "--specs=nosys.specs", + "--specs=nano.specs", + ] + + libs = [ "nosys" ] + + ldflags = cflags + } +} diff --git a/gn/build/config/compiler/compiler.gni b/gn/build/config/compiler/compiler.gni new file mode 100644 index 00000000000000..d71408442321e6 --- /dev/null +++ b/gn/build/config/compiler/compiler.gni @@ -0,0 +1,27 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Use clang to build. + is_clang = false + + # Optimize for size by default. + optimize_for_size = true + + # Optimize debug builds with -Og. + optimize_debug = current_os == "freertos" + + # Symbol level for debugging. + symbol_level = 2 +} diff --git a/gn/build/config/custom_toolchain.gni b/gn/build/config/custom_toolchain.gni new file mode 100644 index 00000000000000..97412cdf5a9f01 --- /dev/null +++ b/gn/build/config/custom_toolchain.gni @@ -0,0 +1,20 @@ +# Copyright (c) 2020 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") + +declare_args() { + # Toolchain to use for taget. + custom_toolchain = "" +} diff --git a/gn/build/config/defaults.gni b/gn/build/config/defaults.gni new file mode 100644 index 00000000000000..cf0447900e9a70 --- /dev/null +++ b/gn/build/config/defaults.gni @@ -0,0 +1,96 @@ +# Copyright (c) 2020 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("//build/config/compiler/compiler.gni") +import("//build/config/custom_toolchain.gni") + +declare_args() { + # Default configs for abi. + default_configs_abi = [ "//build/config/compiler:abi_default" ] + + # Default configs for debugging. + default_configs_debug = [ "//build/config/compiler:debug_default" ] + + # Default configs for specs. + default_configs_specs = [ "//build/config/compiler:specs_default" ] + + # Default configs for optimization. + default_configs_optimize = [ "//build/config/compiler:optimize_default" ] + + # Default configs for language. + default_configs_std = [ "//build/config/compiler:std_default" ] + + # Defaults configs for symbols. + default_configs_symbols = [ "//build/config/compiler:symbols_default" ] + + # Defaults configs for aliasing. + default_configs_aliasing = [ "//build/config/compiler:aliasing_default" ] + + # Defaults configs for size. + default_configs_size = [ "//build/config/compiler:size_default" ] + + # Defaults configs for exceptions. + default_configs_exceptions = [ "//build/config/compiler:exceptions_default" ] + + # Defaults configs for rtti. + default_configs_rtti = [ "//build/config/compiler:rtti_default" ] + + # Defaults configs for pic. + default_configs_pic = [ "//build/config/compiler:pic_default" ] + + # Defaults configs for pie. + default_configs_pie = [ "//build/config/compiler:pie_default" ] + + # Defaults configs for warnings. + default_configs_warnings = [ "//build/config/compiler:warnings_default" ] + + # Defaults cosmetic configs. + default_configs_cosmetic = [ "//build/config/compiler:cosmetic_default" ] + + # Default configs for runtime library. + default_configs_runtime = [ "//build/config/compiler:runtime_default" ] + + # Defaults sanitizer configs. + default_configs_sanitize = [ "//build/config/compiler:sanitize_default" ] + + # Defaults fuzzing configs. + default_configs_fuzzing = [ "//build/config/compiler:fuzzing_default" ] + + # Extra default configs. + default_configs_extra = [] +} + +default_configs = [] +default_configs += default_configs_abi +default_configs += default_configs_debug +default_configs += default_configs_optimize +default_configs += default_configs_std +default_configs += default_configs_symbols +default_configs += default_configs_size +default_configs += default_configs_specs +default_configs += default_configs_exceptions +default_configs += default_configs_pic +default_configs += default_configs_rtti +default_configs += default_configs_warnings +default_configs += default_configs_cosmetic +default_configs += default_configs_runtime +default_configs += default_configs_aliasing +default_configs += default_configs_sanitize +default_configs += default_configs_fuzzing +default_configs += default_configs_extra + +executable_default_configs = [] +executable_default_configs += default_configs_pie diff --git a/gn/build/config/linux/pkg-config.py b/gn/build/config/linux/pkg-config.py new file mode 100755 index 00000000000000..1adbb520c83718 --- /dev/null +++ b/gn/build/config/linux/pkg-config.py @@ -0,0 +1,266 @@ +#!/usr/bin/env python +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Copyright (c) 2020 Project CHIP Authors +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +from __future__ import print_function + +import json +import os +import subprocess +import sys +import re +from optparse import OptionParser + +# This script runs pkg-config, optionally filtering out some results, and +# returns the result. +# +# The result will be [ , , , , ] +# where each member is itself a list of strings. +# +# You can filter out matches using "-v " where all results from +# pkgconfig matching the given regular expression will be ignored. You can +# specify more than one regular expression my specifying "-v" more than once. +# +# You can specify a sysroot using "-s " where sysroot is the absolute +# system path to the sysroot used for compiling. This script will attempt to +# generate correct paths for the sysroot. +# +# When using a sysroot, you must also specify the architecture via +# "-a " where arch is either "x86" or "x64". +# +# CrOS systemroots place pkgconfig files at /usr/share/pkgconfig +# and one of /usr/lib/pkgconfig or /usr/lib64/pkgconfig +# depending on whether the systemroot is for a 32 or 64 bit architecture. They +# specify the 'lib' or 'lib64' of the pkgconfig path by defining the +# 'system_libdir' variable in the args.gn file. pkg_config.gni communicates this +# variable to this script with the "--system_libdir " flag. If no +# flag is provided, then pkgconfig files are assumed to come from +# /usr/lib/pkgconfig. +# +# Additionally, you can specify the option --atleast-version. This will skip +# the normal outputting of a dictionary and instead print true or false, +# depending on the return value of pkg-config for the given package. + + +def SetConfigPath(options): + """Set the PKG_CONFIG_LIBDIR environment variable. + + This takes into account any sysroot and architecture specification from the + options on the given command line. + """ + + sysroot = options.sysroot + assert sysroot + + # Compute the library path name based on the architecture. + arch = options.arch + if sysroot and not arch: + print("You must specify an architecture via -a if using a sysroot.") + sys.exit(1) + + libdir = sysroot + '/usr/' + options.system_libdir + '/pkgconfig' + libdir += ':' + sysroot + '/usr/share/pkgconfig' + os.environ['PKG_CONFIG_LIBDIR'] = libdir + return libdir + + +def GetPkgConfigPrefixToStrip(options, args): + """Returns the prefix from pkg-config where packages are installed. + + This returned prefix is the one that should be stripped from the beginning of + directory names to take into account sysroots. + """ + # Some sysroots, like the Chromium OS ones, may generate paths that are not + # relative to the sysroot. For example, + # /path/to/chroot/build/x86-generic/usr/lib/pkgconfig/pkg.pc may have all + # paths relative to /path/to/chroot (i.e. prefix=/build/x86-generic/usr) + # instead of relative to /path/to/chroot/build/x86-generic (i.e prefix=/usr). + # To support this correctly, it's necessary to extract the prefix to strip + # from pkg-config's |prefix| variable. + prefix = subprocess.check_output([options.pkg_config, + "--variable=prefix"] + args, env=os.environ).decode('utf-8') + if prefix[-4] == '/usr': + return prefix[4:] + return prefix + + +def MatchesAnyRegexp(flag, list_of_regexps): + """Returns true if the first argument matches any regular expression in the + given list.""" + for regexp in list_of_regexps: + if regexp.search(flag) != None: + return True + return False + + +def RewritePath(path, strip_prefix, sysroot): + """Rewrites a path by stripping the prefix and prepending the sysroot.""" + if os.path.isabs(path) and not path.startswith(sysroot): + if path.startswith(strip_prefix): + path = path[len(strip_prefix):] + path = path.lstrip('/') + return os.path.join(sysroot, path) + else: + return path + + +def main(): + parser = OptionParser() + parser.add_option('-d', '--debug', action='store_true') + parser.add_option('-p', action='store', dest='pkg_config', type='string', + default='pkg-config') + parser.add_option('-v', action='append', dest='strip_out', type='string') + parser.add_option('-s', action='store', dest='sysroot', type='string') + parser.add_option('-a', action='store', dest='arch', type='string') + parser.add_option('--system_libdir', action='store', dest='system_libdir', + type='string', default='lib') + parser.add_option('--atleast-version', action='store', + dest='atleast_version', type='string') + parser.add_option('--libdir', action='store_true', dest='libdir') + parser.add_option('--dridriverdir', action='store_true', dest='dridriverdir') + parser.add_option('--version-as-components', action='store_true', + dest='version_as_components') + (options, args) = parser.parse_args() + + # Make a list of regular expressions to strip out. + strip_out = [] + if options.strip_out != None: + for regexp in options.strip_out: + strip_out.append(re.compile(regexp)) + + if options.sysroot: + libdir = SetConfigPath(options) + if options.debug: + sys.stderr.write('PKG_CONFIG_LIBDIR=%s\n' % libdir) + prefix = GetPkgConfigPrefixToStrip(options, args) + else: + prefix = '' + + if options.atleast_version: + # When asking for the return value, just run pkg-config and print the return + # value, no need to do other work. + if not subprocess.call([options.pkg_config, + "--atleast-version=" + options.atleast_version] + + args): + print("true") + else: + print("false") + return 0 + + if options.version_as_components: + cmd = [options.pkg_config, "--modversion"] + args + try: + version_string = subprocess.check_output(cmd).decode('utf-8') + except Exception: + sys.stderr.write('Error from pkg-config.\n') + return 1 + print(json.dumps(list(map(int, version_string.strip().split("."))))) + return 0 + + + if options.libdir: + cmd = [options.pkg_config, "--variable=libdir"] + args + if options.debug: + sys.stderr.write('Running: %s\n' % cmd) + try: + libdir = subprocess.check_output(cmd).decode('utf-8') + except Exception: + print("Error from pkg-config.") + return 1 + sys.stdout.write(libdir.strip()) + return 0 + + if options.dridriverdir: + cmd = [options.pkg_config, "--variable=dridriverdir"] + args + if options.debug: + sys.stderr.write('Running: %s\n' % cmd) + try: + dridriverdir = subprocess.check_output(cmd).decode('utf-8') + except Exception: + print("Error from pkg-config.") + return 1 + sys.stdout.write(dridriverdir.strip()) + return + + cmd = [options.pkg_config, "--cflags", "--libs"] + args + if options.debug: + sys.stderr.write('Running: %s\n' % ' '.join(cmd)) + + try: + flag_string = subprocess.check_output(cmd).decode('utf-8') + except Exception: + sys.stderr.write('Could not run pkg-config.\n') + return 1 + + # For now just split on spaces to get the args out. This will break if + # pkgconfig returns quoted things with spaces in them, but that doesn't seem + # to happen in practice. + all_flags = flag_string.strip().split(' ') + + + sysroot = options.sysroot + if not sysroot: + sysroot = '' + + includes = [] + cflags = [] + libs = [] + lib_dirs = [] + + for flag in all_flags[:]: + if len(flag) == 0 or MatchesAnyRegexp(flag, strip_out): + continue; + + if flag[:2] == '-l': + libs.append(RewritePath(flag[2:], prefix, sysroot)) + elif flag[:2] == '-L': + lib_dirs.append(RewritePath(flag[2:], prefix, sysroot)) + elif flag[:2] == '-I': + includes.append(RewritePath(flag[2:], prefix, sysroot)) + elif flag[:3] == '-Wl': + # Don't allow libraries to control ld flags. These should be specified + # only in build files. + pass + elif flag == '-pthread': + # Many libs specify "-pthread" which we don't need since we always include + # this anyway. Removing it here prevents a bunch of duplicate inclusions + # on the command line. + pass + else: + cflags.append(flag) + + # Output a GN array, the first one is the cflags, the second are the libs. The + # JSON formatter prints GN compatible lists when everything is a list of + # strings. + print(json.dumps([includes, cflags, libs, lib_dirs])) + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/gn/build/config/linux/pkg_config.gni b/gn/build/config/linux/pkg_config.gni new file mode 100644 index 00000000000000..e44bc2541d50a3 --- /dev/null +++ b/gn/build/config/linux/pkg_config.gni @@ -0,0 +1,115 @@ +# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# Copyright (c) 2020 Project CHIP Authors +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# Defines a config specifying the result of running pkg-config for the given +# packages. Put the package names you want to query in the "packages" variable +# inside the template invocation. +# +# You can also add defines via the "defines" variable. This can be useful to +# add this to the config to pass defines that the library expects to get by +# users of its headers. +# +# Example: +# pkg_config("mything") { +# packages = [ "mything1", "mything2" ] +# defines = [ "ENABLE_AWESOME" ] +# } +# +# You can also use "extra args" to filter out results (see pkg-config.py): +# extra_args = [ "-v, "foo" ] +# To ignore libs and ldflags (only cflags/defines will be set, which is useful +# when doing manual dynamic linking), set: +# ignore_libs = true + +declare_args() { + # A pkg-config wrapper to call instead of trying to find and call the right + # pkg-config directly. Wrappers like this are common in cross-compilation + # environments. + # Leaving it blank defaults to searching PATH for 'pkg-config' and relying on + # the sysroot mechanism to find the right .pc files. + pkg_config = "" + + # A optional pkg-config wrapper to use for tools built on the host. + host_pkg_config = "" +} + +pkg_config_script = "//build/config/linux/pkg-config.py" + +# Define the args we pass to the pkg-config script for other build files that +# need to invoke it manually. +pkg_config_args = [] + +if (pkg_config != "") { + pkg_config_args += [ + "-p", + pkg_config, + ] +} + +if (host_pkg_config != "") { + host_pkg_config_args = [ + "-p", + host_pkg_config, + ] +} else { + host_pkg_config_args = pkg_config_args +} + +template("pkg_config") { + assert(defined(invoker.packages), + "Variable |packages| must be defined to be a list in pkg_config.") + config(target_name) { + if (host_toolchain == current_toolchain) { + args = host_pkg_config_args + invoker.packages + } else { + args = pkg_config_args + invoker.packages + } + if (defined(invoker.extra_args)) { + args += invoker.extra_args + } + + pkgresult = exec_script(pkg_config_script, args, "value") + cflags = pkgresult[1] + + foreach(include, pkgresult[0]) { + cflags += [ "-I$include" ] + } + + if (!defined(invoker.ignore_libs) || !invoker.ignore_libs) { + libs = pkgresult[2] + lib_dirs = pkgresult[3] + } + + forward_variables_from(invoker, + [ + "defines", + "visibility", + ]) + } +} diff --git a/gn/build/toolchain/arm_gcc/BUILD.gn b/gn/build/toolchain/arm_gcc/BUILD.gn new file mode 100644 index 00000000000000..2edca649611cef --- /dev/null +++ b/gn/build/toolchain/arm_gcc/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright 2020 The Pigweed Authors +# Copyright (c) 2020 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("arm_toolchain.gni") + +arm_toolchain("arm_gcc") { +} diff --git a/gn/build/toolchain/arm_gcc/arm_toolchain.gni b/gn/build/toolchain/arm_gcc/arm_toolchain.gni new file mode 100644 index 00000000000000..3db265f9e9d6a6 --- /dev/null +++ b/gn/build/toolchain/arm_gcc/arm_toolchain.gni @@ -0,0 +1,44 @@ +# Copyright (c) 2020 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/pigweed.gni") +import("$dir_pw_toolchain/generate_toolchain.gni") + +template("arm_toolchain") { + _arm_gcc_toolchain_tools = { + _tool_name_root = "arm-none-eabi-" + ar = _tool_name_root + "ar" + cc = _tool_name_root + "gcc" + cxx = _tool_name_root + "g++" + } + + _toolchain = { + name = target_name + forward_variables_from(_arm_gcc_toolchain_tools, "*") + defaults = { + current_cpu = "arm" + current_os = invoker.current_os + + if (defined(invoker.toolchain_args_file)) { + import(invoker.toolchain_args_file) + } else if (defined(invoker.defaults)) { + forward_variables_from(invoker.defaults, "*") + } + } + } + + generate_toolchains("host_toolchains") { + toolchains = [ _toolchain ] + } +} diff --git a/gn/build/toolchain/host_clang/BUILD.gn b/gn/build/toolchain/host_clang/BUILD.gn new file mode 100644 index 00000000000000..10912d5b8f7546 --- /dev/null +++ b/gn/build/toolchain/host_clang/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright 2020 The Pigweed Authors +# Copyright (c) 2020 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. + +# gn-format disable +import("//build_overrides/pigweed.gni") + +import("$dir_pw_toolchain/generate_toolchain.gni") +import("toolchains.gni") +generate_toolchains("host_toolchains") { + toolchains = pw_toolchain_host_clang_list +} diff --git a/gn/build/toolchain/host_clang/toolchains.gni b/gn/build/toolchain/host_clang/toolchains.gni new file mode 100644 index 00000000000000..48971f92a9fa7d --- /dev/null +++ b/gn/build/toolchain/host_clang/toolchains.gni @@ -0,0 +1,116 @@ +# Copyright 2020 The Pigweed 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 +# +# https://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. + +# gn-format disable +import("//build_overrides/pigweed.gni") +declare_args() { + # Sets the sanitizer to pass to clang. Valid values are those for "-fsanitize" + # listed in https://clang.llvm.org/docs/UsersManual.html#id9. + pw_toolchain_SANITIZER = "" + + # Indicates if this build is a part of OSS-Fuzz, which needs to be able to + # provide its own compiler and flags. This violates the build hermeticisim and + # should only be used for OSS-Fuzz. + pw_toolchain_OSS_FUZZ_ENABLED = false +} + +# Specifies the tools used by host Clang toolchains. +_host_clang_toolchain = { + # Note: On macOS, there is no "llvm-ar", only "ar", which happens to be LLVM + # ar. This should get updated for linux systems. + ar = "ar" + + if (pw_toolchain_OSS_FUZZ_ENABLED) { + cc = getenv("CC") + cxx = getenv("CXX") + } else { + cc = "clang" + cxx = "clang++" + } + + is_host_toolchain = true + link_group = true +} + +# Common default scope shared by all host Clang toolchains. +_defaults = { + if (pw_toolchain_SANITIZER != "") { + configs += + [ "$dir_pw_toolchain/host_clang:sanitize_$pw_toolchain_SANITIZER" ] + } + if (pw_toolchain_OSS_FUZZ_ENABLED) { + default_configs_fuzzing = oss_fuzz_added_configs + default_configs_fuzzing += [ "$dir_pw_fuzzer:oss_fuzz_extra" ] + + # Add the configs to be removed. They will be de-duplicated, and this + # ensures they are present to be removed. + default_configs += oss_fuzz_removed_configs + remove_configs = oss_fuzz_removed_configs + } +} + +pw_toolchain_host_clang = { + default = { + name = "${host_os}_${host_cpu}_clang" + forward_variables_from(_host_clang_toolchain, "*") + defaults = { + forward_variables_from(_defaults, "*") + current_os = host_os + is_clang = true + } + } + + debug = { + name = "${host_os}_${host_cpu}_clang_debug" + forward_variables_from(_host_clang_toolchain, "*") + defaults = { + forward_variables_from(_defaults, "*") + current_os = host_os + is_clang = true + is_debug = true + } + } + + speed_optimized = { + name = "${host_os}_${host_cpu}_clang_speed_optimized" + forward_variables_from(_host_clang_toolchain, "*") + defaults = { + forward_variables_from(_defaults, "*") + current_os = host_os + is_clang = true + is_debug = false + optimize_for_size = false + } + } + + size_optimized = { + name = "${host_os}_${host_cpu}_clang_size_optimized" + forward_variables_from(_host_clang_toolchain, "*") + defaults = { + forward_variables_from(_defaults, "*") + current_os = host_os + is_clang = true + is_debug = false + optimize_for_size = true + } + } +} + +# Describes host clang toolchains. +pw_toolchain_host_clang_list = [ + pw_toolchain_host_clang.default, + pw_toolchain_host_clang.debug, + pw_toolchain_host_clang.speed_optimized, + pw_toolchain_host_clang.size_optimized, +] diff --git a/gn/build/toolchain/host_gcc/BUILD.gn b/gn/build/toolchain/host_gcc/BUILD.gn new file mode 100644 index 00000000000000..260b08169ac48f --- /dev/null +++ b/gn/build/toolchain/host_gcc/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright 2020 The Pigweed Authors +# Copyright (c) 2020 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. + +# gn-format disable +import("//build_overrides/pigweed.gni") + +import("$dir_pw_toolchain/generate_toolchain.gni") +import("toolchains.gni") +generate_toolchains("host_toolchains") { + toolchains = pw_toolchain_host_gcc_list +} diff --git a/gn/build/toolchain/host_gcc/toolchains.gni b/gn/build/toolchain/host_gcc/toolchains.gni new file mode 100644 index 00000000000000..2a00fdf6b02fc0 --- /dev/null +++ b/gn/build/toolchain/host_gcc/toolchains.gni @@ -0,0 +1,98 @@ +# Copyright 2020 The Pigweed Authors +# Copyright (c) 2020 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. + +# gn-format disable +import("//build_overrides/chip.gni") +import("//build_overrides/pigweed.gni") +_host_gcc_toolchain = { + ar = "ar" + cc = "gcc" + cxx = "g++" + + is_host_toolchain = true + link_group = true +} + +_configs = [ + "$dir_pw_toolchain/host_gcc:disable_psabi_warning", + "$dir_pw_toolchain/host_gcc:mingw_z_format", +] + +pw_toolchain_host_gcc = { + default = { + name = "${host_os}_${host_cpu}_gcc" + forward_variables_from(_host_gcc_toolchain, "*") + defaults = { + default_configs_extra = _configs + current_os = host_os + is_clang = false + } + } + + mbedtls = { + name = "${host_os}_${host_cpu}_gcc_mbedtls" + forward_variables_from(_host_gcc_toolchain, "*") + defaults = { + default_configs_extra = _configs + current_os = host_os + is_clang = false + chip_crypto = "mbedtls" + } + } + + debug = { + name = "${host_os}_${host_cpu}_gcc_debug" + forward_variables_from(_host_gcc_toolchain, "*") + defaults = { + default_configs_extra = _configs + current_os = host_os + is_clang = false + is_debug = true + } + } + + speed_optimized = { + name = "${host_os}_${host_cpu}_gcc_speed_optimized" + forward_variables_from(_host_gcc_toolchain, "*") + defaults = { + default_configs_extra = _configs + current_os = host_os + is_clang = false + is_debug = false + optimize_for_size = false + } + } + + size_optimized = { + name = "${host_os}_${host_cpu}_gcc_size_optimized" + forward_variables_from(_host_gcc_toolchain, "*") + defaults = { + default_configs_extra = _configs + current_os = host_os + is_clang = false + is_debug = false + optimize_for_size = true + } + } +} + +# Describes host Linux GCC toolchains. +pw_toolchain_host_gcc_list = [ + pw_toolchain_host_gcc.default, + pw_toolchain_host_gcc.mbedtls, + pw_toolchain_host_gcc.debug, + pw_toolchain_host_gcc.speed_optimized, + pw_toolchain_host_gcc.size_optimized, +] diff --git a/gn/build_overrides/chip.gni b/gn/build_overrides/chip.gni new file mode 100644 index 00000000000000..26ac4812c0f797 --- /dev/null +++ b/gn/build_overrides/chip.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for CHIP. + chip_root = "//" +} diff --git a/gn/build_overrides/lwip.gni b/gn/build_overrides/lwip.gni new file mode 100644 index 00000000000000..a0a68d95a11dee --- /dev/null +++ b/gn/build_overrides/lwip.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for lwIP. + lwip_root = "//third_party/lwip" +} diff --git a/gn/build_overrides/mbedtls.gni b/gn/build_overrides/mbedtls.gni new file mode 100644 index 00000000000000..04f377ed99eabc --- /dev/null +++ b/gn/build_overrides/mbedtls.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for mbedTLS. + mbedtls_root = "//third_party/mbedtls" +} diff --git a/gn/build_overrides/nlassert.gni b/gn/build_overrides/nlassert.gni new file mode 100644 index 00000000000000..e54060eb3aba06 --- /dev/null +++ b/gn/build_overrides/nlassert.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nlassert. + nlassert_root = "//third_party/nlassert" +} diff --git a/gn/build_overrides/nlfaultinjection.gni b/gn/build_overrides/nlfaultinjection.gni new file mode 100644 index 00000000000000..581ba58ee5851e --- /dev/null +++ b/gn/build_overrides/nlfaultinjection.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nlfaultinjection. + nlfaultinjection_root = "//third_party/nlfaultinjection" +} diff --git a/gn/build_overrides/nlio.gni b/gn/build_overrides/nlio.gni new file mode 100644 index 00000000000000..c7f7ce61eb28f2 --- /dev/null +++ b/gn/build_overrides/nlio.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nlio. + nlio_root = "//third_party/nlio" +} diff --git a/gn/build_overrides/nlunit_test.gni b/gn/build_overrides/nlunit_test.gni new file mode 100644 index 00000000000000..b3b729504b1be1 --- /dev/null +++ b/gn/build_overrides/nlunit_test.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nlunit-test. + nlunit_test_root = "//third_party/nlunit-test" +} diff --git a/gn/build_overrides/nrf5_lock_app.gni b/gn/build_overrides/nrf5_lock_app.gni new file mode 100644 index 00000000000000..ecb6a4c5f45c74 --- /dev/null +++ b/gn/build_overrides/nrf5_lock_app.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nRF5 lock app example. + nrf5_lock_app_root = "//examples/lock-app/nrf5" +} diff --git a/gn/build_overrides/nrf5_sdk.gni b/gn/build_overrides/nrf5_sdk.gni new file mode 100644 index 00000000000000..f9422dc9eb319c --- /dev/null +++ b/gn/build_overrides/nrf5_sdk.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Root directory for nRF5 SDK build files. + nrf5_sdk_build_root = "//third_party/nrf5_sdk" +} diff --git a/gn/build_overrides/pigweed.gni b/gn/build_overrides/pigweed.gni new file mode 100644 index 00000000000000..2ef577a00aa734 --- /dev/null +++ b/gn/build_overrides/pigweed.gni @@ -0,0 +1,20 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Location of the Pigweed repository. + dir_pigweed = "//third_party/pigweed" +} + +import("$dir_pigweed/modules.gni") diff --git a/gn/chip/chip_build.gni b/gn/chip/chip_build.gni new file mode 100644 index 00000000000000..3b46a74fb574f1 --- /dev/null +++ b/gn/chip/chip_build.gni @@ -0,0 +1,32 @@ +# Copyright (c) 2020 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}/gn/chip/tests.gni") + +template("chip_build") { + _build_name = target_name + _toolchain = invoker.toolchain + + group("all_${_build_name}") { + deps = [ ":all(${_toolchain})" ] + } + + if (chip_build_tests) { + group("check_${_build_name}") { + deps = [ ":check(${_toolchain})" ] + } + } +} diff --git a/gn/chip/chip_test.gni b/gn/chip/chip_test.gni new file mode 100644 index 00000000000000..7650782dc67d5a --- /dev/null +++ b/gn/chip/chip_test.gni @@ -0,0 +1,48 @@ +# Copyright (c) 2020 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("//build_overrides/pigweed.gni") + +import("${chip_root}/gn/chip/tests.gni") +import("${dir_pw_unit_test}/test.gni") + +assert(chip_build_tests) + +template("chip_test") { + _test_name = target_name + + _test_output_dir = "${root_out_dir}/tests" + if (defined(invoker.output_dir)) { + _test_output_dir = invoker.output_dir + } + + executable(_test_name) { + forward_variables_from(invoker, "*", [ "output_dir" ]) + output_dir = _test_output_dir + } + + pw_python_script(_test_name + "_run") { + deps = [ ":${_test_name}" ] + inputs = [ pw_unit_test_AUTOMATIC_RUNNER ] + script = "$dir_pw_unit_test/py/pw_unit_test/test_runner.py" + args = [ + "--runner", + pw_unit_test_AUTOMATIC_RUNNER, + "--test", + get_path_info("$_test_output_dir:$_test_name", "abspath"), + ] + stamp = true + } +} diff --git a/gn/chip/chip_test_group.gni b/gn/chip/chip_test_group.gni new file mode 100644 index 00000000000000..dd7bf31d3471db --- /dev/null +++ b/gn/chip/chip_test_group.gni @@ -0,0 +1,34 @@ +# Copyright (c) 2020 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}/gn/chip/tests.gni") + +assert(chip_build_tests) + +template("chip_test_group") { + _test_group_name = target_name + + group("${_test_group_name}") { + deps = invoker.deps + } + + group("${_test_group_name}_run") { + deps = [] + foreach(_test, invoker.deps) { + deps += [ get_label_info(_test, "label_no_toolchain") + "_run" ] + } + } +} diff --git a/gn/chip/chip_test_suite.gni b/gn/chip/chip_test_suite.gni new file mode 100644 index 00000000000000..dc7d0cd3c4a6e3 --- /dev/null +++ b/gn/chip/chip_test_suite.gni @@ -0,0 +1,73 @@ +# Copyright (c) 2020 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}/gn/chip/chip_test.gni") +import("${chip_root}/gn/chip/tests.gni") +import("${dir_pw_unit_test}/test.gni") + +assert(chip_build_tests) + +template("chip_test_suite") { + _suite_name = target_name + + static_library("${_suite_name}_common") { + forward_variables_from(invoker, + "*", + [ + "tests", + "c_tests", + ]) + } + + tests = [] + if (defined(invoker.tests)) { + foreach(_test, invoker.tests) { + chip_test(_test) { + sources = [ "${_test}Driver.cpp" ] + + public_deps = [ ":${_suite_name}_common" ] + } + + tests += [ _test ] + } + } + + if (defined(invoker.c_tests)) { + foreach(_test, invoker.c_tests) { + chip_test(_test) { + sources = [ "${_test}Driver.c" ] + + public_deps = [ ":${_suite_name}_common" ] + } + + tests += [ _test ] + } + } + + group(_suite_name) { + deps = [] + foreach(_test, tests) { + deps += [ ":${_test}" ] + } + } + + group("${_suite_name}_run") { + deps = [] + foreach(_test, tests) { + deps += [ ":${_test}_run" ] + } + } +} diff --git a/gn/chip/chip_version.gni b/gn/chip/chip_version.gni new file mode 100644 index 00000000000000..e461af388a8ed9 --- /dev/null +++ b/gn/chip/chip_version.gni @@ -0,0 +1,29 @@ +# Copyright (c) 2020 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") + +declare_args() { + # CHIP major version number. + chip_version_major = 0 + + # CHIP minor version number. + chip_version_minor = 0 + + # CHIP patch version number. + chip_version_patch = 0 + + # CHIP extra version string. + chip_version_extra = "" +} diff --git a/gn/chip/device.gni b/gn/chip/device.gni new file mode 100644 index 00000000000000..5bdddee5c68177 --- /dev/null +++ b/gn/chip/device.gni @@ -0,0 +1,28 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Device platform layer: freertos, nrf5, none. + device_platform = "" +} + +if (device_platform == "") { + if (current_os != "freertos") { + device_platform = "none" + } +} + +assert((current_os != "freertos" && device_platform == "none") || + device_platform == "nrf5", + "Please select a valid value for device_platform") diff --git a/gn/chip/tests.gni b/gn/chip/tests.gni new file mode 100644 index 00000000000000..4e4e3455b758d0 --- /dev/null +++ b/gn/chip/tests.gni @@ -0,0 +1,21 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Enable building tests. + chip_build_tests = current_os != "freertos" + + # Enable use of nlfaultinjection. + chip_with_nlfaultinjection = true +} diff --git a/gn/chip/tools.gni b/gn/chip/tools.gni new file mode 100644 index 00000000000000..6c9d4eab7739f4 --- /dev/null +++ b/gn/chip/tools.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Build CHIP tools. + chip_build_tools = current_os != "freertos" +} diff --git a/gn_build.sh b/gn_build.sh new file mode 100755 index 00000000000000..88bd9781f44d0e --- /dev/null +++ b/gn_build.sh @@ -0,0 +1,92 @@ +#!/bin/bash -e +# +# Copyright (c) 2020 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. +# + +CHIP_ROOT="$(dirname "$0")" + +_chip_red() { + echo -e "\033[0;31m$*\033[0m" +} + +_chip_yellow() { + echo -e "\033[0;33m$*\033[0m" +} + +_chip_banner() { + _chip_yellow '.--------------------------------' + _chip_yellow "-- $1" + _chip_yellow "'--------------------------------" +} + +_chip_banner "Environment bringup" + +git -C "$CHIP_ROOT" submodule update --init + +set +e +source "$CHIP_ROOT/scripts/activate.sh" +set -e + +_chip_banner "Build: GN configure" + +nrf5_sdk_args="" +extra_args="" + +if [[ -d "$NRF5_SDK_ROOT/components/libraries" ]]; then + nrf5_sdk_args+="nrf5_sdk_root=\"$NRF5_SDK_ROOT\"" + extra_args+=" $nrf5_sdk_args enable_nrf5_lock_app_build=true" +fi + +gn --root="$CHIP_ROOT" gen --check "$CHIP_ROOT/out/debug" --args='target_os="all"'"$extra_args" +gn --root="$CHIP_ROOT" gen --check "$CHIP_ROOT/out/release" --args='target_os="all" is_debug=false'"$extra_args" + +_chip_banner "Build: Ninja build" + +time ninja -C "$CHIP_ROOT/out/debug" check + +echo +echo 'To activate existing build environment in your shell, run (do this first):' +echo source "$CHIP_ROOT/scripts/activate.sh" + +echo +echo 'To re-create the build environment from scratch, run:' +echo source "$CHIP_ROOT/scripts/bootstrap.sh" + +echo +echo 'To build a debug build:' +echo gn gen "$CHIP_ROOT/out/debug" --args=\''target_os="all"'"$extra_args"\' +echo ninja -C "$CHIP_ROOT/out/debug" + +echo +echo 'To run tests (idempotent):' +echo ninja -C "$CHIP_ROOT/out/debug" check + +echo +echo 'To build & test an optimized build:' +echo gn gen "$CHIP_ROOT/out/release" --args=\''target_os="all" is_debug=false'"$extra_args"\' +echo ninja -C "$CHIP_ROOT/out/release" check + +echo +echo 'To build a custom build (for help run "gn args --list out/debug")' +echo gn args "$CHIP_ROOT/out/custom" +echo ninja -C "$CHIP_ROOT/out/custom" + +echo +if [[ ! -d "$NRF5_SDK_ROOT/components/libraries" ]]; then + echo "Hint: Set \$NRF5_SDK_ROOT to enable building for nRF5" +else + echo 'To build the nRF5 lock sample as a standalone project': + echo "(cd $CHIP_ROOT/examples/lock-app/nrf5; gn gen out/debug --args='$nrf5_sdk_args'; ninja -C out/debug)" +fi diff --git a/repos.conf b/repos.conf deleted file mode 100644 index fecf19b5b20739..00000000000000 --- a/repos.conf +++ /dev/null @@ -1,45 +0,0 @@ -[submodule "nlassert"] - path = third_party/nlassert/repo - url = https://github.com/nestlabs/nlassert.git - branch = master - update = none -[submodule "nlfaultinjection"] - path = third_party/nlfaultinjection/repo - url = https://github.com/nestlabs/nlfaultinjection.git - branch = master - update = none -[submodule "nlio"] - path = third_party/nlio/repo - url = https://github.com/nestlabs/nlio.git - branch = master - update = none -[submodule "nlunit-test"] - path = third_party/nlunit-test/repo - url = https://github.com/nestlabs/nlunit-test.git - branch = master - update = none -[submodule "mbedtls"] - path = third_party/mbedtls/repo - url = https://github.com/ARMmbed/mbedtls.git - branch = mbedtls-2.18 - update = none -[submodule "qrcode"] - path = examples/common/QRCode/repo - url = https://github.com/nayuki/QR-Code-generator.git - branch = master - update = none -[submodule "m5stack-tft"] - path = examples/common/m5stack-tft/repo - url = https://github.com/jeremyjh/ESP32_TFT_library.git - branch = master - update = none -[submodule "openthread"] - path = third_party/openthread/repo - url = https://github.com/openthread/openthread.git - branch = master - update = none -[submodule "ot-br-posix"] - path = third_party/ot-br-posix/repo - url = https://github.com/openthread/ot-br-posix.git - branch = master - update = none diff --git a/repos.conf b/repos.conf new file mode 120000 index 00000000000000..7837f9c220680c --- /dev/null +++ b/repos.conf @@ -0,0 +1 @@ +.gitmodules \ No newline at end of file diff --git a/activate.sh b/scripts/activate.sh similarity index 91% rename from activate.sh rename to scripts/activate.sh index 8d65e052abfbe6..69953ce1d30a6f 100644 --- a/activate.sh +++ b/scripts/activate.sh @@ -14,7 +14,9 @@ # limitations under the License. # -CHIP_ROOT="$(dirname "$0")" +if [[ ! -d "${CHIP_ROOT}" ]]; then + CHIP_ROOT="$(dirname "$0")/.." +fi export PW_BRANDING_BANNER="$CHIP_ROOT/.chip-banner.txt" export PW_BRANDING_BANNER_COLOR="bold_white" diff --git a/bootstrap.sh b/scripts/bootstrap.sh similarity index 96% rename from bootstrap.sh rename to scripts/bootstrap.sh index b682aa75023969..9ed9a85bc0304c 100644 --- a/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -14,7 +14,7 @@ # limitations under the License. # -CHIP_ROOT="$(dirname "$0")" +CHIP_ROOT="$(dirname "$0")/.." export PW_BRANDING_BANNER="$CHIP_ROOT/.chip-banner.txt" export PW_BRANDING_BANNER_COLOR="bold_white" diff --git a/scripts/build/gn_bootstrap.sh b/scripts/build/gn_bootstrap.sh new file mode 100755 index 00000000000000..f7a8a0516db4bb --- /dev/null +++ b/scripts/build/gn_bootstrap.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2020 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. +# + +# Bootstrap script for GN build GitHub workflow. + +# This is used to account bootstrap time in a dedicated workflow step; there's +# no need to use this script locally. + +CHIP_ROOT="$(dirname "$0")/../.." + +source "$CHIP_ROOT/scripts/activate.sh" diff --git a/scripts/build/gn_build.sh b/scripts/build/gn_build.sh new file mode 100755 index 00000000000000..55f5d81b7a66c0 --- /dev/null +++ b/scripts/build/gn_build.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2020 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. +# + +# Build script for GN build GitHub workflow. + +CHIP_ROOT="$(dirname "$0")/../.." + +source "$CHIP_ROOT/scripts/activate.sh" + +set -e +set -x +env + +ninja -v -C "$CHIP_ROOT/out/$BUILD_TYPE" diff --git a/scripts/build/gn_gen.sh b/scripts/build/gn_gen.sh new file mode 100755 index 00000000000000..1fe94aef334343 --- /dev/null +++ b/scripts/build/gn_gen.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2020 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. +# + +# GN gen script for GN build GitHub workflow. + +CHIP_ROOT="$(dirname "$0")/../.." + +source "$CHIP_ROOT/scripts/activate.sh" + +set -e +set -x +env + +gn --root="$CHIP_ROOT" gen --check "$CHIP_ROOT/out/$BUILD_TYPE" "$@" diff --git a/scripts/gen_chip_version.py b/scripts/gen_chip_version.py new file mode 100755 index 00000000000000..36348f6be4e9f3 --- /dev/null +++ b/scripts/gen_chip_version.py @@ -0,0 +1,231 @@ +#!/usr/bin/env python + +# Copyright (c) 2020 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 optparse +import sys + +TEMPLATE = '''/* + * + * Copyright (c) 2020 Project CHIP Authors + * All rights reserved. + * + * 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. + */ + +/** + * \@file + * This file defines constants and macros for introspecting and + * manipulating CHIP versions. + * + * !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! + * + * DO NOT EDIT THIS FILE! This file is automatically-generated by + * the '${program}' script. + * + * The constants and macros defined here may be used to, for , + * example, conditionally-compile older, newer, or changed CHIP + * APIs based on the CHIP version. For example: + * + * \@code + * #if CHIP_VERSION_CODE >= CHIP_VERSION_CODE_ENCODE(1, 5, 0) + * ... + * #else + * ... + * #endif + * \@endcode + * + */ + +#ifndef CHIP_VERSION_H_ +#define CHIP_VERSION_H_ + +#define _CHIP_VERSION_CODE_MAJOR_WIDTH 8 +#define _CHIP_VERSION_CODE_MINOR_WIDTH 8 +#define _CHIP_VERSION_CODE_PATCH_WIDTH 8 + +#define _CHIP_VERSION_CODE_MAJOR_MASK ((1 << _CHIP_VERSION_CODE_MAJOR_WIDTH) - 1) +#define _CHIP_VERSION_CODE_MINOR_MASK ((1 << _CHIP_VERSION_CODE_MINOR_WIDTH) - 1) +#define _CHIP_VERSION_CODE_PATCH_MASK ((1 << _CHIP_VERSION_CODE_PATCH_WIDTH) - 1) + +#define _CHIP_VERSION_CODE_MAJOR_SHIFT 24 +#define _CHIP_VERSION_CODE_MINOR_SHIFT 16 +#define _CHIP_VERSION_CODE_PATCH_SHIFT 8 + +/** + * \@def CHIP_VERSION_CODE_ENCODE(major, minor, patch) + * + * \@brief + * Encode a CHIP version code from its constituent \@a major, \@a minor, and \@a patch + * components. + * + * This macro may be used in conjunction with CHIP_VERSION_CODE to, for + * example, conditionally-compile older, newer, or changed CHIP APIs based + * on the CHIP version. For example: + * + * \@code + * #if CHIP_VERSION_CODE >= CHIP_VERSION_CODE_ENCODE(1, 5, 0) + * ... + * #else + * ... + * #endif + * \@endcode + * + */ +#define CHIP_VERSION_CODE_ENCODE(major, minor, patch) \\ + ((((major) & _CHIP_VERSION_CODE_MAJOR_MASK) << _CHIP_VERSION_CODE_MAJOR_SHIFT) | \\ + (((minor) & _CHIP_VERSION_CODE_MINOR_MASK) << _CHIP_VERSION_CODE_MINOR_SHIFT) | \\ + (((patch) & _CHIP_VERSION_CODE_PATCH_MASK) << _CHIP_VERSION_CODE_PATCH_SHIFT)) + +/** + * \@def CHIP_VERSION_CODE_DECODE_MAJOR(code) + * + * \@brief + * Decode a CHIP major version component from a CHIP version \@a code. + * + */ +#define CHIP_VERSION_CODE_DECODE_MAJOR(code) (((code) >> _CHIP_VERSION_CODE_MAJOR_SHIFT) & _CHIP_VERSION_CODE_MAJOR_MASK) + +/** + * \@def CHIP_VERSION_CODE_DECODE_MINOR(code) + * + * \@brief + * Decode a CHIP minor version component from a CHIP version \@a code. + * + */ +#define CHIP_VERSION_CODE_DECODE_MINOR(code) (((code) >> _CHIP_VERSION_CODE_MINOR_SHIFT) & _CHIP_VERSION_CODE_MINOR_MASK) + +/** + * \@def CHIP_VERSION_CODE_DECODE_PATCH(code) + * + * \@brief + * Decode a CHIP patch version component from a CHIP version \@a code. + * + */ +#define CHIP_VERSION_CODE_DECODE_PATCH(code) (((code) >> _CHIP_VERSION_CODE_PATCH_SHIFT) & _CHIP_VERSION_CODE_PATCH_MASK) + +/** + * \@def CHIP_VERSION_MAJOR + * + * \@brief + * The CHIP version major component, as an unsigned integer. + * + */ +#define CHIP_VERSION_MAJOR %(chip_major)d + +/** + * \@def CHIP_VERSION_MINOR + * + * \@brief + * The CHIP version minor component, as an unsigned integer. + * + */ +#define CHIP_VERSION_MINOR %(chip_minor)d + +/** + * \@def CHIP_VERSION_PATCH + * + * \@brief + * The CHIP version patch component, as an unsigned integer. + * + */ +#define CHIP_VERSION_PATCH %(chip_patch)d + +/** + * \@def CHIP_VERSION_EXTRA + * + * \@brief + * The CHIP version extra component, as a quoted C string. + * + */ +#define CHIP_VERSION_EXTRA \"%(chip_extra)s\" + +/** + * \@def CHIP_VERSION_STRING + * + * \@brief + * The CHIP version, as a quoted C string. + * + */ +#define CHIP_VERSION_STRING \"%(chip_version)s\" + +/** + * \@def CHIP_VERSION_CODE + * + * \@brief + * The CHIP version, including the major, minor, and patch components, + * encoded as an unsigned integer. + * + * This macro may be used in conjunction with CHIP_VERSION_CODE_ENCODE + * to, for example, conditionally-compile older, newer, or changed CHIP + * APIs based on the CHIP version. For example: + * + * \@code + * #if CHIP_VERSION_CODE >= CHIP_VERSION_CODE_ENCODE(1, 5, 0) + * ... + * #else + * ... + * #endif + * \@endcode + * + */ +#define CHIP_VERSION_CODE CHIP_VERSION_CODE_ENCODE( \\ + CHIP_VERSION_MAJOR, \\ + CHIP_VERSION_MINOR, \\ + CHIP_VERSION_PATCH \\ + ) + +#endif /* CHIP_VERSION_H_ */ +''' + + +def main(argv): + parser = optparse.OptionParser() + + parser.add_option('--output_file') + parser.add_option('--chip_major', type=int, default=0) + parser.add_option('--chip_minor', type=int, default=0) + parser.add_option('--chip_patch', type=int, default=0) + parser.add_option('--chip_extra', type=str, default='') + + options, _ = parser.parse_args(argv) + + template_args = { + 'chip_major': options.chip_major, + 'chip_minor': options.chip_minor, + 'chip_patch': options.chip_patch, + 'chip_extra': options.chip_extra, + } + + template_args['chip_version'] = '%d.%d.%d%s' % (options.chip_major, options.chip_minor, options.chip_patch, options.chip_extra) + + with open(options.output_file, 'w') as chip_version_file: + chip_version_file.write(TEMPLATE % template_args) + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/scripts/tests/gn_tests.sh b/scripts/tests/gn_tests.sh new file mode 100755 index 00000000000000..c19b13c1f82402 --- /dev/null +++ b/scripts/tests/gn_tests.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# +# Copyright (c) 2020 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. +# + +# Test script for GN GitHub workflow. + +CHIP_ROOT="$(dirname "$0")/../.." + +source "$CHIP_ROOT/scripts/activate.sh" + +set -e +set -x +env + +ninja -v -C "$CHIP_ROOT/out/$BUILD_TYPE" check diff --git a/src/BUILD.gn b/src/BUILD.gn new file mode 100644 index 00000000000000..92d1b43b02e939 --- /dev/null +++ b/src/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright (c) 2020 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") + +config("public_includes") { + include_dirs = [ "include" ] +} + +config("includes") { + include_dirs = [ "." ] + + configs = [ ":public_includes" ] +} diff --git a/src/app/BUILD.gn b/src/app/BUILD.gn new file mode 100644 index 00000000000000..d8bf6362474134 --- /dev/null +++ b/src/app/BUILD.gn @@ -0,0 +1,88 @@ +# Copyright (c) 2020 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") + +config("app_config") { + include_dirs = [ + "gen", + "chip-zcl", + ".", + ] +} + +static_library("common") { + output_name = "libCHIPDataModelCommon" + + sources = [ + "chip-zcl/chip-zcl-buffer.h", + "chip-zcl/chip-zcl-codec.h", + "chip-zcl/chip-zcl-struct.h", + "chip-zcl/chip-zcl.h", + "gen/gen-attribute-storage.h", + "gen/gen-attribute-type.h", + "gen/gen-callback-stubs.c", + "gen/gen-callbacks.h", + "gen/gen-cluster-id.h", + "gen/gen-command-handler.c", + "gen/gen-command-handler.h", + "gen/gen-command-id.h", + "gen/gen-endpoint-config.h", + "gen/gen-global-command-handler.c", + "gen/gen-global-command-handler.h", + "gen/gen-specs.c", + "gen/gen-types.h", + "gen/gen.h", + "plugin/cluster-server-basic/basic-server.c", + "plugin/cluster-server-identify/identify-server.c", + "plugin/cluster-server-level-control/level-control-server-tokens.h", + "plugin/cluster-server-level-control/level-control-server.c", + "plugin/cluster-server-level-control/level-control-server.h", + "plugin/cluster-server-on-off/on-off-server-tokens.h", + "plugin/cluster-server-on-off/on-off-server.c", + "plugin/cluster-server-on-off/on-off-server.h", + "plugin/codec-simple/codec-simple.c", + "plugin/core-api/core-api.c", + "plugin/core-data-model/zcl-data-model.c", + "plugin/core-message-dispatch/dispatch.c", + "plugin/core-message-dispatch/dispatch.h", + ] + + public_deps = [ + "${chip_root}/src/lib/support", + "${chip_root}/src/system", + ] + + public_configs = [ ":app_config" ] +} + +static_library("chip") { + output_name = "libCHIPDataModel" + + sources = [ "plugin/binding-chip/chip.cpp" ] + + public_deps = [ ":common" ] +} + +static_library("mock") { + output_name = "libCHIPDataModelMock" + + sources = [ "plugin/binding-mock/mock.c" ] + + public_deps = [ ":common" ] +} + +group("app") { + public_deps = [ ":chip" ] +} diff --git a/src/app/plugin/tests/BUILD.gn b/src/app/plugin/tests/BUILD.gn new file mode 100644 index 00000000000000..515dc51e2681ff --- /dev/null +++ b/src/app/plugin/tests/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (c) 2020 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("//build_overrides/nlunit_test.gni") + +import("${chip_root}/gn/chip/chip_test_suite.gni") + +chip_test_suite("tests") { + output_name = "libChipZclUnitTests" + + sources = [ + "ChipZclUnitTests.h", + "cluster-cmd-on-off-test.c", + "cluster-server-basic-test.c", + "cluster-server-identify-test.c", + "cluster-server-level-control-test.c", + "cluster-server-on-off-test.c", + "codec-simple-test.c", + "core-data-model-test.c", + "core-message-dispatch-test.c", + ] + + public_deps = [ + "${chip_root}/src/app:mock", + "${chip_root}/src/inet", + "${chip_root}/src/system", + "${nlunit_test_root}:nlunit-test", + ] + + public_configs = [ "${chip_root}/src/app:app_config" ] + + c_tests = [ "ChipZclUnitTests" ] +} diff --git a/src/ble/BUILD.gn b/src/ble/BUILD.gn new file mode 100644 index 00000000000000..52d5f503b39836 --- /dev/null +++ b/src/ble/BUILD.gn @@ -0,0 +1,79 @@ +# Copyright (c) 2020 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("ble.gni") + +declare_args() { + # Extra header to include in BleConfig.h for project. + ble_project_config_include = "" + + # Extra header to include in BleConfig.h for platform. + ble_platform_config_include = "" +} + +config("ble_config") { + configs = [ "${chip_root}/src:includes" ] + + defines = [] + if (ble_project_config_include != "") { + defines += [ "BLE_PROJECT_CONFIG_INCLUDE=${ble_project_config_include}" ] + } + if (ble_platform_config_include != "") { + defines += [ "BLE_PLATFORM_CONFIG_INCLUDE=${ble_platform_config_include}" ] + } + + if (config_network_layer_ble) { + defines += [ "CONFIG_NETWORK_LAYER_BLE=1" ] + } else { + defines += [ "CONFIG_NETWORK_LAYER_BLE=0" ] + } +} + +source_set("ble_config_header") { + sources = [ "BleConfig.h" ] + + public_configs = [ ":ble_config" ] + + public_deps = [ "${chip_root}/src/system:system_config_header" ] +} + +static_library("ble") { + output_name = "libBleLayer" + + sources = [ + "BLEEndPoint.cpp", + "BLEEndPoint.h", + "Ble.h", + "BleApplicationDelegate.h", + "BleConfig.h", + "BleError.cpp", + "BleError.h", + "BleLayer.cpp", + "BleLayer.h", + "BlePlatformDelegate.h", + "BleUUID.cpp", + "BleUUID.h", + "BtpEngine.cpp", + "BtpEngine.h", + "CHIPBleServiceData.h", + ] + + public_deps = [ + ":ble_config_header", + "${chip_root}/src/inet", + "${chip_root}/src/lib/support", + ] +} diff --git a/src/ble/ble.gni b/src/ble/ble.gni new file mode 100644 index 00000000000000..f532ab579ecda5 --- /dev/null +++ b/src/ble/ble.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Enable BLE support. + config_network_layer_ble = true +} diff --git a/src/ble/tests/BUILD.gn b/src/ble/tests/BUILD.gn new file mode 100644 index 00000000000000..30fa07a35c2acc --- /dev/null +++ b/src/ble/tests/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2020 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("//build_overrides/nlunit_test.gni") + +import("${chip_root}/gn/chip/chip_test_suite.gni") + +chip_test_suite("tests") { + output_name = "libBleLayerTests" + + sources = [ + "TestBleErrorStr.cpp", + "TestBleLayer.h", + ] + + public_deps = [ + "${chip_root}/src/ble", + "${nlunit_test_root}:nlunit-test", + ] + + tests = [ "TestBleErrorStr" ] +} diff --git a/src/controller/BUILD.gn b/src/controller/BUILD.gn new file mode 100644 index 00000000000000..a52a68f71fe180 --- /dev/null +++ b/src/controller/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 2020 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") + +static_library("controller") { + output_name = "libChipController" + + sources = [ + "CHIPDeviceController.cpp", + "CHIPDeviceController.h", + ] + + public_deps = [ + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + "${chip_root}/src/transport", + ] +} diff --git a/src/crypto/BUILD.gn b/src/crypto/BUILD.gn new file mode 100644 index 00000000000000..f6636b307ce2d9 --- /dev/null +++ b/src/crypto/BUILD.gn @@ -0,0 +1,65 @@ +# Copyright (c) 2020 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("//build_overrides/nlassert.gni") + +import("crypto.gni") + +config("crypto_config") { + defines = [] + if (chip_crypto == "mbedtls") { + defines += [ "CHIP_CRYPTO_MBEDTLS=1" ] + } else { + defines += [ "CHIP_CRYPTO_MBEDTLS=0" ] + } + if (chip_crypto == "openssl") { + defines += [ "CHIP_CRYPTO_OPENSSL=1" ] + } else { + defines += [ "CHIP_CRYPTO_OPENSSL=0" ] + } +} + +if (chip_crypto == "openssl") { + import("//build/config/linux/pkg_config.gni") + + pkg_config("openssl_config") { + packages = [ "openssl" ] + } +} else { + import("//build_overrides/mbedtls.gni") +} + +static_library("crypto") { + output_name = "libChipCrypto" + + sources = [ "CHIPCryptoPAL.h" ] + + public_deps = [ + "${chip_root}/src/lib/core", + "${nlassert_root}:nlassert", + ] + + public_configs = [ ":crypto_config" ] + + if (chip_crypto == "mbedtls") { + sources += [ "CHIPCryptoPALmbedTLS.cpp" ] + public_deps += [ "${mbedtls_root}:mbedtls" ] + } else if (chip_crypto == "openssl") { + sources += [ "CHIPCryptoPALOpenSSL.cpp" ] + public_configs += [ ":openssl_config" ] + } else { + assert(false, "Invalid CHIP crypto") + } +} diff --git a/src/crypto/crypto.gni b/src/crypto/crypto.gni new file mode 100644 index 00000000000000..26ddb3418fed5d --- /dev/null +++ b/src/crypto/crypto.gni @@ -0,0 +1,29 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Crypto implementation: mbedtls, openssl. + chip_crypto = "" +} + +if (chip_crypto == "") { + if (current_os == "freertos") { + chip_crypto = "mbedtls" + } else { + chip_crypto = "openssl" + } +} + +assert(chip_crypto == "mbedtls" || chip_crypto == "openssl", + "Please select a valid crypto implementation: mbedtls, openssl") diff --git a/src/crypto/tests/BUILD.gn b/src/crypto/tests/BUILD.gn new file mode 100644 index 00000000000000..f6b83d3c1b38b1 --- /dev/null +++ b/src/crypto/tests/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2020 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("//build_overrides/nlunit_test.gni") + +import("${chip_root}/gn/chip/chip_test_suite.gni") + +chip_test_suite("tests") { + output_name = "libChipCrypto" + + sources = [ + "AES_CCM_128_test_vectors.h", + "AES_CCM_256_test_vectors.h", + "CHIPCryptoPALTest.cpp", + "ECDH_P256_test_vectors.h", + "HKDF_SHA256_test_vectors.h", + "TestCryptoLayer.h", + ] + + public_deps = [ + "${chip_root}/src/crypto", + "${chip_root}/src/lib/core", + "${nlunit_test_root}:nlunit-test", + ] + + tests = [ "CHIPCryptoPALTest" ] +} diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn new file mode 100644 index 00000000000000..443a9be9dd67ac --- /dev/null +++ b/src/inet/BUILD.gn @@ -0,0 +1,156 @@ +# Copyright (c) 2020 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("//build_overrides/nlassert.gni") +import("//build_overrides/nlfaultinjection.gni") +import("//build_overrides/nlio.gni") + +import("${chip_root}/gn/chip/tests.gni") +import("inet.gni") + +declare_args() { + # Extra header to include in SystemConfig.h for project. + inet_project_config_include = "" + + # Extra header to include in SystemConfig.h for platform. + inet_platform_config_include = "" +} + +config("inet_config") { + configs = [ "${chip_root}/src:includes" ] + + defines = [] + if (inet_project_config_include != "") { + defines += [ "INET_PROJECT_CONFIG_INCLUDE=${inet_project_config_include}" ] + } + if (inet_platform_config_include != "") { + defines += + [ "INET_PLATFORM_CONFIG_INCLUDE=${inet_platform_config_include}" ] + } + if (chip_build_tests) { + defines += [ "INET_CONFIG_TEST=1" ] + } else { + defines += [ "INET_CONFIG_TEST=0" ] + } + if (inet_config_enable_ipv4) { + defines += [ "INET_CONFIG_ENABLE_IPV4=1" ] + } else { + defines += [ "INET_CONFIG_ENABLE_IPV4=0" ] + } + if (inet_config_enable_dns_resolver) { + defines += [ "INET_CONFIG_ENABLE_DNS_RESOLVER=1" ] + } else { + defines += [ "INET_CONFIG_ENABLE_DNS_RESOLVER=0" ] + } + if (inet_config_enable_async_dns_sockets) { + defines += [ "INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS=1" ] + } else { + defines += [ "INET_CONFIG_ENABLE_ASYNC_DNS_SOCKETS=0" ] + } + if (inet_config_enable_raw_endpoint) { + defines += [ "INET_CONFIG_ENABLE_RAW_ENDPOINT=1" ] + } else { + defines += [ "INET_CONFIG_ENABLE_RAW_ENDPOINT=0" ] + } + if (inet_config_enable_tcp_endpoint) { + defines += [ "INET_CONFIG_ENABLE_TCP_ENDPOINT=1" ] + } else { + defines += [ "INET_CONFIG_ENABLE_TCP_ENDPOINT=0" ] + } + if (inet_config_enable_tun_endpoint) { + defines += [ "INET_CONFIG_ENABLE_TUN_ENDPOINT=1" ] + } else { + defines += [ "INET_CONFIG_ENABLE_TUN_ENDPOINT=0" ] + } + if (inet_config_enable_udp_endpoint) { + defines += [ "INET_CONFIG_ENABLE_UDP_ENDPOINT=1" ] + } else { + assert(false, "CHIP currently request UDP endpoint") + } +} + +source_set("inet_config_header") { + sources = [ "InetConfig.h" ] + + public_configs = [ ":inet_config" ] + + public_deps = [ "${chip_root}/src/system:system_config_header" ] +} + +static_library("inet") { + output_name = "libInetLayer" + + sources = [ + "AsyncDNSResolverSockets.cpp", + "AsyncDNSResolverSockets.h", + "EndPointBasis.cpp", + "EndPointBasis.h", + "IANAConstants.h", + "IPAddress-StringFuncts.cpp", + "IPAddress.cpp", + "IPAddress.h", + "IPEndPointBasis.cpp", + "IPEndPointBasis.h", + "IPPrefix.cpp", + "IPPrefix.h", + "Inet.h", + "InetArgParser.cpp", + "InetArgParser.h", + "InetError.cpp", + "InetError.h", + "InetFaultInjection.h", + "InetInterface.cpp", + "InetInterface.h", + "InetLayer.cpp", + "InetLayer.h", + "InetLayerBasis.cpp", + "InetLayerBasis.h", + "InetLayerEvents.h", + "InetUtils.cpp", + "RawEndPoint.cpp", + "RawEndPoint.h", + "TCPEndPoint.cpp", + "TCPEndPoint.h", + "UDPEndPoint.cpp", + "UDPEndPoint.h", + "arpa-inet-compatibility.h", + ] + + public_deps = [ + ":inet_config_header", + "${chip_root}/src/lib/support", + "${chip_root}/src/system", + "${nlio_root}:nlio", + ] + + if (inet_config_enable_dns_resolver) { + sources += [ + "DNSResolver.cpp", + "DNSResolver.h", + ] + } + + if (inet_config_enable_tun_endpoint) { + sources += [ + "TunEndPoint.cpp", + "TunEndPoint.h", + ] + } + + if (chip_with_nlfaultinjection) { + sources += [ "InetFaultInjection.cpp" ] + public_deps += [ "${nlfaultinjection_root}:nlfaultinjection" ] + } +} diff --git a/src/inet/inet.gni b/src/inet/inet.gni new file mode 100644 index 00000000000000..231c388066cd37 --- /dev/null +++ b/src/inet/inet.gni @@ -0,0 +1,38 @@ +# Copyright (c) 2020 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") + +declare_args() { + # Enable IPv4 support. + inet_config_enable_ipv4 = true + + # Enable DNS resolver. + inet_config_enable_dns_resolver = true + + # Enable async DNS. + inet_config_enable_async_dns_sockets = true + + # Enable raw endpoint. + inet_config_enable_raw_endpoint = true + + # Enable UDP endpoint. + inet_config_enable_udp_endpoint = true + + # Enable TCP endpoint. + inet_config_enable_tcp_endpoint = true + + # Enable TUN endpoint. + inet_config_enable_tun_endpoint = current_os == "linux" +} diff --git a/src/inet/tests/BUILD.gn b/src/inet/tests/BUILD.gn new file mode 100644 index 00000000000000..fe968dbea03dde --- /dev/null +++ b/src/inet/tests/BUILD.gn @@ -0,0 +1,57 @@ +# Copyright (c) 2020 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("//build_overrides/nlunit_test.gni") + +import("${chip_root}/gn/chip/chip_test_suite.gni") + +config("tests_config") { + include_dirs = [ "." ] +} + +chip_test_suite("tests") { + output_name = "libTestInetCommon" + + sources = [ + "TapAddrAutoconf.cpp", + "TapAddrAutoconf.h", + "TestInetAddress.cpp", + "TestInetCommon.cpp", + "TestInetCommon.h", + "TestInetCommonOptions.cpp", + "TestInetCommonOptions.h", + "TestInetEndPoint.cpp", + "TestInetErrorStr.cpp", + "TestInetLayer.cpp", + "TestInetLayer.h", + "TestInetLayerCommon.cpp", + "TestInetLayerDNS.cpp", + "TestInetLayerMulticast.cpp", + "TestLwIPDNS.cpp", + ] + + public_configs = [ ":tests_config" ] + + public_deps = [ + "${chip_root}/src/inet", + "${chip_root}/src/lib/core", + "${nlunit_test_root}:nlunit-test", + ] + + tests = [ + "TestInetAddress", + "TestInetErrorStr", + ] +} diff --git a/src/lib/BUILD.gn b/src/lib/BUILD.gn new file mode 100644 index 00000000000000..e119fc3466ee0c --- /dev/null +++ b/src/lib/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2020 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") + +config("includes") { + include_dirs = [ "." ] +} + +static_library("lib") { + public_deps = [ + "${chip_root}/src/app:chip", + "${chip_root}/src/ble", + "${chip_root}/src/controller", + "${chip_root}/src/crypto", + "${chip_root}/src/inet", + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + "${chip_root}/src/platform", + "${chip_root}/src/system", + "${chip_root}/src/transport", + ] + + output_name = "libCHIP" + + output_dir = "${root_out_dir}/lib" + + complete_static_lib = true +} diff --git a/src/lib/core/BUILD.gn b/src/lib/core/BUILD.gn new file mode 100644 index 00000000000000..0d9d6c8830865b --- /dev/null +++ b/src/lib/core/BUILD.gn @@ -0,0 +1,153 @@ +# Copyright (c) 2020 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("//build_overrides/nlio.gni") + +import("${chip_root}/gn/chip/tests.gni") +import("${chip_root}/src/inet/inet.gni") +import("core.gni") + +config("chip_config") { + # TODO - Move CHIP_PROJECT_CONFIG_INCLUDE, CHIP_PLATFORM_CONFIG_INCLUDE here. + # Currently those are also used from src/system. + defines = [] + + if (chip_build_tests) { + defines += [ "CHIP_CONFIG_TEST=1" ] + } else { + defines += [ "CHIP_CONFIG_TEST=0" ] + } + if (chip_error_logging) { + defines += [ "CHIP_ERROR_LOGGING=1" ] + } else { + defines += [ "CHIP_ERROR_LOGGING=0" ] + } + if (chip_progress_logging) { + defines += [ "CHIP_PROGRESS_LOGGING=1" ] + } else { + defines += [ "CHIP_PROGRESS_LOGGING=0" ] + } + if (chip_detail_logging) { + defines += [ "CHIP_DETAIL_LOGGING=1" ] + } else { + defines += [ "CHIP_DETAIL_LOGGING=0" ] + } + + if (chip_config_short_error_str) { + defines += [ "CHIP_CONFIG_SHORT_ERROR_STR=1" ] + } else { + defines += [ "CHIP_CONFIG_SHORT_ERROR_STR=0" ] + } + + if (chip_config_enable_arg_parser) { + defines += [ "CHIP_CONFIG_ENABLE_ARG_PARSER=1" ] + } else { + defines += [ "CHIP_CONFIG_ENABLE_ARG_PARSER=0" ] + } + + if (chip_target_style == "unix") { + defines += [ "CHIP_TARGET_STYLE_UNIX=1" ] + } else { + defines += [ "CHIP_TARGET_STYLE_UNIX=0" ] + } + if (chip_target_style == "embedded") { + defines += [ "CHIP_TARGET_STYLE_EMBEDDED=1" ] + } else { + defines += [ "CHIP_TARGET_STYLE_EMBEDDED=0" ] + } + + if (chip_logging_style == "android") { + defines += [ "CHIP_LOGGING_STYLE_ANDROID=1" ] + } else { + defines += [ "CHIP_LOGGING_STYLE_ANDROID=0" ] + } + if (chip_logging_style == "external") { + defines += [ "CHIP_LOGGING_STYLE_EXTERNAL=1" ] + } else { + defines += [ "CHIP_LOGGING_STYLE_EXTERNAL=0" ] + } + if (chip_logging_style == "stdio") { + defines += [ "CHIP_LOGGING_STYLE_STDIO=1" ] + } else { + defines += [ "CHIP_LOGGING_STYLE_STDIO=0" ] + } + if (chip_logging_style == "stdio_weak") { + defines += [ "CHIP_LOGGING_STYLE_STDIO_WEAK=1" ] + } else { + defines += [ "CHIP_LOGGING_STYLE_STDIO_WEAK=0" ] + } + + include_dirs = [ target_gen_dir ] + + configs = [ + "${chip_root}/src:includes", + "${chip_root}/src/lib:includes", + ] +} + +source_set("chip_config_header") { + sources = [ + "CHIPConfig.h", + "CHIPEventLoggingConfig.h", + "CHIPTimeConfig.h", + "CHIPTunnelConfig.h", + ] + + public_configs = [ ":chip_config" ] + + public_deps = [ "${chip_root}/src/system:system_config_header" ] +} + +static_library("core") { + output_name = "libChipCore" + + sources = [ + "CHIPCallback.h", + "CHIPCircularTLVBuffer.cpp", + "CHIPCircularTLVBuffer.h", + "CHIPCore.h", + "CHIPEncoding.h", + "CHIPError.cpp", + "CHIPError.h", + "CHIPKeyIds.cpp", + "CHIPKeyIds.h", + "CHIPTLV.h", + "CHIPTLVDebug.cpp", + "CHIPTLVReader.cpp", + "CHIPTLVTags.h", + "CHIPTLVTypes.h", + "CHIPTLVUpdater.cpp", + "CHIPTLVUtilities.cpp", + "CHIPTLVWriter.cpp", + ] + + public_deps = [ + ":chip_config_header", + "${chip_root}/src/ble", + "${chip_root}/src/inet", + "${chip_root}/src/lib/support", + "${chip_root}/src/platform", + "${chip_root}/src/system", + "${nlio_root}:nlio", + ] + + allow_circular_includes_from = [ + "${chip_root}/src/ble", + "${chip_root}/src/lib/support", + "${chip_root}/src/inet", + "${chip_root}/src/platform", + "${chip_root}/src/system", + ] +} diff --git a/src/lib/core/core.gni b/src/lib/core/core.gni new file mode 100644 index 00000000000000..0fa97c99e2e57a --- /dev/null +++ b/src/lib/core/core.gni @@ -0,0 +1,65 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Enable logging. Shorthand for chip_error_logging, etc. + chip_logging = true +} + +declare_args() { + # Configure target tyle: unix, embedded. + chip_target_style = "" + + # Configure logging style: stdio, external. + chip_logging_style = "" + + # Enable error logging. + chip_error_logging = chip_logging + + # Enable progress logging. + chip_progress_logging = chip_logging + + # Enable detail logging. + chip_detail_logging = chip_logging + + # Enable short error strings. + chip_config_short_error_str = false + + # Enable argument parser. + chip_config_enable_arg_parser = true +} + +if (chip_target_style == "") { + if (current_os != "freertos") { + chip_target_style = "unix" + } else { + chip_target_style = "embedded" + } +} + +if (chip_logging_style == "") { + if (current_os != "freertos") { + chip_logging_style = "stdio" + } else { + chip_logging_style = "external" + } +} + +assert(chip_target_style == "unix" || chip_target_style == "embedded", + "Please select a valid target style: unix, embedded") + +assert( + chip_logging_style == "android" || chip_logging_style == "external" || + chip_logging_style == "stdio" || chip_logging_style == "stdio_weak", + "Please select a valid logging style: android, external, stdio, stdio_weak") diff --git a/src/lib/core/tests/BUILD.gn b/src/lib/core/tests/BUILD.gn new file mode 100644 index 00000000000000..06951cfe708f55 --- /dev/null +++ b/src/lib/core/tests/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2020 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("//build_overrides/nlunit_test.gni") + +import("${chip_root}/gn/chip/chip_test_suite.gni") + +chip_test_suite("tests") { + output_name = "libCoreTests" + + sources = [ + "TestCHIPCallback.cpp", + "TestCHIPErrorStr.cpp", + "TestCHIPTLV.cpp", + "TestCore.h", + "TestReferenceCounted.cpp", + ] + + public_deps = [ + "${chip_root}/src/lib/core", + "${nlunit_test_root}:nlunit-test", + ] + + tests = [ + "TestCHIPErrorStr", + "TestReferenceCounted", + "TestCHIPTLV", + "TestCHIPCallback", + ] +} diff --git a/src/lib/shell/BUILD.gn b/src/lib/shell/BUILD.gn new file mode 100644 index 00000000000000..8c3619e8a0aa48 --- /dev/null +++ b/src/lib/shell/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2020 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") + +static_library("shell") { + output_name = "libCHIPShell" + + sources = [ + "commands.cpp", + "commands.h", + "shell.cpp", + "shell.h", + "streamer.cpp", + "streamer.h", + "streamer_stdio.cpp", + ] + + public_deps = [ + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + ] +} diff --git a/src/lib/support/BUILD.gn b/src/lib/support/BUILD.gn new file mode 100644 index 00000000000000..35c112f099cd49 --- /dev/null +++ b/src/lib/support/BUILD.gn @@ -0,0 +1,112 @@ +# Copyright (c) 2020 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("//build_overrides/nlassert.gni") +import("//build_overrides/nlfaultinjection.gni") +import("//build_overrides/nlio.gni") + +import("${chip_root}/gn/chip/chip_version.gni") +import("${chip_root}/gn/chip/tests.gni") + +action("gen_chip_version") { + script = "${chip_root}/scripts/gen_chip_version.py" + + version_file = "${target_gen_dir}/include/CHIPVersion.h" + outputs = [ version_file ] + args = [ + "--output_file=" + rebase_path(version_file, root_build_dir), + "--chip_major=${chip_version_major}", + "--chip_minor=${chip_version_minor}", + "--chip_patch=${chip_version_patch}", + "--chip_extra={chip_version_extra}", + ] +} + +source_set("chip_version_header") { + sources = get_target_outputs(":gen_chip_version") + + deps = [ ":gen_chip_version" ] +} + +config("support_config") { + configs = [ + "${chip_root}/src:includes", + "${chip_root}/src/lib:includes", + "${chip_root}/src/system:system_config", + ] + + include_dirs = [ "${target_gen_dir}/include" ] +} + +support_headers = [ + "Base64.h", + "CHIPCounter.h", + "CodeUtils.h", + "DLLUtil.h", + "ErrorStr.h", + "FibonacciUtils.h", + "PersistedCounter.h", + "RandUtils.h", + "TestUtils.h", + "TimeUtils.h", + "logging/CHIPLogging.h", + "verhoeff/Verhoeff.h", +] + +static_library("support") { + output_name = "libSupportLayer" + + sources = [ + "Base64.cpp", + "CHIPArgParser.cpp", + "CHIPCounter.cpp", + "ErrorStr.cpp", + "FibonacciUtils.cpp", + "PersistedCounter.cpp", + "RandUtils.cpp", + "TestUtils.cpp", + "TimeUtils.cpp", + "logging/CHIPLogging.cpp", + "logging/CHIPLoggingLogV.cpp", + "verhoeff/Verhoeff.cpp", + "verhoeff/Verhoeff10.cpp", + "verhoeff/Verhoeff16.cpp", + "verhoeff/Verhoeff32.cpp", + "verhoeff/Verhoeff36.cpp", + ] + + public = support_headers + + public_deps = [ + ":chip_version_header", + ":support_headers", + "${chip_root}/src/lib/core:chip_config_header", + "${nlassert_root}:nlassert", + ] + + public_configs = [ ":support_config" ] + + if (chip_with_nlfaultinjection) { + sources += [ "CHIPFaultInjection.cpp" ] + public += [ "CHIPFaultInjection.h" ] + public_deps += [ "${nlfaultinjection_root}:nlfaultinjection" ] + } +} + +copy("support_headers") { + sources = support_headers + + outputs = [ "${target_gen_dir}/include/support/{{source_file_part}}" ] +} diff --git a/src/lib/support/tests/BUILD.gn b/src/lib/support/tests/BUILD.gn new file mode 100644 index 00000000000000..90913791da52f5 --- /dev/null +++ b/src/lib/support/tests/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2020 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("//build_overrides/nlunit_test.gni") + +import("${chip_root}/gn/chip/chip_test_suite.gni") + +chip_test_suite("tests") { + output_name = "libSupportTests" + + sources = [ + "TestCHIPArgParser.cpp", + "TestCHIPCounter.cpp", + "TestErrorStr.cpp", + "TestPersistedCounter.cpp", + "TestPersistedStorageImplementation.cpp", + "TestPersistedStorageImplementation.h", + "TestSupport.h", + "TestTimeUtils.cpp", + ] + + public_deps = [ + "${chip_root}/src/lib/core", + "${nlunit_test_root}:nlunit-test", + ] + + tests = [ + "TestErrorStr", + "TestCHIPArgParser", + "TestTimeUtils", + ] +} diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn new file mode 100644 index 00000000000000..6eb7267b773f99 --- /dev/null +++ b/src/lwip/BUILD.gn @@ -0,0 +1,88 @@ +# Copyright (c) 2020 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("//build_overrides/lwip.gni") + +import("${lwip_root}/lwip.gni") + +declare_args() { + # Enable lwIP debugging. + lwip_debug = is_debug + + # lwIP platform: standalone, freertos. + lwip_platform = "" +} + +if (lwip_platform == "") { + if (current_os != "freertos") { + lwip_platform = "standalone" + } +} + +assert(lwip_platform == "standalone" || lwip_platform == "nrf5" || + lwip_platform == "efr32", + "Unsupported lwIP platform: ${lwip_platform}") + +if (lwip_platform == "nrf5") { + import("//build_overrides/nrf5_sdk.gni") +} + +config("lwip_config") { + # Automatically enable LWIP_DEBUG for internal is_debug builds. + if (lwip_debug) { + lwip_debug = 1 + } else { + lwip_debug = 0 + } + defines = [ "LWIP_DEBUG=${lwip_debug}" ] + + include_dirs = [ lwip_platform ] + + if (lwip_platform != "standalone") { + include_dirs += [ "freertos" ] + } +} + +lwip_target("lwip") { + public = [ + "${lwip_platform}/arch/cc.h", + "${lwip_platform}/arch/perf.h", + "${lwip_platform}/lwipopts.h", + ] + + sources = [] + + if (lwip_platform == "standalone") { + public += [ "standalone/arch/sys_arch.h" ] + sources += [ "standalone/sys_arch.c" ] + } else { + public += [ + "${lwip_platform}/lwippools.h", + "freertos/arch/sys_arch.h", + ] + sources += [ "freertos/sys_arch.c" ] + } + + public_deps = [] + if (lwip_platform == "nrf5") { + public_deps += [ "${nrf5_sdk_build_root}:nrf5_sdk" ] + } + + public_configs = [ ":lwip_config" ] +} + +group("all") { + deps = [ ":lwip_all" ] +} diff --git a/src/lwip/efr32/lwipopts.h b/src/lwip/efr32/lwipopts.h index 60e3c10c92118b..15e67108a67255 100644 --- a/src/lwip/efr32/lwipopts.h +++ b/src/lwip/efr32/lwipopts.h @@ -142,9 +142,10 @@ #define DEFAULT_UDP_RECVMBOX_SIZE 6 #define DEFAULT_TCP_RECVMBOX_SIZE 6 -// TODO: make LWIP_DEBUG conditional on build type - +#ifndef LWIP_DEBUG #define LWIP_DEBUG 1 +#endif + #define MEMP_OVERFLOW_CHECK (0) #define MEMP_SANITY_CHECK (0) #define MEM_DEBUG (LWIP_DBG_OFF) diff --git a/src/lwip/nrf5/lwipopts.h b/src/lwip/nrf5/lwipopts.h index 2f3f466d6ba5ea..9f719ebec0bb9b 100644 --- a/src/lwip/nrf5/lwipopts.h +++ b/src/lwip/nrf5/lwipopts.h @@ -129,7 +129,10 @@ // TODO: make LWIP_DEBUG conditional on build type +#ifndef LWIP_DEBUG #define LWIP_DEBUG 1 +#endif + #define MEMP_OVERFLOW_CHECK (0) #define MEMP_SANITY_CHECK (0) #define MEM_DEBUG (LWIP_DBG_OFF) diff --git a/src/lwip/tests/BUILD.gn b/src/lwip/tests/BUILD.gn new file mode 100644 index 00000000000000..32a3bd9bd714de --- /dev/null +++ b/src/lwip/tests/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright (c) 2020 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}/gn/chip/chip_test.gni") +import("${chip_root}/gn/chip/chip_test_group.gni") + +chip_test("TestLwIP") { + sources = [ "tests.c" ] + deps = [ "${chip_root}/src/lwip" ] +} + +chip_test_group("tests") { + deps = [ ":TestLwIP" ] +} diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn new file mode 100644 index 00000000000000..440a748c0b915b --- /dev/null +++ b/src/platform/BUILD.gn @@ -0,0 +1,98 @@ +# Copyright (c) 2020 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("//build_overrides/nlio.gni") + +import("${chip_root}/gn/chip/device.gni") + +if (device_platform != "none") { + declare_args() { + # Extra header to include in CHIPDeviceConfig.h for project. + chip_device_project_config_include = "" + + # Extra header to include in CHIPDeviceConfig.h for platform. + chip_device_platform_config_include = "" + } + + config("platform_config") { + configs = [ "${chip_root}/src:includes" ] + + defines = [] + if (chip_device_project_config_include != "") { + defines += [ "CHIP_DEVICE_PROJECT_CONFIG_INCLUDE=${chip_device_project_config_include}" ] + } + if (chip_device_platform_config_include != "") { + defines += [ "CHIP_DEVICE_PLATFORM_CONFIG_INCLUDE=${chip_device_platform_config_include}" ] + } + + if (device_platform == "nrf5") { + defines += [ + "CHIP_DEVICE_LAYER_TARGET_NRF5=1", + "CHIP_DEVICE_LAYER_TARGET=nRF5", + ] + } else { + defines += [ "CHIP_DEVICE_LAYER_TARGET_NRF5=0" ] + } + } + + static_library("platform") { + output_name = "libDeviceLayer" + + sources = [ + "GeneralUtils.cpp", + "Globals.cpp", + "PersistedStorage.cpp", + "SystemEventSupport.cpp", + "SystemTimerSupport.cpp", + ] + + public_deps = [ + "${chip_root}/src/ble", + "${chip_root}/src/lib/core:chip_config_header", + "${chip_root}/src/lib/support", + "${nlio_root}:nlio", + ] + + public_configs = [ ":platform_config" ] + + if (device_platform == "nrf5") { + sources += [ + "FreeRTOS/SystemTimeSupport.cpp", + "nRF5/BLEManagerImpl.cpp", + "nRF5/BLEManagerImpl.h", + "nRF5/BlePlatformConfig.h", + "nRF5/CHIPDevicePlatformConfig.h", + "nRF5/CHIPDevicePlatformEvent.h", + "nRF5/CHIPPlatformConfig.h", + "nRF5/ConfigurationManagerImpl.cpp", + "nRF5/ConfigurationManagerImpl.h", + "nRF5/ConnectivityManagerImpl.cpp", + "nRF5/ConnectivityManagerImpl.h", + "nRF5/InetPlatformConfig.h", + "nRF5/Logging.cpp", + "nRF5/PlatformManagerImpl.cpp", + "nRF5/PlatformManagerImpl.h", + "nRF5/SystemPlatformConfig.h", + "nRF5/nRF5Config.cpp", + "nRF5/nRF5Config.h", + "nRF5/nRF5Utils.cpp", + "nRF5/nRF5Utils.h", + ] + } + } +} else { + group("platform") { + } +} diff --git a/src/qrcodetool/BUILD.gn b/src/qrcodetool/BUILD.gn new file mode 100644 index 00000000000000..455f6c6fc7aa24 --- /dev/null +++ b/src/qrcodetool/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright (c) 2020 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}/gn/chip/tools.gni") + +assert(chip_build_tools) + +executable("qrcodetool") { + sources = [ + "qrcodetool.cpp", + "qrcodetool_command_manager.h", + "setup_payload_commands.cpp", + "setup_payload_commands.h", + ] + + public_deps = [ + "${chip_root}/src/lib/support", + "${chip_root}/src/setup_payload", + ] +} diff --git a/src/setup_payload/BUILD.gn b/src/setup_payload/BUILD.gn new file mode 100644 index 00000000000000..760698c1eff5a7 --- /dev/null +++ b/src/setup_payload/BUILD.gn @@ -0,0 +1,47 @@ +# Copyright (c) 2020 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") + +config("setup_payload_config") { + include_dirs = [ "." ] +} + +static_library("setup_payload") { + output_name = "libSetupPayload" + + sources = [ + "Base41.cpp", + "Base41.h", + "ManualSetupPayloadGenerator.cpp", + "ManualSetupPayloadGenerator.h", + "ManualSetupPayloadParser.cpp", + "ManualSetupPayloadParser.h", + "QRCodeSetupPayloadGenerator.cpp", + "QRCodeSetupPayloadGenerator.h", + "QRCodeSetupPayloadParser.cpp", + "QRCodeSetupPayloadParser.h", + "SetupPayload.cpp", + "SetupPayload.h", + "SetupPayloadHelper.cpp", + "SetupPayloadHelper.h", + ] + + public_deps = [ + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + ] + + public_configs = [ ":setup_payload_config" ] +} diff --git a/src/setup_payload/tests/BUILD.gn b/src/setup_payload/tests/BUILD.gn new file mode 100644 index 00000000000000..a25aab2957ae64 --- /dev/null +++ b/src/setup_payload/tests/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2020 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("//build_overrides/nlunit_test.gni") + +import("${chip_root}/gn/chip/chip_test_suite.gni") + +chip_test_suite("tests") { + output_name = "libSetupPayloadTests" + + sources = [ + "TestManualCode.cpp", + "TestManualCode.h", + "TestQRCode.cpp", + "TestQRCode.h", + "TestQRCodeTLV.cpp", + "TestQRCodeTLV.h", + ] + + public_deps = [ + "${chip_root}/src/setup_payload", + "${nlunit_test_root}:nlunit-test", + ] + + tests = [ + "TestQRCodeTLV", + "TestManualCode", + "TestQRCode", + ] +} diff --git a/src/system/BUILD.gn b/src/system/BUILD.gn new file mode 100644 index 00000000000000..91436caf0f0147 --- /dev/null +++ b/src/system/BUILD.gn @@ -0,0 +1,160 @@ +# Copyright (c) 2020 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("//build_overrides/nlassert.gni") +import("//build_overrides/nlfaultinjection.gni") + +import("${chip_root}/gn/chip/tests.gni") +import("system.gni") + +declare_args() { + # Extra header to include in CHIPConfig.h for project. + # TODO - This should probably be in src/core but src/system also uses it. + chip_project_config_include = "" + + # Extra header to include in CHIPConfig.h for platform. + # TODO - This should probably be in src/core but src/system also uses it. + chip_platform_config_include = "" + + # Extra header to include in SystemConfig.h for project. + system_project_config_include = "" + + # Extra header to include in SystemConfig.h for platform. + system_platform_config_include = "" +} + +config("system_config") { + configs = [ "${chip_root}/src:includes" ] + + defines = [] + if (chip_project_config_include != "") { + defines += [ "CHIP_PROJECT_CONFIG_INCLUDE=${chip_project_config_include}" ] + } + if (chip_platform_config_include != "") { + defines += + [ "CHIP_PLATFORM_CONFIG_INCLUDE=${chip_platform_config_include}" ] + } + if (system_project_config_include != "") { + defines += + [ "SYSTEM_PROJECT_CONFIG_INCLUDE=${system_project_config_include}" ] + } + if (system_platform_config_include != "") { + defines += + [ "SYSTEM_PLATFORM_CONFIG_INCLUDE=${system_platform_config_include}" ] + } + if (chip_build_tests) { + defines += [ "CHIP_SYSTEM_CONFIG_TEST=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_TEST=0" ] + } + if (chip_with_nlfaultinjection) { + defines += [ "CHIP_WITH_NLFAULTINJECTION=1" ] + } else { + defines += [ "CHIP_WITH_NLFAULTINJECTION=0" ] + } + if (chip_system_config_use_lwip) { + defines += [ "CHIP_SYSTEM_CONFIG_USE_LWIP=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_USE_LWIP=0" ] + } + if (chip_system_config_use_sockets) { + defines += [ "CHIP_SYSTEM_CONFIG_USE_SOCKETS=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_USE_SOCKETS=0" ] + } + if (chip_system_config_locking == "posix") { + defines += [ "CHIP_SYSTEM_CONFIG_POSIX_LOCKING=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_POSIX_LOCKING=0" ] + } + if (chip_system_config_locking == "freertos") { + defines += [ "CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING=0" ] + } + if (chip_system_config_locking == "none") { + defines += [ "CHIP_SYSTEM_CONFIG_NO_LOCKING=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_NO_LOCKING=0" ] + } + if (chip_system_config_provide_statistics) { + defines += [ "CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS=1" ] + } else { + defines += [ "CHIP_SYSTEM_CONFIG_PROVIDE_STATISTICS=0" ] + } + if (chip_system_config_use_malloc) { + defines += [ "CONFIG_HAVE_HEAP=1" ] + defines += [ "HAVE_MALLOC=1" ] + defines += [ "HAVE_FREE=1" ] + } + if (chip_system_config_clock == "clock_gettime") { + defines += [ "HAVE_CLOCK_GETTIME=1" ] + defines += [ "HAVE_CLOCK_SETTIME=1" ] + } + if (chip_system_config_clock == "gettimeofday") { + defines += [ "HAVE_GETTIMEOFDAY=1" ] + } +} + +source_set("system_config_header") { + sources = [ "SystemConfig.h" ] + + public_configs = [ ":system_config" ] + + public_deps = [] + + if (chip_system_config_use_lwip) { + public_deps += [ "${chip_root}/src/lwip" ] + } +} + +static_library("system") { + output_name = "libSystemLayer" + + sources = [ + "SystemAlignSize.h", + "SystemClock.cpp", + "SystemClock.h", + "SystemConfig.h", + "SystemError.cpp", + "SystemError.h", + "SystemEvent.h", + "SystemFaultInjection.h", + "SystemLayer.cpp", + "SystemLayer.h", + "SystemLayerPrivate.h", + "SystemMutex.cpp", + "SystemMutex.h", + "SystemObject.cpp", + "SystemObject.h", + "SystemPacketBuffer.cpp", + "SystemPacketBuffer.h", + "SystemStats.cpp", + "SystemStats.h", + "SystemTimer.cpp", + "SystemTimer.h", + "TimeSource.h", + ] + + public_deps = [ + "${chip_root}/src/lib/support", + "${nlassert_root}:nlassert", + ] + + if (chip_with_nlfaultinjection) { + sources += [ "SystemFaultInjection.cpp" ] + public_deps += [ "${nlfaultinjection_root}:nlfaultinjection" ] + } +} diff --git a/src/system/system.gni b/src/system/system.gni new file mode 100644 index 00000000000000..532390bd43a6b8 --- /dev/null +++ b/src/system/system.gni @@ -0,0 +1,54 @@ +# Copyright (c) 2020 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. + +declare_args() { + # Build tests. + chip_system_config_test = true + + # Use malloc. + chip_system_config_use_malloc = current_os != "freertos" + + # Use the lwIP library. + chip_system_config_use_lwip = current_os == "freertos" + + # Use BSD/POSIX socket API. + chip_system_config_use_sockets = current_os != "freertos" + + # Mutex implementation: posix, freertos, none. + chip_system_config_locking = "" + + # Clock implementation: clock_gettime, gettimeofday + chip_system_config_clock = "clock_gettime" + + # Enable metrics collection. + chip_system_config_provide_statistics = true +} + +if (chip_system_config_locking == "") { + if (current_os != "freertos") { + chip_system_config_locking = "posix" + } else { + chip_system_config_locking = "none" + } +} + +assert(chip_system_config_locking == "posix" || + chip_system_config_locking == "freertos" || + chip_system_config_locking == "none", + "Please select a valid mutex implementation: posix, freertos, none") + +assert( + chip_system_config_clock == "clock_gettime" || + chip_system_config_clock == "gettimeofday", + "Please select a valid clock implementation: clock_gettime, gettimeofday") diff --git a/src/system/tests/BUILD.gn b/src/system/tests/BUILD.gn new file mode 100644 index 00000000000000..c9486e8d69c4eb --- /dev/null +++ b/src/system/tests/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (c) 2020 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("//build_overrides/nlunit_test.gni") + +import("${chip_root}/gn/chip/chip_test_suite.gni") + +chip_test_suite("tests") { + output_name = "libSystemLayerTests" + + sources = [ + "TestSystemErrorStr.cpp", + "TestSystemLayer.h", + "TestSystemObject.cpp", + "TestSystemPacketBuffer.cpp", + "TestSystemTimer.cpp", + "TestTimeSource.cpp", + ] + + public_deps = [ + "${chip_root}/src/inet", + "${chip_root}/src/system", + "${nlunit_test_root}:nlunit-test", + ] + + tests = [ + "TestSystemErrorStr", + "TestSystemObject", + "TestSystemPacketBuffer", + "TestSystemTimer", + "TestTimeSource", + ] +} diff --git a/src/transport/BUILD.gn b/src/transport/BUILD.gn new file mode 100644 index 00000000000000..08f5be2c4fe478 --- /dev/null +++ b/src/transport/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 2020 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") + +static_library("transport") { + output_name = "libTransportLayer" + + sources = [ + "Base.h", + "MessageHeader.cpp", + "MessageHeader.h", + "PeerAddress.h", + "PeerConnectionState.h", + "PeerConnections.h", + "SecureSession.cpp", + "SecureSession.h", + "SecureSessionMgr.cpp", + "SecureSessionMgr.h", + "UDP.cpp", + "UDP.h", + ] + + public_deps = [ + "${chip_root}/src/crypto", + "${chip_root}/src/inet", + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + ] +} diff --git a/src/transport/tests/BUILD.gn b/src/transport/tests/BUILD.gn new file mode 100644 index 00000000000000..abf50396256f72 --- /dev/null +++ b/src/transport/tests/BUILD.gn @@ -0,0 +1,51 @@ +# Copyright (c) 2020 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("//build_overrides/nlio.gni") +import("//build_overrides/nlunit_test.gni") + +import("${chip_root}/gn/chip/chip_test_suite.gni") + +chip_test_suite("tests") { + output_name = "libTransportLayerTests" + + sources = [ + "NetworkTestHelpers.cpp", + "NetworkTestHelpers.h", + "TestMessageHeader.cpp", + "TestPeerConnections.cpp", + "TestSecureSession.cpp", + "TestSecureSessionMgr.cpp", + "TestTransportLayer.h", + "TestUDP.cpp", + "TestUDPDriver.cpp", + ] + + public_deps = [ + "${chip_root}/src/inet/tests:tests_common", + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + "${chip_root}/src/transport", + "${nlio_root}:nlio", + "${nlunit_test_root}:nlunit-test", + ] + + tests = [ + "TestMessageHeader", + "TestPeerConnections", + "TestSecureSession", + "TestSecureSessionMgr", + ] +} diff --git a/third_party/lwip/lwip.gni b/third_party/lwip/lwip.gni new file mode 100644 index 00000000000000..e9ffce8084d965 --- /dev/null +++ b/third_party/lwip/lwip.gni @@ -0,0 +1,411 @@ +# Copyright (c) 2020 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/lwip.gni") + +declare_args() { + # Default enablement for lwIP library components. + # This has no effect on its own; it only changes between opt-out and opt-in. + lwip_default = current_os != "freertos" +} + +declare_args() { + # Build IPv4 support in lwIP. + lwip_ipv4 = lwip_default + + # Enable IPv6 support in lwIP. + lwip_ipv6 = lwip_default + + # Enable sequential & socket API support in lwIP. + lwip_api = lwip_default + + # Enable ethernet support in lwIP. + lwip_ethernet = lwip_default + + # Enable SLIP interface support in lwIP. + lwip_slip = lwip_default + + # Enable 6LoWPAN support in lwIP. + lwip_6lowpan = lwip_default + + # Enable PPP support in lwIP. + lwip_ppp = lwip_default + + # Default enablement for lwIP application components. + # This has no effect on its own; it only changes between opt-out and opt-in. + lwip_apps_default = false +} + +declare_args() { + # Enable SNMPv2c agent application. + lwip_snmp = lwip_apps_default + + # Enable HTTP server. + lwip_httpd = lwip_apps_default + + # Enable IPERF server. + lwip_iperf = lwip_apps_default + + # Enable SNTP client. + lwip_sntp = lwip_apps_default + + # Enable MDNS responder. + lwip_mdns = lwip_apps_default + + # Enable NetBIOS name server. + lwip_netbiosns = lwip_apps_default + + # Enable TFTP server. + lwip_tftp = lwip_apps_default + + # Enable MQTT client. + lwip_mqtt = lwip_apps_default +} + +# Defines a lwIP build target. +# +# lwIP depends on external header files to compile. This template defines +# a combined build of the lwIP sources plus target configuration. +template("lwip_target") { + _lwip_root = "${lwip_root}/repo/lwip" + + lwip_target_name = target_name + + config("${lwip_target_name}_warnings") { + cflags = [ + "-Wno-address", + "-Wno-type-limits", + ] + } + + config("${lwip_target_name}_base_config") { + include_dirs = [ + "${lwip_root}/repo/lwip/src/include", + "include", + ] + + # These options may have overlap with lwipopts.h, however this is harmless + # as long the options are the same and if they are not the same it's a + # compile error. + if (lwip_ipv4) { + enable_ipv4 = 1 + } else { + enable_ipv4 = 0 + } + if (lwip_ipv6) { + enable_ipv6 = 1 + } else { + enable_ipv6 = 0 + } + if (lwip_api) { + enable_api = 1 + } else { + enable_api = 0 + } + if (lwip_ethernet) { + enable_ethernet = 1 + } else { + enable_ethernet = 0 + } + if (lwip_slip) { + enable_slip = 1 + } else { + enable_slip = 0 + } + if (lwip_6lowpan) { + enable_6lowpan = 1 + } else { + enable_6lowpan = 0 + } + if (lwip_ppp) { + enable_ppp = 1 + } else { + enable_ppp = 0 + } + defines = [ + "LWIP_IPV4=${enable_ipv4}", + "LWIP_IPV6=${enable_ipv6}", + "LWIP_API=${enable_api}", + "LWIP_ETHERNET=${enable_ethernet}", + "LWIP_SLIP=${enable_slip}", + "LWIP_6LOWPAN=${enable_6lowpan}", + "LWIP_PPP=${enable_ppp}", + ] + } + + source_set(lwip_target_name) { + forward_variables_from(invoker, + [ + "sources", + "public", + "public_configs", + "public_deps", + ]) + + # lwIP headers become empty if the relevant feature is disabled, so the + # whole interface can be public regardless of build options. + public += [ + "${_lwip_root}/src/include/lwip/api.h", + "${_lwip_root}/src/include/lwip/autoip.h", + "${_lwip_root}/src/include/lwip/debug.h", + "${_lwip_root}/src/include/lwip/def.h", + "${_lwip_root}/src/include/lwip/dhcp.h", + "${_lwip_root}/src/include/lwip/dhcp6.h", + "${_lwip_root}/src/include/lwip/dns.h", + "${_lwip_root}/src/include/lwip/err.h", + "${_lwip_root}/src/include/lwip/etharp.h", + "${_lwip_root}/src/include/lwip/ethip6.h", + "${_lwip_root}/src/include/lwip/icmp.h", + "${_lwip_root}/src/include/lwip/icmp6.h", + "${_lwip_root}/src/include/lwip/if.h", + "${_lwip_root}/src/include/lwip/igmp.h", + "${_lwip_root}/src/include/lwip/inet.h", + "${_lwip_root}/src/include/lwip/inet_chksum.h", + "${_lwip_root}/src/include/lwip/init.h", + "${_lwip_root}/src/include/lwip/ip.h", + "${_lwip_root}/src/include/lwip/ip4_frag.h", + "${_lwip_root}/src/include/lwip/ip6.h", + "${_lwip_root}/src/include/lwip/ip6_addr.h", + "${_lwip_root}/src/include/lwip/ip6_frag.h", + "${_lwip_root}/src/include/lwip/ip6_route_table.h", + "${_lwip_root}/src/include/lwip/ip_addr.h", + "${_lwip_root}/src/include/lwip/mem.h", + "${_lwip_root}/src/include/lwip/memp.h", + "${_lwip_root}/src/include/lwip/mld6.h", + "${_lwip_root}/src/include/lwip/nd6.h", + "${_lwip_root}/src/include/lwip/netbuf.h", + "${_lwip_root}/src/include/lwip/netdb.h", + "${_lwip_root}/src/include/lwip/netif.h", + "${_lwip_root}/src/include/lwip/netifapi.h", + "${_lwip_root}/src/include/lwip/opt.h", + "${_lwip_root}/src/include/lwip/pbuf.h", + "${_lwip_root}/src/include/lwip/priv/tcp_priv.h", + "${_lwip_root}/src/include/lwip/priv/tcpip_priv.h", + "${_lwip_root}/src/include/lwip/prot/autoip.h", + "${_lwip_root}/src/include/lwip/prot/dhcp.h", + "${_lwip_root}/src/include/lwip/prot/dns.h", + "${_lwip_root}/src/include/lwip/prot/ethernet.h", + "${_lwip_root}/src/include/lwip/prot/icmp6.h", + "${_lwip_root}/src/include/lwip/prot/igmp.h", + "${_lwip_root}/src/include/lwip/prot/mld6.h", + "${_lwip_root}/src/include/lwip/prot/nd6.h", + "${_lwip_root}/src/include/lwip/raw.h", + "${_lwip_root}/src/include/lwip/snmp.h", + "${_lwip_root}/src/include/lwip/sockets.h", + "${_lwip_root}/src/include/lwip/stats.h", + "${_lwip_root}/src/include/lwip/sys.h", + "${_lwip_root}/src/include/lwip/tcp.h", + "${_lwip_root}/src/include/lwip/tcpip.h", + "${_lwip_root}/src/include/lwip/timeouts.h", + "${_lwip_root}/src/include/lwip/udp.h", + ] + + sources += [ + "${_lwip_root}/src/core/def.c", + "${_lwip_root}/src/core/dns.c", + "${_lwip_root}/src/core/inet_chksum.c", + "${_lwip_root}/src/core/init.c", + "${_lwip_root}/src/core/ip.c", + "${_lwip_root}/src/core/mem.c", + "${_lwip_root}/src/core/memp.c", + "${_lwip_root}/src/core/netif.c", + "${_lwip_root}/src/core/pbuf.c", + "${_lwip_root}/src/core/raw.c", + "${_lwip_root}/src/core/stats.c", + "${_lwip_root}/src/core/sys.c", + "${_lwip_root}/src/core/tcp.c", + "${_lwip_root}/src/core/tcp_in.c", + "${_lwip_root}/src/core/tcp_out.c", + "${_lwip_root}/src/core/timeouts.c", + "${_lwip_root}/src/core/udp.c", + "${_lwip_root}/src/include/lwip/priv/api_msg.h", + "${_lwip_root}/src/include/lwip/priv/memp_std.h", + "${_lwip_root}/src/include/lwip/priv/nd6_priv.h", + ] + + if (lwip_ipv4) { + sources += [ + "${_lwip_root}/src/core/ipv4/autoip.c", + "${_lwip_root}/src/core/ipv4/dhcp.c", + "${_lwip_root}/src/core/ipv4/etharp.c", + "${_lwip_root}/src/core/ipv4/icmp.c", + "${_lwip_root}/src/core/ipv4/igmp.c", + "${_lwip_root}/src/core/ipv4/ip4.c", + "${_lwip_root}/src/core/ipv4/ip4_addr.c", + "${_lwip_root}/src/core/ipv4/ip4_frag.c", + ] + } + + if (lwip_ipv6) { + sources += [ + "${_lwip_root}/src/core/ipv6/dhcp6.c", + "${_lwip_root}/src/core/ipv6/ethip6.c", + "${_lwip_root}/src/core/ipv6/icmp6.c", + "${_lwip_root}/src/core/ipv6/inet6.c", + "${_lwip_root}/src/core/ipv6/ip6.c", + "${_lwip_root}/src/core/ipv6/ip6_addr.c", + "${_lwip_root}/src/core/ipv6/ip6_frag.c", + "${_lwip_root}/src/core/ipv6/ip6_route_table.c", + "${_lwip_root}/src/core/ipv6/mld6.c", + "${_lwip_root}/src/core/ipv6/nd6.c", + ] + } + + if (lwip_api) { + sources += [ + "${_lwip_root}/src/api/api_lib.c", + "${_lwip_root}/src/api/api_msg.c", + "${_lwip_root}/src/api/err.c", + "${_lwip_root}/src/api/if.c", + "${_lwip_root}/src/api/netbuf.c", + "${_lwip_root}/src/api/netdb.c", + "${_lwip_root}/src/api/netifapi.c", + "${_lwip_root}/src/api/sockets.c", + "${_lwip_root}/src/api/tcpip.c", + ] + } + + if (lwip_ethernet) { + sources += [ "${_lwip_root}/src/netif/ethernet.c" ] + } + + if (lwip_slip) { + sources += [ "${_lwip_root}/src/netif/slipif.c" ] + } + + if (lwip_6lowpan) { + sources += [ "${_lwip_root}/src/netif/lowpan6.c" ] + } + + # Relax warnings for third_party code. + configs += [ ":${lwip_target_name}_warnings" ] + + public_configs += [ ":${lwip_target_name}_base_config" ] + } + + lwip_apps = [] + + template("lwip_app") { + app_name = target_name + + static_library("${lwip_target_name}_${app_name}") { + forward_variables_from(invoker, [ "sources" ]) + + deps = [ ":lwip" ] + + # Relax warnings for third_party code. + configs += [ ":${lwip_target_name}_warnings" ] + } + } + + if (lwip_snmp) { + lwip_app("snmp") { + sources = [ + "${_lwip_root}/src/apps/snmp/snmp_asn1.c", + "${_lwip_root}/src/apps/snmp/snmp_core.c", + "${_lwip_root}/src/apps/snmp/snmp_mib2.c", + "${_lwip_root}/src/apps/snmp/snmp_mib2_icmp.c", + "${_lwip_root}/src/apps/snmp/snmp_mib2_interfaces.c", + "${_lwip_root}/src/apps/snmp/snmp_mib2_ip.c", + "${_lwip_root}/src/apps/snmp/snmp_mib2_snmp.c", + "${_lwip_root}/src/apps/snmp/snmp_mib2_system.c", + "${_lwip_root}/src/apps/snmp/snmp_mib2_tcp.c", + "${_lwip_root}/src/apps/snmp/snmp_mib2_udp.c", + "${_lwip_root}/src/apps/snmp/snmp_msg.c", + "${_lwip_root}/src/apps/snmp/snmp_netconn.c", + "${_lwip_root}/src/apps/snmp/snmp_pbuf_stream.c", + "${_lwip_root}/src/apps/snmp/snmp_raw.c", + "${_lwip_root}/src/apps/snmp/snmp_scalar.c", + "${_lwip_root}/src/apps/snmp/snmp_table.c", + "${_lwip_root}/src/apps/snmp/snmp_threadsync.c", + "${_lwip_root}/src/apps/snmp/snmp_traps.c", + "${_lwip_root}/src/apps/snmp/snmpv3.c", + "${_lwip_root}/src/apps/snmp/snmpv3_dummy.c", + "${_lwip_root}/src/apps/snmp/snmpv3_mbedtls.c", + ] + } + + lwip_apps += [ ":${lwip_target_name}_snmp" ] + } + + if (lwip_httpd) { + lwip_app("httpd") { + sources = [ + "${_lwip_root}/src/apps/httpd/fs.c", + "${_lwip_root}/src/apps/httpd/httpd.c", + ] + } + + lwip_apps += [ ":${lwip_target_name}_httpd" ] + } + + if (lwip_iperf) { + lwip_app("lwiperf") { + sources = [ "${_lwip_root}/src/apps/lwiperf/lwiperf.c" ] + } + + lwip_apps += [ ":${lwip_target_name}_lwiperf" ] + } + + if (lwip_sntp) { + lwip_app("sntp") { + sources = [ "${_lwip_root}/src/apps/sntp/sntp.c" ] + } + + lwip_apps += [ ":${lwip_target_name}_sntp" ] + } + + if (lwip_mdns) { + lwip_app("mdns") { + sources = [ "${_lwip_root}/src/apps/mdns/mdns.c" ] + } + + lwip_apps += [ ":${lwip_target_name}_mdns" ] + } + + if (lwip_netbiosns) { + lwip_app("netbiosns") { + sources = [ "${_lwip_root}/src/apps/netbiosns/netbiosns.c" ] + } + + lwip_apps += [ ":${lwip_target_name}_netbiosns" ] + } + + if (lwip_tftp) { + lwip_app("tftp") { + sources = [ "${_lwip_root}/src/apps/tftp/tftp_server.c" ] + } + + lwip_apps += [ ":${lwip_target_name}_tftp" ] + } + + if (lwip_mqtt) { + lwip_app("mqtt") { + sources = [ "${_lwip_root}/src/apps/mqtt/mqtt.c" ] + } + + lwip_apps += [ ":${lwip_target_name}_mqtt" ] + } + + group("${lwip_target_name}_apps") { + deps = lwip_apps + } + + group("${lwip_target_name}_all") { + deps = [ + ":${lwip_target_name}", + ":${lwip_target_name}_apps", + ] + } +} diff --git a/third_party/mbedtls/BUILD.gn b/third_party/mbedtls/BUILD.gn new file mode 100644 index 00000000000000..aec535aa4409b9 --- /dev/null +++ b/third_party/mbedtls/BUILD.gn @@ -0,0 +1,102 @@ +# Copyright (c) 2020 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. + +config("mbedtls_config") { + include_dirs = [ "repo/include" ] + + if (current_os == "freertos") { + defines = [ + "MBEDTLS_NO_PLATFORM_ENTROPY", + "MBEDTLS_TEST_NULL_ENTROPY", + "MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES", + ] + cflags = [ "-Wno-cpp" ] + } +} + +static_library("mbedtls") { + sources = [ + "repo/library/aes.c", + "repo/library/aesni.c", + "repo/library/arc4.c", + "repo/library/asn1parse.c", + "repo/library/asn1write.c", + "repo/library/base64.c", + "repo/library/bignum.c", + "repo/library/blowfish.c", + "repo/library/camellia.c", + "repo/library/ccm.c", + "repo/library/certs.c", + "repo/library/chacha20.c", + "repo/library/chachapoly.c", + "repo/library/cipher.c", + "repo/library/cipher_wrap.c", + "repo/library/ctr_drbg.c", + "repo/library/debug.c", + "repo/library/des.c", + "repo/library/dhm.c", + "repo/library/ecdh.c", + "repo/library/ecdsa.c", + "repo/library/ecp.c", + "repo/library/ecp_curves.c", + "repo/library/entropy.c", + "repo/library/entropy_poll.c", + "repo/library/error.c", + "repo/library/gcm.c", + "repo/library/hkdf.c", + "repo/library/hmac_drbg.c", + "repo/library/md.c", + "repo/library/md5.c", + "repo/library/md_wrap.c", + "repo/library/oid.c", + "repo/library/pem.c", + "repo/library/pk.c", + "repo/library/pk_wrap.c", + "repo/library/pkcs12.c", + "repo/library/pkcs5.c", + "repo/library/pkparse.c", + "repo/library/pkwrite.c", + "repo/library/platform.c", + "repo/library/platform_util.c", + "repo/library/poly1305.c", + "repo/library/ripemd160.c", + "repo/library/rsa.c", + "repo/library/rsa_internal.c", + "repo/library/sha1.c", + "repo/library/sha256.c", + "repo/library/sha512.c", + "repo/library/ssl_cache.c", + "repo/library/ssl_ciphersuites.c", + "repo/library/ssl_cli.c", + "repo/library/ssl_cookie.c", + "repo/library/ssl_srv.c", + "repo/library/ssl_ticket.c", + "repo/library/ssl_tls.c", + "repo/library/version.c", + "repo/library/version_features.c", + "repo/library/x509.c", + "repo/library/x509_create.c", + "repo/library/x509_crl.c", + "repo/library/x509_csr.c", + "repo/library/x509write_crt.c", + "repo/library/x509write_csr.c", + "repo/library/xtea.c", + ] + + if (current_os != "freertos") { + sources += [ "repo/library/timing.c" ] + } + + public_configs = [ ":mbedtls_config" ] +} diff --git a/third_party/nlassert/BUILD.gn b/third_party/nlassert/BUILD.gn new file mode 100644 index 00000000000000..4e2e795ca90946 --- /dev/null +++ b/third_party/nlassert/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright (c) 2020 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. + +config("nlassert_config") { + include_dirs = [ "repo/include" ] +} + +source_set("nlassert") { + sources = [ "repo/include/nlassert.h" ] + + public_configs = [ ":nlassert_config" ] +} diff --git a/third_party/nlfaultinjection/BUILD.gn b/third_party/nlfaultinjection/BUILD.gn new file mode 100644 index 00000000000000..b1953bb02f2f7b --- /dev/null +++ b/third_party/nlfaultinjection/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (c) 2020 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/nlassert.gni") + +config("nlfaultinjection_config") { + include_dirs = [ "repo/include" ] +} + +static_library("nlfaultinjection") { + sources = [ + "repo/include/nlfaultinjection.hpp", + "repo/src/nlfaultinjection.cpp", + ] + + deps = [ "${nlassert_root}:nlassert" ] + + public_configs = [ ":nlfaultinjection_config" ] +} diff --git a/third_party/nlio/BUILD.gn b/third_party/nlio/BUILD.gn new file mode 100644 index 00000000000000..167db7db5ac469 --- /dev/null +++ b/third_party/nlio/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2020 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. + +config("nlio_config") { + include_dirs = [ "repo/include" ] +} + +source_set("nlio") { + sources = [ + "repo/include/nlbyteorder-big.h", + "repo/include/nlbyteorder-little.h", + "repo/include/nlbyteorder.h", + "repo/include/nlbyteorder.hpp", + "repo/include/nlio-base.h", + "repo/include/nlio-base.hpp", + "repo/include/nlio-byteorder-big.h", + "repo/include/nlio-byteorder-big.hpp", + "repo/include/nlio-byteorder-little.h", + "repo/include/nlio-byteorder-little.hpp", + "repo/include/nlio-byteorder.h", + "repo/include/nlio-byteorder.hpp", + "repo/include/nlio-private.h", + "repo/include/nlio.h", + "repo/include/nlio.hpp", + ] + + public_configs = [ ":nlio_config" ] +} diff --git a/third_party/nlunit-test/BUILD.gn b/third_party/nlunit-test/BUILD.gn new file mode 100644 index 00000000000000..df627d3585b902 --- /dev/null +++ b/third_party/nlunit-test/BUILD.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2020 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. + +config("nlunit-test_config") { + include_dirs = [ "repo/src" ] +} + +static_library("nlunit-test") { + output_name = "libnlunit-test" + + sources = [ + "repo/src/nlunit-test.c", + "repo/src/nlunit-test.h", + ] + + public_configs = [ ":nlunit-test_config" ] +} diff --git a/third_party/nrf5_sdk/BUILD.gn b/third_party/nrf5_sdk/BUILD.gn new file mode 100644 index 00000000000000..96247fc8ffebe6 --- /dev/null +++ b/third_party/nrf5_sdk/BUILD.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2020 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/nrf5_sdk.gni") + +import("${nrf5_sdk_build_root}/nrf5_sdk.gni") + +declare_args() { + # Build target to use for nRF5 SDK. Use this to set global SDK defines. + nrf5_sdk_target = "" +} + +assert(nrf5_sdk_target != "", "nrf5_sdk_target must be specified") + +group("nrf5_sdk") { + public_deps = [ nrf5_sdk_target ] +} diff --git a/third_party/nrf5_sdk/nrf5_sdk.gni b/third_party/nrf5_sdk/nrf5_sdk.gni new file mode 100644 index 00000000000000..8b4d0e1381af3a --- /dev/null +++ b/third_party/nrf5_sdk/nrf5_sdk.gni @@ -0,0 +1,183 @@ +# Copyright (c) 2020 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/nrf5_sdk.gni") + +declare_args() { + # Location of the nRF5 SDK. + nrf5_sdk_root = "" +} + +if (nrf5_sdk_root == "") { + nrf5_sdk_root = getenv("NRF5_SDK_ROOT") +} + +assert(nrf5_sdk_root != "", "nrf5_sdk_root must be specified") + +# Defines an nRF SDK build target. +# +# Parameters: +# nrf5_sdk_root - The location of the nRF SDK. +# sources - The sources files to build. +template("nrf5_sdk") { + if (defined(invoker.nrf5_sdk_root)) { + nrf5_sdk_root = invoker.nrf5_sdk_root + } + + assert(nrf5_sdk_root != "", "nrf5_sdk_root must be specified") + + sdk_target_name = target_name + + config("${sdk_target_name}_config") { + include_dirs = [] + if (defined(invoker.include_dirs)) { + include_dirs += invoker.include_dirs + } + include_dirs += [ + "${nrf5_sdk_root}/components", + "${nrf5_sdk_root}/components/boards", + "${nrf5_sdk_root}/components/ble/ble_advertising", + "${nrf5_sdk_root}/components/ble/common", + "${nrf5_sdk_root}/components/ble/nrf_ble_gatt", + "${nrf5_sdk_root}/components/libraries/atomic", + "${nrf5_sdk_root}/components/libraries/atomic_fifo", + "${nrf5_sdk_root}/components/libraries/balloc", + "${nrf5_sdk_root}/components/libraries/bsp", + "${nrf5_sdk_root}/components/libraries/button", + "${nrf5_sdk_root}/components/libraries/crc16", + "${nrf5_sdk_root}/components/libraries/delay", + "${nrf5_sdk_root}/components/libraries/experimental_section_vars", + "${nrf5_sdk_root}/components/libraries/fds", + "${nrf5_sdk_root}/components/libraries/fstorage", + "${nrf5_sdk_root}/components/libraries/log", + "${nrf5_sdk_root}/components/libraries/log/src", + "${nrf5_sdk_root}/components/libraries/memobj", + "${nrf5_sdk_root}/components/libraries/mem_manager", + "${nrf5_sdk_root}/components/libraries/mutex", + "${nrf5_sdk_root}/components/libraries/queue", + "${nrf5_sdk_root}/components/libraries/ringbuf", + "${nrf5_sdk_root}/components/libraries/stack_info", + "${nrf5_sdk_root}/components/libraries/strerror", + "${nrf5_sdk_root}/components/libraries/timer", + "${nrf5_sdk_root}/components/libraries/util", + "${nrf5_sdk_root}/components/softdevice/common", + "${nrf5_sdk_root}/components/softdevice/s140/headers", + "${nrf5_sdk_root}/components/softdevice/s140/headers/nrf52", + "${nrf5_sdk_root}/components/softdevice/mbr/nrf52840/headers", + "${nrf5_sdk_root}/components/thread/freertos_mbedtls_mutex", + "${nrf5_sdk_root}/components/toolchain/cmsis/include", + "${nrf5_sdk_root}/config/nrf52840/config", + "${nrf5_sdk_root}/external/fprintf", + "${nrf5_sdk_root}/external/freertos/config", + "${nrf5_sdk_root}/external/freertos/portable/CMSIS/nrf52", + "${nrf5_sdk_root}/external/freertos/portable/GCC/nrf52", + "${nrf5_sdk_root}/external/freertos/source/include", + "${nrf5_sdk_root}/external/segger_rtt", + "${nrf5_sdk_root}/integration/nrfx", + "${nrf5_sdk_root}/integration/nrfx/legacy", + "${nrf5_sdk_root}/modules/nrfx", + "${nrf5_sdk_root}/modules/nrfx/drivers/include", + "${nrf5_sdk_root}/modules/nrfx/hal", + "${nrf5_sdk_root}/modules/nrfx/mdk", + ] + + lib_dirs = [ "${nrf5_sdk_root}/modules/nrfx/mdk" ] + + defines = [ + "NRF52840_XXAA", + "BOARD_PCA10056", + "BSP_DEFINES_ONLY", + "CONFIG_GPIO_AS_PINRESET", + "FLOAT_ABI_HARD", + "__HEAP_SIZE=40960", + "__STACK_SIZE=8192", + "SOFTDEVICE_PRESENT", + "PRINTF_DISABLE_SUPPORT_EXPONENTIAL", + "S140", + ] + if (defined(invoker.defines)) { + defines += invoker.defines + } + cflags = [ "-Wno-array-bounds" ] + } + + # TODO - Break up this monolith and make it configurable. + static_library(sdk_target_name) { + sources = [ + "${nrf5_sdk_root}/components/ble/common/ble_advdata.c", + "${nrf5_sdk_root}/components/ble/common/ble_srv_common.c", + "${nrf5_sdk_root}/components/ble/nrf_ble_gatt/nrf_ble_gatt.c", + "${nrf5_sdk_root}/components/boards/boards.c", + "${nrf5_sdk_root}/components/libraries/atomic/nrf_atomic.c", + "${nrf5_sdk_root}/components/libraries/atomic_fifo/nrf_atfifo.c", + "${nrf5_sdk_root}/components/libraries/balloc/nrf_balloc.c", + "${nrf5_sdk_root}/components/libraries/button/app_button.c", + "${nrf5_sdk_root}/components/libraries/crc16/crc16.c", + "${nrf5_sdk_root}/components/libraries/experimental_section_vars/nrf_section_iter.c", + "${nrf5_sdk_root}/components/libraries/fds/fds.c", + "${nrf5_sdk_root}/components/libraries/fstorage/nrf_fstorage.c", + "${nrf5_sdk_root}/components/libraries/fstorage/nrf_fstorage_sd.c", + "${nrf5_sdk_root}/components/libraries/log/src/nrf_log_backend_rtt.c", + "${nrf5_sdk_root}/components/libraries/log/src/nrf_log_backend_serial.c", + "${nrf5_sdk_root}/components/libraries/log/src/nrf_log_default_backends.c", + "${nrf5_sdk_root}/components/libraries/log/src/nrf_log_frontend.c", + "${nrf5_sdk_root}/components/libraries/log/src/nrf_log_str_formatter.c", + "${nrf5_sdk_root}/components/libraries/mem_manager/mem_manager.c", + "${nrf5_sdk_root}/components/libraries/memobj/nrf_memobj.c", + "${nrf5_sdk_root}/components/libraries/queue/nrf_queue.c", + "${nrf5_sdk_root}/components/libraries/ringbuf/nrf_ringbuf.c", + "${nrf5_sdk_root}/components/libraries/strerror/nrf_strerror.c", + "${nrf5_sdk_root}/components/libraries/timer/app_timer_freertos.c", + "${nrf5_sdk_root}/components/libraries/uart/retarget.c", + "${nrf5_sdk_root}/components/libraries/util/app_error.c", + "${nrf5_sdk_root}/components/libraries/util/app_error_handler_gcc.c", + "${nrf5_sdk_root}/components/libraries/util/app_error_weak.c", + "${nrf5_sdk_root}/components/libraries/util/app_util_platform.c", + "${nrf5_sdk_root}/components/libraries/util/nrf_assert.c", + "${nrf5_sdk_root}/components/softdevice/common/nrf_sdh.c", + "${nrf5_sdk_root}/components/softdevice/common/nrf_sdh_ble.c", + "${nrf5_sdk_root}/components/softdevice/common/nrf_sdh_soc.c", + "${nrf5_sdk_root}/external/fprintf/nrf_fprintf.c", + "${nrf5_sdk_root}/external/fprintf/nrf_fprintf_format.c", + "${nrf5_sdk_root}/external/freertos/portable/CMSIS/nrf52/port_cmsis.c", + "${nrf5_sdk_root}/external/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c", + "${nrf5_sdk_root}/external/freertos/portable/GCC/nrf52/port.c", + "${nrf5_sdk_root}/external/freertos/source/croutine.c", + "${nrf5_sdk_root}/external/freertos/source/event_groups.c", + "${nrf5_sdk_root}/external/freertos/source/list.c", + "${nrf5_sdk_root}/external/freertos/source/portable/MemMang/heap_3.c", + "${nrf5_sdk_root}/external/freertos/source/queue.c", + "${nrf5_sdk_root}/external/freertos/source/stream_buffer.c", + "${nrf5_sdk_root}/external/freertos/source/tasks.c", + "${nrf5_sdk_root}/external/freertos/source/timers.c", + "${nrf5_sdk_root}/external/segger_rtt/SEGGER_RTT.c", + "${nrf5_sdk_root}/external/segger_rtt/SEGGER_RTT_Syscalls_GCC.c", + "${nrf5_sdk_root}/external/segger_rtt/SEGGER_RTT_printf.c", + "${nrf5_sdk_root}/integration/nrfx/legacy/nrf_drv_clock.c", + "${nrf5_sdk_root}/integration/nrfx/legacy/nrf_drv_rng.c", + "${nrf5_sdk_root}/modules/nrfx/drivers/src/nrfx_clock.c", + "${nrf5_sdk_root}/modules/nrfx/drivers/src/nrfx_gpiote.c", + "${nrf5_sdk_root}/modules/nrfx/drivers/src/nrfx_uart.c", + "${nrf5_sdk_root}/modules/nrfx/drivers/src/nrfx_uarte.c", + "${nrf5_sdk_root}/modules/nrfx/drivers/src/prs/nrfx_prs.c", + "${nrf5_sdk_root}/modules/nrfx/mdk/gcc_startup_nrf52840.S", + "${nrf5_sdk_root}/modules/nrfx/mdk/system_nrf52840.c", + ] + if (defined(invoker.sources)) { + sources += invoker.sources + } + + public_configs = [ ":${sdk_target_name}_config" ] + } +}