diff --git a/.github/workflows/gn_build.yaml b/.github/workflows/gn_build.yaml index 94c7fe49e1a04c..fd232689b7eaff 100644 --- a/.github/workflows/gn_build.yaml +++ b/.github/workflows/gn_build.yaml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - type: [main, clang, mbedtls] + type: [main, clang, linux-embedded, mbedtls] env: BUILD_TYPE: ${{ matrix.type }} BUILD_VERSION: 0.2.18 @@ -36,7 +36,7 @@ jobs: case $BUILD_TYPE in "main") GN_ARGS='';; "clang") GN_ARGS='is_clang=true';; - "linux-embedded") GN_ARGS='device_platform="linux"';; + "linux-embedded") GN_ARGS='import("//src/platform/Linux/args.gni")';; "mbedtls") GN_ARGS='chip_crypto="mbedtls"';; *) ;; esac diff --git a/.github/workflows/gn_examples.yaml b/.github/workflows/gn_examples.yaml new file mode 100644 index 00000000000000..2c34f50fa3db05 --- /dev/null +++ b/.github/workflows/gn_examples.yaml @@ -0,0 +1,76 @@ +name: GN Examples + +on: + push: + pull_request: + +jobs: + nrf: + name: nRF + + env: + BUILD_TYPE: nrf + BUILD_VERSION: 0.2.14 + BUILD_IMAGE: chip-build-nrf-platform + BUILD_ORG: connectedhomeip + + runs-on: ubuntu-latest + + container: + image: connectedhomeip/chip-build-nrf-platform:0.2.14 # $BUILD_IMAGE/$BUILD_ORG:$BUILD_VERSION + volumes: + - "/tmp/bloat_reports:/tmp/bloat_reports" + - "/tmp/output_binaries:/tmp/output_binaries" + + 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: Build example nRF5 Lock App + run: scripts/examples/gn_nrf_example.sh examples/lock-app/nrf5 out/lock_app_debug + - name: Build example nRF5 Lighting App + run: scripts/examples/gn_nrf_example.sh examples/lighting-app/nrf5 out/lighting_app_debug + - name: Preserve artifacts + run: | + mkdir -p example_binaries/nrf-build + cp out/lock_app_debug/chip-nrf52840-lock-example \ + out/lighting_app_debug/chip-nrf52840-lighting-example \ + example_binaries/nrf-build/ + + linux-standalone: + name: Linux Standalone + + env: + BUILD_TYPE: linux + BUILD_VERSION: 0.2.14 + BUILD_IMAGE: chip-build + BUILD_ORG: connectedhomeip + + runs-on: ubuntu-latest + + container: + image: connectedhomeip/chip-build:0.2.14 # $BUILD_IMAGE/$BUILD_ORG:$BUILD_VERSION + volumes: + - "/tmp/bloat_reports:/tmp/bloat_reports" + - "/tmp/output_binaries:/tmp/output_binaries" + + 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: Build example Standalone Echo Client + run: scripts/examples/gn_build_example.sh examples/chip-tool out/chip_tool_debug + - name: Build example Standalone Shell + run: scripts/examples/gn_build_example.sh examples/shell out/shell_debug + - name: Preserve artifacts + run: | + mkdir -p example_binaries/$BUILD_TYPE + cp out/chip_tool_debug/bin/chip-standalone-demo \ + out/shell_debug/bin/chip-shell \ + example_binaries/$BUILD_TYPE/ diff --git a/BUILD.gn b/BUILD.gn index 76facff41b6d78..d389987140676e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -40,6 +40,7 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { "${chip_root}/src/inet", "${chip_root}/src/lib", "${chip_root}/src/lib/core", + "${chip_root}/src/lib/shell", "${chip_root}/src/lib/support", "${chip_root}/src/lwip:all", "${chip_root}/src/system", @@ -56,9 +57,6 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { 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", ] @@ -77,6 +75,7 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { "${chip_root}/src/lib/core/tests", "${chip_root}/src/lib/support/tests", "${chip_root}/src/lwip/tests", + "${chip_root}/src/platform/tests", "${chip_root}/src/setup_payload/tests", "${chip_root}/src/system/tests", "${chip_root}/src/transport/tests", @@ -93,6 +92,9 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { declare_args() { # Set this to false to disable all builds by default. enable_default_builds = true + + # Set this to true to enable nRF5 builds by default. + enable_nrf5_builds = false } declare_args() { @@ -105,26 +107,51 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { # Build building chip with gcc & mbedtls. enable_host_gcc_mbdtls_build = enable_default_builds + # Build the chip-tool example. + enable_standalone_chip_tool_build = enable_default_builds + + # Build the shell example. + enable_standalone_shell_build = enable_default_builds + # Build the nRF5 lock app example. - enable_nrf5_lock_app_build = false - } + enable_nrf5_lock_app_build = enable_nrf5_builds - if (enable_nrf5_lock_app_build) { - import("//build_overrides/nrf5_lock_app.gni") + # Build the nRF5 lighting app example. + enable_nrf5_lighting_app_build = enable_nrf5_builds } - 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" + toolchain = "//build/toolchain/host:${host_os}_${host_cpu}_clang" } chip_build("host_gcc") { - toolchain = "//build/toolchain/host_gcc:${host_os}_${host_cpu}_gcc" + toolchain = "//build/toolchain/host:${host_os}_${host_cpu}_gcc" } chip_build("host_gcc_mbedtls") { - toolchain = "//build/toolchain/host_gcc:${host_os}_${host_cpu}_gcc_mbedtls" + toolchain = "${chip_root}/config/mbedtls/toolchain:${host_os}_${host_cpu}_gcc_mbedtls" + } + + standalone_toolchain = "${chip_root}/config/standalone/toolchain:standalone" + + group("standalone_chip_tool") { + deps = [ "${chip_root}/examples/chip-tool(${standalone_toolchain})" ] + } + + group("standalone_shell") { + deps = [ "${chip_root}/examples/shell(${standalone_toolchain})" ] + } + + if (enable_nrf5_lock_app_build) { + group("nrf5_lock_app") { + deps = [ "${chip_root}/examples/lock-app/nrf5(${chip_root}/config/nrf5/toolchain:nrf5_lock_app)" ] + } + } + + if (enable_nrf5_lighting_app_build) { + group("nrf5_lighting_app") { + deps = [ "${chip_root}/examples/lighting-app/nrf5(${chip_root}/config/nrf5/toolchain:nrf5_lighting_app)" ] + } } group("default") { @@ -138,8 +165,17 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { if (enable_host_gcc_mbdtls_build) { deps += [ ":all_host_gcc_mbedtls" ] } + if (enable_standalone_chip_tool_build) { + deps += [ ":standalone_chip_tool" ] + } + if (enable_standalone_shell_build) { + deps += [ ":standalone_shell" ] + } if (enable_nrf5_lock_app_build) { - deps += [ "${nrf5_lock_app_root}:nrf5(${nrf5_lock_app_root}/toolchain:nrf5_lock_app)" ] + deps += [ ":nrf5_lock_app" ] + } + if (enable_nrf5_lighting_app_build) { + deps += [ ":nrf5_lighting_app" ] } } @@ -155,9 +191,6 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { if (enable_host_gcc_mbdtls_build) { deps += [ ":check_host_gcc_mbedtls" ] } - if (enable_nrf5_lock_app_build) { - deps += [ ":default" ] - } } } } diff --git a/gn/build/toolchain/host_gcc/BUILD.gn b/config/mbedtls/toolchain/BUILD.gn similarity index 69% rename from gn/build/toolchain/host_gcc/BUILD.gn rename to config/mbedtls/toolchain/BUILD.gn index 260b08169ac48f..c8a586d11b789e 100644 --- a/gn/build/toolchain/host_gcc/BUILD.gn +++ b/config/mbedtls/toolchain/BUILD.gn @@ -1,4 +1,3 @@ -# Copyright 2020 The Pigweed Authors # Copyright (c) 2020 Project CHIP Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,11 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -# gn-format disable -import("//build_overrides/pigweed.gni") +import("//build_overrides/chip.gni") -import("$dir_pw_toolchain/generate_toolchain.gni") -import("toolchains.gni") -generate_toolchains("host_toolchains") { - toolchains = pw_toolchain_host_gcc_list +import("//build/toolchain/gcc_toolchain.gni") + +gcc_toolchain("${host_os}_${host_cpu}_gcc_mbedtls") { + toolchain_args = { + current_os = host_os + current_cpu = host_cpu + is_clang = false + chip_crypto = "mbedtls" + } } diff --git a/config/nrf5/toolchain/BUILD.gn b/config/nrf5/toolchain/BUILD.gn new file mode 100644 index 00000000000000..93d5d313d125d9 --- /dev/null +++ b/config/nrf5/toolchain/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("//build/toolchain/arm_gcc/arm_toolchain.gni") + +arm_toolchain("nrf5_lock_app") { + toolchain_args = { + current_os = "freertos" + import("${chip_root}/examples/lock-app/nrf5/args.gni") + } +} + +arm_toolchain("nrf5_lighting_app") { + toolchain_args = { + current_os = "freertos" + import("${chip_root}/examples/lighting-app/nrf5/args.gni") + } +} diff --git a/config/standalone/args.gni b/config/standalone/args.gni new file mode 100644 index 00000000000000..162d52f203c3e5 --- /dev/null +++ b/config/standalone/args.gni @@ -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. + +chip_build_tests = false + +config_network_layer_ble = false +inet_config_enable_async_dns_sockets = false + +project_config_include_dirs = rebase_path([ "." ]) +chip_project_config_include = "" +system_project_config_include = "" diff --git a/gn/build/toolchain/host_clang/BUILD.gn b/config/standalone/toolchain/BUILD.gn similarity index 68% rename from gn/build/toolchain/host_clang/BUILD.gn rename to config/standalone/toolchain/BUILD.gn index 10912d5b8f7546..5c745a8da14998 100644 --- a/gn/build/toolchain/host_clang/BUILD.gn +++ b/config/standalone/toolchain/BUILD.gn @@ -1,4 +1,3 @@ -# Copyright 2020 The Pigweed Authors # Copyright (c) 2020 Project CHIP Authors # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,11 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -# gn-format disable -import("//build_overrides/pigweed.gni") +import("//build_overrides/chip.gni") -import("$dir_pw_toolchain/generate_toolchain.gni") -import("toolchains.gni") -generate_toolchains("host_toolchains") { - toolchains = pw_toolchain_host_clang_list +import("//build/toolchain/gcc_toolchain.gni") + +gcc_toolchain("standalone") { + toolchain_args = { + current_os = host_os + current_cpu = host_cpu + is_clang = false + import("${chip_root}/config/standalone/args.gni") + } } diff --git a/examples/lock-app/nrf5/build_overrides/chip.gni b/examples/build_overrides/chip.gni similarity index 100% rename from examples/lock-app/nrf5/build_overrides/chip.gni rename to examples/build_overrides/chip.gni diff --git a/examples/lock-app/nrf5/build_overrides/lwip.gni b/examples/build_overrides/lwip.gni similarity index 100% rename from examples/lock-app/nrf5/build_overrides/lwip.gni rename to examples/build_overrides/lwip.gni diff --git a/examples/lock-app/nrf5/build_overrides/mbedtls.gni b/examples/build_overrides/mbedtls.gni similarity index 100% rename from examples/lock-app/nrf5/build_overrides/mbedtls.gni rename to examples/build_overrides/mbedtls.gni diff --git a/examples/lock-app/nrf5/build_overrides/nlassert.gni b/examples/build_overrides/nlassert.gni similarity index 100% rename from examples/lock-app/nrf5/build_overrides/nlassert.gni rename to examples/build_overrides/nlassert.gni diff --git a/examples/lock-app/nrf5/build_overrides/nlfaultinjection.gni b/examples/build_overrides/nlfaultinjection.gni similarity index 100% rename from examples/lock-app/nrf5/build_overrides/nlfaultinjection.gni rename to examples/build_overrides/nlfaultinjection.gni diff --git a/examples/lock-app/nrf5/build_overrides/nlio.gni b/examples/build_overrides/nlio.gni similarity index 100% rename from examples/lock-app/nrf5/build_overrides/nlio.gni rename to examples/build_overrides/nlio.gni diff --git a/examples/lock-app/nrf5/build_overrides/nlunit_test.gni b/examples/build_overrides/nlunit_test.gni similarity index 100% rename from examples/lock-app/nrf5/build_overrides/nlunit_test.gni rename to examples/build_overrides/nlunit_test.gni diff --git a/examples/lock-app/nrf5/build_overrides/nrf5_sdk.gni b/examples/build_overrides/nrf5_sdk.gni similarity index 100% rename from examples/lock-app/nrf5/build_overrides/nrf5_sdk.gni rename to examples/build_overrides/nrf5_sdk.gni diff --git a/examples/lock-app/nrf5/build_overrides/pigweed.gni b/examples/build_overrides/pigweed.gni similarity index 90% rename from examples/lock-app/nrf5/build_overrides/pigweed.gni rename to examples/build_overrides/pigweed.gni index e0ceb20c34f32b..0aaf7c4d226844 100644 --- a/examples/lock-app/nrf5/build_overrides/pigweed.gni +++ b/examples/build_overrides/pigweed.gni @@ -14,7 +14,7 @@ declare_args() { # Location of the Pigweed repository. - dir_pigweed = "//third_party/connectedhomeip/third_party/repo/pigweed" + dir_pigweed = "//third_party/connectedhomeip/third_party/pigweed/repo" } import("$dir_pigweed/modules.gni") diff --git a/examples/chip-tool/.gn b/examples/chip-tool/.gn new file mode 100644 index 00000000000000..2129e6fa50ebaa --- /dev/null +++ b/examples/chip-tool/.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/chip-tool/BUILD.gn b/examples/chip-tool/BUILD.gn index c935610a527f00..f0713d89b6269b 100644 --- a/examples/chip-tool/BUILD.gn +++ b/examples/chip-tool/BUILD.gn @@ -21,6 +21,12 @@ assert(chip_build_tools) executable("chip-standalone-demo") { sources = [ "main.cpp" ] + if (is_debug) { + defines = [ "BUILD_RELEASE=0" ] + } else { + defines = [ "BUILD_RELEASE=1" ] + } + public_deps = [ "${chip_root}/src/lib" ] output_dir = "${root_out_dir}/bin" diff --git a/examples/lock-app/nrf5/build_overrides/nrf5_lock_app.gni b/examples/chip-tool/args.gni similarity index 86% rename from examples/lock-app/nrf5/build_overrides/nrf5_lock_app.gni rename to examples/chip-tool/args.gni index 3f8857c41f9ba7..311ddab32d5fe5 100644 --- a/examples/lock-app/nrf5/build_overrides/nrf5_lock_app.gni +++ b/examples/chip-tool/args.gni @@ -12,7 +12,6 @@ # 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 = "//" -} +import("//build_overrides/chip.gni") + +import("${chip_root}/config/standalone/args.gni") diff --git a/examples/chip-tool/build_overrides b/examples/chip-tool/build_overrides new file mode 120000 index 00000000000000..b430cf6a2e6391 --- /dev/null +++ b/examples/chip-tool/build_overrides @@ -0,0 +1 @@ +../build_overrides \ No newline at end of file diff --git a/examples/lighting-app/nrf5/.gn b/examples/lighting-app/nrf5/.gn new file mode 100644 index 00000000000000..94532917636fd3 --- /dev/null +++ b/examples/lighting-app/nrf5/.gn @@ -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. + +# 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 = { + target_cpu = "arm" + target_os = "freertos" + + import("//args.gni") +} diff --git a/examples/lighting-app/nrf5/BUILD.gn b/examples/lighting-app/nrf5/BUILD.gn new file mode 100644 index 00000000000000..743ef07d878844 --- /dev/null +++ b/examples/lighting-app/nrf5/BUILD.gn @@ -0,0 +1,90 @@ +# 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("lighting_app") { + output_name = "chip-nrf52840-lighting-example" + + 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/DataModelHandler.cpp", + "main/LightingManager.cpp", + "main/include/AppEvent.h", + "main/include/AppTask.h", + "main/include/DataModelHandler.h", + "main/include/LightingManager.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 = [ ":lighting_app" ] +} diff --git a/examples/lighting-app/nrf5/args.gni b/examples/lighting-app/nrf5/args.gni new file mode 100644 index 00000000000000..62e4a8f458d9f3 --- /dev/null +++ b/examples/lighting-app/nrf5/args.gni @@ -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}/src/platform/nRF5/args.gni") + +# SDK target. This is overriden to add our SDK app_config.h & defines. +nrf5_sdk_target = get_label_info(":sdk", "label_no_toolchain") + +arm_arch = "armv7e-m" +arm_float_abi = "hard" +arm_cpu = "cortex-m4" +arm_fpu = "fpv4-sp-d16" + +ble_project_config_include = "" +chip_device_project_config_include = "" +chip_project_config_include = "" +inet_project_config_include = "" +system_project_config_include = "" diff --git a/examples/lighting-app/nrf5/build_overrides b/examples/lighting-app/nrf5/build_overrides new file mode 120000 index 00000000000000..e578e73312ebd1 --- /dev/null +++ b/examples/lighting-app/nrf5/build_overrides @@ -0,0 +1 @@ +../../build_overrides \ No newline at end of file diff --git a/examples/lighting-app/nrf5/main/main.cpp b/examples/lighting-app/nrf5/main/main.cpp index 4267a5d3c08949..20c847262ab0d6 100644 --- a/examples/lighting-app/nrf5/main/main.cpp +++ b/examples/lighting-app/nrf5/main/main.cpp @@ -49,24 +49,9 @@ extern "C" { #include "nrf_log_default_backends.h" #endif // NRF_LOG_ENABLED +#include "chipinit.h" #include -#if CHIP_ENABLE_OPENTHREAD -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#endif // CHIP_ENABLE_OPENTHREAD - -#include "chipinit.h" using namespace ::chip; using namespace ::chip::Inet; diff --git a/examples/lock-app/nrf5/.gn b/examples/lock-app/nrf5/.gn index 2129e6fa50ebaa..94532917636fd3 100644 --- a/examples/lock-app/nrf5/.gn +++ b/examples/lock-app/nrf5/.gn @@ -22,5 +22,8 @@ check_system_includes = true secondary_source = "//third_party/connectedhomeip/gn/" default_args = { + target_cpu = "arm" + target_os = "freertos" + import("//args.gni") } diff --git a/examples/lock-app/nrf5/BUILD.gn b/examples/lock-app/nrf5/BUILD.gn index 0ec33ac7d53b0d..ed25aa46530e85 100644 --- a/examples/lock-app/nrf5/BUILD.gn +++ b/examples/lock-app/nrf5/BUILD.gn @@ -51,6 +51,8 @@ nrf5_sdk("sdk") { } executable("lock_app") { + output_name = "chip-nrf52840-lock-example" + public_deps = [ ":sdk", "${chip_root}/src/lib", diff --git a/examples/lock-app/nrf5/args.gni b/examples/lock-app/nrf5/args.gni index a8291bec008034..62e4a8f458d9f3 100644 --- a/examples/lock-app/nrf5/args.gni +++ b/examples/lock-app/nrf5/args.gni @@ -12,13 +12,20 @@ # 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") +import("//build_overrides/chip.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. +import("${chip_root}/src/platform/nRF5/args.gni") + +# SDK target. This is overriden to add our SDK app_config.h & defines. +nrf5_sdk_target = get_label_info(":sdk", "label_no_toolchain") + +arm_arch = "armv7e-m" +arm_float_abi = "hard" +arm_cpu = "cortex-m4" +arm_fpu = "fpv4-sp-d16" + +ble_project_config_include = "" +chip_device_project_config_include = "" +chip_project_config_include = "" +inet_project_config_include = "" +system_project_config_include = "" diff --git a/examples/lock-app/nrf5/build_overrides b/examples/lock-app/nrf5/build_overrides new file mode 120000 index 00000000000000..e578e73312ebd1 --- /dev/null +++ b/examples/lock-app/nrf5/build_overrides @@ -0,0 +1 @@ +../../build_overrides \ No newline at end of file diff --git a/examples/shell/.gn b/examples/shell/.gn new file mode 100644 index 00000000000000..2129e6fa50ebaa --- /dev/null +++ b/examples/shell/.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/shell/BUILD.gn b/examples/shell/BUILD.gn index da409f3c0e9c0e..ed5a84f17cb8a5 100644 --- a/examples/shell/BUILD.gn +++ b/examples/shell/BUILD.gn @@ -27,6 +27,12 @@ executable("chip-shell") { public_deps = [ "${chip_root}/src/lib/shell" ] + if (is_debug) { + defines = [ "BUILD_RELEASE=0" ] + } else { + defines = [ "BUILD_RELEASE=1" ] + } + output_dir = "${root_out_dir}/bin" } diff --git a/gn/build_overrides/nrf5_lock_app.gni b/examples/shell/args.gni similarity index 83% rename from gn/build_overrides/nrf5_lock_app.gni rename to examples/shell/args.gni index ecb6a4c5f45c74..311ddab32d5fe5 100644 --- a/gn/build_overrides/nrf5_lock_app.gni +++ b/examples/shell/args.gni @@ -12,7 +12,6 @@ # 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" -} +import("//build_overrides/chip.gni") + +import("${chip_root}/config/standalone/args.gni") diff --git a/examples/shell/build_overrides b/examples/shell/build_overrides new file mode 120000 index 00000000000000..b430cf6a2e6391 --- /dev/null +++ b/examples/shell/build_overrides @@ -0,0 +1 @@ +../build_overrides \ No newline at end of file diff --git a/gn/build/config/BUILDCONFIG.gn b/gn/build/config/BUILDCONFIG.gn index ac573c4353e3e5..f1c243a1aa00bd 100644 --- a/gn/build/config/BUILDCONFIG.gn +++ b/gn/build/config/BUILDCONFIG.gn @@ -51,9 +51,9 @@ declare_args() { if (host_toolchain == "") { if (_chip_defaults.is_clang) { - host_toolchain = "${_chip_overrides.chip_root}/build/toolchain/host_clang:${host_os}_${host_cpu}_clang" + host_toolchain = "//build/toolchain/host:${host_os}_${host_cpu}_clang" } else { - host_toolchain = "${_chip_overrides.chip_root}/build/toolchain/host_gcc:${host_os}_${host_cpu}_gcc" + host_toolchain = "//build/toolchain/host:${host_os}_${host_cpu}_gcc" } } diff --git a/gn/build/config/compiler/BUILD.gn b/gn/build/config/compiler/BUILD.gn index fc50a216ab1d19..e5478f76e53bce 100644 --- a/gn/build/config/compiler/BUILD.gn +++ b/gn/build/config/compiler/BUILD.gn @@ -104,6 +104,7 @@ config("disabled_warnings") { ] if (!is_clang) { cflags += [ + "-Wno-psabi", "-Wno-cast-function-type", "-Wno-maybe-uninitialized", "-Wno-unknown-warning-option", diff --git a/gn/build/toolchain/arm_gcc/BUILD.gn b/gn/build/toolchain/arm_gcc/BUILD.gn index 2edca649611cef..adaea6596c2591 100644 --- a/gn/build/toolchain/arm_gcc/BUILD.gn +++ b/gn/build/toolchain/arm_gcc/BUILD.gn @@ -16,4 +16,6 @@ import("arm_toolchain.gni") arm_toolchain("arm_gcc") { + toolchain_args = { + } } diff --git a/gn/build/toolchain/arm_gcc/arm_toolchain.gni b/gn/build/toolchain/arm_gcc/arm_toolchain.gni index 3db265f9e9d6a6..c75c2760280cae 100644 --- a/gn/build/toolchain/arm_gcc/arm_toolchain.gni +++ b/gn/build/toolchain/arm_gcc/arm_toolchain.gni @@ -12,33 +12,21 @@ # 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") +import("//build/toolchain/gcc_toolchain.gni") template("arm_toolchain") { - _arm_gcc_toolchain_tools = { + gcc_toolchain(target_name) { _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 = { + toolchain_args = { current_cpu = "arm" current_os = invoker.current_os + is_clang = false - if (defined(invoker.toolchain_args_file)) { - import(invoker.toolchain_args_file) - } else if (defined(invoker.defaults)) { - forward_variables_from(invoker.defaults, "*") - } + forward_variables_from(invoker.toolchain_args, "*") } } - - generate_toolchains("host_toolchains") { - toolchains = [ _toolchain ] - } } diff --git a/gn/build/toolchain/gcc_toolchain.gni b/gn/build/toolchain/gcc_toolchain.gni new file mode 100644 index 00000000000000..b84da312581cc9 --- /dev/null +++ b/gn/build/toolchain/gcc_toolchain.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. + +import("//build_overrides/pigweed.gni") +import("$dir_pw_toolchain/generate_toolchain.gni") + +template("gcc_toolchain") { + invoker_toolchain_args = invoker.toolchain_args + + _toolchain = { + name = target_name + + ar = "ar" + if (invoker_toolchain_args.is_clang) { + cc = "clang" + cxx = "clang++" + } else { + cc = "gcc" + cxx = "g++" + } + + if (defined(invoker.ar)) { + ar = invoker.ar + } + if (defined(invoker.cc)) { + cc = invoker.cc + } + if (defined(invoker.cxx)) { + cxx = invoker.cxx + } + + is_host_toolchain = invoker_toolchain_args.current_os == host_os + link_group = true + + defaults = { + forward_variables_from(invoker_toolchain_args, "*") + } + } + + generate_toolchains("gcc_toolchains") { + toolchains = [ _toolchain ] + } +} diff --git a/gn/build/toolchain/host/BUILD.gn b/gn/build/toolchain/host/BUILD.gn new file mode 100644 index 00000000000000..3ef74dc94feac7 --- /dev/null +++ b/gn/build/toolchain/host/BUILD.gn @@ -0,0 +1,32 @@ +# 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("//build/toolchain/gcc_toolchain.gni") + +gcc_toolchain("${host_os}_${host_cpu}_gcc") { + toolchain_args = { + current_os = host_os + current_cpu = host_cpu + is_clang = false + } +} + +gcc_toolchain("${host_os}_${host_cpu}_clang") { + toolchain_args = { + current_os = host_os + current_cpu = host_cpu + is_clang = true + } +} diff --git a/gn/build/toolchain/host_clang/toolchains.gni b/gn/build/toolchain/host_clang/toolchains.gni deleted file mode 100644 index 48971f92a9fa7d..00000000000000 --- a/gn/build/toolchain/host_clang/toolchains.gni +++ /dev/null @@ -1,116 +0,0 @@ -# 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/toolchains.gni b/gn/build/toolchain/host_gcc/toolchains.gni deleted file mode 100644 index 2a00fdf6b02fc0..00000000000000 --- a/gn/build/toolchain/host_gcc/toolchains.gni +++ /dev/null @@ -1,98 +0,0 @@ -# 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/chip/tests.gni b/gn/chip/tests.gni index 4e4e3455b758d0..11807f7dc03553 100644 --- a/gn/chip/tests.gni +++ b/gn/chip/tests.gni @@ -15,7 +15,9 @@ declare_args() { # Enable building tests. chip_build_tests = current_os != "freertos" +} +declare_args() { # Enable use of nlfaultinjection. - chip_with_nlfaultinjection = true + chip_with_nlfaultinjection = chip_build_tests } diff --git a/gn_build.sh b/gn_build.sh index ec6f53012a8c01..3bd349c1a5f1d6 100755 --- a/gn_build.sh +++ b/gn_build.sh @@ -46,7 +46,7 @@ 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" + extra_args+=" $nrf5_sdk_args enable_nrf5_builds=true" fi gn --root="$CHIP_ROOT" gen --check "$CHIP_ROOT/out/debug" --args='target_os="all"'"$extra_args" diff --git a/scripts/examples/gn_build_example.sh b/scripts/examples/gn_build_example.sh new file mode 100755 index 00000000000000..edb921a3ab28b3 --- /dev/null +++ b/scripts/examples/gn_build_example.sh @@ -0,0 +1,31 @@ +#!/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 examples GitHub workflow. + +CHIP_ROOT="$(dirname "$0")/../.." + +source "$CHIP_ROOT/scripts/activate.sh" + +set -e +set -x +env + +gn gen --root="$1" "$2" + +ninja -v -C "$2" diff --git a/scripts/examples/gn_nrf_example.sh b/scripts/examples/gn_nrf_example.sh new file mode 100755 index 00000000000000..35814d6e9d0954 --- /dev/null +++ b/scripts/examples/gn_nrf_example.sh @@ -0,0 +1,31 @@ +#!/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 nRF5 examples GitHub workflow. + +CHIP_ROOT="$(dirname "$0")/../.." + +source "$CHIP_ROOT/scripts/activate.sh" + +set -e +set -x +env + +gn gen --root="$1" --args="nrf5_sdk_root=\"$NRF5_SDK_ROOT\"" "$2" + +ninja -v -C "$2" diff --git a/src/ble/BUILD.gn b/src/ble/BUILD.gn index 52d5f503b39836..9a716f5d9a02f3 100644 --- a/src/ble/BUILD.gn +++ b/src/ble/BUILD.gn @@ -50,30 +50,35 @@ source_set("ble_config_header") { public_deps = [ "${chip_root}/src/system:system_config_header" ] } -static_library("ble") { - output_name = "libBleLayer" +if (config_network_layer_ble) { + 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", - ] + 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", - ] + public_deps = [ + ":ble_config_header", + "${chip_root}/src/inet", + "${chip_root}/src/lib/support", + ] + } +} else { + group("ble") { + } } diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn index 443a9be9dd67ac..ba7e4acfadb08a 100644 --- a/src/inet/BUILD.gn +++ b/src/inet/BUILD.gn @@ -93,8 +93,6 @@ static_library("inet") { output_name = "libInetLayer" sources = [ - "AsyncDNSResolverSockets.cpp", - "AsyncDNSResolverSockets.h", "EndPointBasis.cpp", "EndPointBasis.h", "IANAConstants.h", @@ -142,6 +140,13 @@ static_library("inet") { ] } + if (inet_config_enable_async_dns_sockets) { + sources += [ + "AsyncDNSResolverSockets.cpp", + "AsyncDNSResolverSockets.h", + ] + } + if (inet_config_enable_tun_endpoint) { sources += [ "TunEndPoint.cpp", diff --git a/src/inet/inet.gni b/src/inet/inet.gni index 231c388066cd37..cef9907dcafd10 100644 --- a/src/inet/inet.gni +++ b/src/inet/inet.gni @@ -14,6 +14,8 @@ import("//build_overrides/chip.gni") +import("${chip_root}/src/system/system.gni") + declare_args() { # Enable IPv4 support. inet_config_enable_ipv4 = true @@ -21,9 +23,6 @@ declare_args() { # 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 @@ -36,3 +35,9 @@ declare_args() { # Enable TUN endpoint. inet_config_enable_tun_endpoint = current_os == "linux" } + +declare_args() { + # Enable async DNS. + inet_config_enable_async_dns_sockets = + inet_config_enable_dns_resolver && chip_system_config_use_sockets +} diff --git a/src/lib/shell/BUILD.gn b/src/lib/shell/BUILD.gn index 8c3619e8a0aa48..23f59a3d35c69c 100644 --- a/src/lib/shell/BUILD.gn +++ b/src/lib/shell/BUILD.gn @@ -14,6 +14,8 @@ import("//build_overrides/chip.gni") +import("${chip_root}/src/lib/core/core.gni") + static_library("shell") { output_name = "libCHIPShell" @@ -24,9 +26,12 @@ static_library("shell") { "shell.h", "streamer.cpp", "streamer.h", - "streamer_stdio.cpp", ] + if (chip_target_style == "unix") { + sources += [ "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 index 35c112f099cd49..5d5d366ca7a8f6 100644 --- a/src/lib/support/BUILD.gn +++ b/src/lib/support/BUILD.gn @@ -30,7 +30,7 @@ action("gen_chip_version") { "--chip_major=${chip_version_major}", "--chip_minor=${chip_version_minor}", "--chip_patch=${chip_version_patch}", - "--chip_extra={chip_version_extra}", + "--chip_extra=${chip_version_extra}", ] } @@ -63,6 +63,7 @@ support_headers = [ "TimeUtils.h", "logging/CHIPLogging.h", "verhoeff/Verhoeff.h", + "CHIPMem.h", ] static_library("support") { @@ -72,6 +73,8 @@ static_library("support") { "Base64.cpp", "CHIPArgParser.cpp", "CHIPCounter.cpp", + "CHIPMem-Malloc.cpp", + "CHIPMem-SimpleAlloc.cpp", "ErrorStr.cpp", "FibonacciUtils.cpp", "PersistedCounter.cpp", diff --git a/src/lib/support/tests/BUILD.gn b/src/lib/support/tests/BUILD.gn index 90913791da52f5..48fabc8868f4d4 100644 --- a/src/lib/support/tests/BUILD.gn +++ b/src/lib/support/tests/BUILD.gn @@ -23,6 +23,7 @@ chip_test_suite("tests") { sources = [ "TestCHIPArgParser.cpp", "TestCHIPCounter.cpp", + "TestCHIPMem.cpp", "TestErrorStr.cpp", "TestPersistedCounter.cpp", "TestPersistedStorageImplementation.cpp", @@ -40,5 +41,6 @@ chip_test_suite("tests") { "TestErrorStr", "TestCHIPArgParser", "TestTimeUtils", + "TestCHIPMem", ] } diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index 440a748c0b915b..f81ec92b6e535b 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -15,7 +15,7 @@ import("//build_overrides/chip.gni") import("//build_overrides/nlio.gni") -import("${chip_root}/gn/chip/device.gni") +import("device.gni") if (device_platform != "none") { declare_args() { @@ -37,6 +37,14 @@ if (device_platform != "none") { defines += [ "CHIP_DEVICE_PLATFORM_CONFIG_INCLUDE=${chip_device_platform_config_include}" ] } + if (device_platform == "linux") { + defines += [ + "CHIP_DEVICE_LAYER_TARGET_LINUX=1", + "CHIP_DEVICE_LAYER_TARGET=Linux", + ] + } else { + defines += [ "CHIP_DEVICE_LAYER_TARGET_LINUX=0" ] + } if (device_platform == "nrf5") { defines += [ "CHIP_DEVICE_LAYER_TARGET_NRF5=1", @@ -67,7 +75,45 @@ if (device_platform != "none") { public_configs = [ ":platform_config" ] - if (device_platform == "nrf5") { + if (chip_enable_openthread) { + sources += [ "OpenThread/OpenThreadUtils.cpp" ] + } + + if (device_platform == "linux") { + sources += [ + "Linux/BLEManagerImpl.cpp", + "Linux/BLEManagerImpl.h", + "Linux/BlePlatformConfig.h", + "Linux/CHIPDevicePlatformConfig.h", + "Linux/CHIPDevicePlatformEvent.h", + "Linux/CHIPLinuxStorage.cpp", + "Linux/CHIPLinuxStorage.h", + "Linux/CHIPLinuxStorageIni.cpp", + "Linux/CHIPLinuxStorageIni.h", + "Linux/CHIPPlatformConfig.h", + "Linux/ConfigurationManagerImpl.cpp", + "Linux/ConfigurationManagerImpl.h", + "Linux/ConnectivityManagerImpl.cpp", + "Linux/ConnectivityManagerImpl.h", + "Linux/InetPlatformConfig.h", + "Linux/Logging.cpp", + "Linux/PlatformManagerImpl.cpp", + "Linux/PlatformManagerImpl.h", + "Linux/PosixConfig.cpp", + "Linux/PosixConfig.h", + "Linux/SystemPlatformConfig.h", + "Linux/SystemTimeSupport.cpp", + ] + + if (chip_enable_openthread) { + sources += [ + "Linux/ThreadStackManagerImpl.cpp", + "Linux/ThreadStackManagerImpl.h", + ] + } + + public_deps += [ "${chip_root}/third_party/inipp" ] + } else if (device_platform == "nrf5") { sources += [ "FreeRTOS/SystemTimeSupport.cpp", "nRF5/BLEManagerImpl.cpp", @@ -90,6 +136,13 @@ if (device_platform != "none") { "nRF5/nRF5Utils.cpp", "nRF5/nRF5Utils.h", ] + + if (chip_enable_openthread) { + sources += [ + "nRF5/ThreadStackManagerImpl.cpp", + "nRF5/ThreadStackManagerImpl.h", + ] + } } } } else { diff --git a/src/platform/Linux/args.gni b/src/platform/Linux/args.gni new file mode 100644 index 00000000000000..31824728d53f76 --- /dev/null +++ b/src/platform/Linux/args.gni @@ -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. + +device_platform = "linux" + +ble_platform_config_include = "" +chip_device_platform_config_include = + "" +chip_platform_config_include = "" +inet_platform_config_include = "" +system_platform_config_include = "" diff --git a/gn/chip/device.gni b/src/platform/device.gni similarity index 87% rename from gn/chip/device.gni rename to src/platform/device.gni index 5bdddee5c68177..d4b465230824e1 100644 --- a/gn/chip/device.gni +++ b/src/platform/device.gni @@ -15,6 +15,9 @@ declare_args() { # Device platform layer: freertos, nrf5, none. device_platform = "" + + # Enable openthread support. + chip_enable_openthread = false } if (device_platform == "") { @@ -24,5 +27,5 @@ if (device_platform == "") { } assert((current_os != "freertos" && device_platform == "none") || - device_platform == "nrf5", + device_platform == "nrf5" || device_platform == "linux", "Please select a valid value for device_platform") diff --git a/examples/lock-app/nrf5/common_args.gni b/src/platform/nRF5/args.gni similarity index 71% rename from examples/lock-app/nrf5/common_args.gni rename to src/platform/nRF5/args.gni index b3426f5cba12e8..bde932e42db312 100644 --- a/examples/lock-app/nrf5/common_args.gni +++ b/src/platform/nRF5/args.gni @@ -12,15 +12,8 @@ # 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 @@ -30,16 +23,10 @@ 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/src/platform/tests/BUILD.gn b/src/platform/tests/BUILD.gn new file mode 100644 index 00000000000000..8aa9cb62d8974d --- /dev/null +++ b/src/platform/tests/BUILD.gn @@ -0,0 +1,61 @@ +# 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}/src/platform/device.gni") + +if (device_platform != "none") { + import("${chip_root}/gn/chip/chip_test_suite.gni") + + chip_test_suite("tests") { + output_name = "libPlatformTests" + + sources = [ + "TestConfigurationMgr.cpp", + "TestConfigurationMgr.h", + "TestPlatformMgr.cpp", + "TestPlatformMgr.h", + "TestPlatformTime.cpp", + "TestPlatformTime.h", + ] + + public_deps = [ + "${chip_root}/src/lib/support", + "${chip_root}/src/platform", + "${chip_root}/src/system", + "${nlunit_test_root}:nlunit-test", + ] + + tests = [ + "TestConfigurationMgr", + "TestPlatformMgr", + "TestPlatformTime", + ] + + if (chip_enable_openthread) { + sources += [ + "TestThreadStackMgr.cpp", + "TestThreadStackMgr.h", + ] + tests += [ "TestThreadStackMgr" ] + } + } +} else { + import("${chip_root}/gn/chip/chip_test_group.gni") + chip_test_group("tests") { + deps = [] + } +} diff --git a/src/system/BUILD.gn b/src/system/BUILD.gn index 91436caf0f0147..41ef7c19128e9a 100644 --- a/src/system/BUILD.gn +++ b/src/system/BUILD.gn @@ -33,6 +33,9 @@ declare_args() { # Extra header to include in SystemConfig.h for platform. system_platform_config_include = "" + + # Extra include dirs for project configs. + project_config_include_dirs = [] } config("system_config") { @@ -106,6 +109,8 @@ config("system_config") { if (chip_system_config_clock == "gettimeofday") { defines += [ "HAVE_GETTIMEOFDAY=1" ] } + + include_dirs = project_config_include_dirs } source_set("system_config_header") { @@ -153,6 +158,8 @@ static_library("system") { "${nlassert_root}:nlassert", ] + allow_circular_includes_from = [ "${chip_root}/src/lib/support" ] + if (chip_with_nlfaultinjection) { sources += [ "SystemFaultInjection.cpp" ] public_deps += [ "${nlfaultinjection_root}:nlfaultinjection" ] diff --git a/src/transport/BUILD.gn b/src/transport/BUILD.gn index 08f5be2c4fe478..7dc1ae309c0105 100644 --- a/src/transport/BUILD.gn +++ b/src/transport/BUILD.gn @@ -28,6 +28,7 @@ static_library("transport") { "SecureSession.h", "SecureSessionMgr.cpp", "SecureSessionMgr.h", + "Tuple.h", "UDP.cpp", "UDP.h", ] diff --git a/examples/lock-app/nrf5/toolchain/BUILD.gn b/third_party/inipp/BUILD.gn similarity index 72% rename from examples/lock-app/nrf5/toolchain/BUILD.gn rename to third_party/inipp/BUILD.gn index b311daa63968ab..e7f0725eb3be35 100644 --- a/examples/lock-app/nrf5/toolchain/BUILD.gn +++ b/third_party/inipp/BUILD.gn @@ -12,11 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build_overrides/nrf5_lock_app.gni") +config("inipp_config") { + include_dirs = [ "repo/inipp" ] +} -import("//build/toolchain/arm_gcc/arm_toolchain.gni") +source_set("inipp") { + sources = [ "repo/inipp/inipp/inipp.h" ] -arm_toolchain("nrf5_lock_app") { - toolchain_args_file = "${nrf5_lock_app_root}/common_args.gni" - current_os = "freertos" + public_configs = [ ":inipp_config" ] }