Skip to content

Commit

Permalink
[gn] add zephyr platform to gn build system (#2320)
Browse files Browse the repository at this point in the history
* [gn] add nRF Connect SDK support with gn

* [nrfconnect] include missing header in device layer

* [core] fix signed/unsigned comparison

* [thread] use proper sprintf format for uint32_t

* [zephyr] remove uses of deprecated types and fix casting

* [nrfconnect] clean up unused include

* [github] move nRF Connect build configuration
  • Loading branch information
e-rk authored Aug 31, 2020
1 parent 7c31226 commit 90bc94c
Show file tree
Hide file tree
Showing 24 changed files with 374 additions and 214 deletions.
46 changes: 0 additions & 46 deletions .github/workflows/examples-autotools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,49 +64,3 @@ jobs:
${{ env.BUILD_TYPE }}-example-build-${{
steps.outsuffix.outputs.value }}
path: /tmp/output_binaries/${{ env.BUILD_TYPE }}-build

nrfconnect:
name: nRF Connect SDK

env:
BUILD_TYPE: nrfconnect

runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-nrf-platform:0.4.2
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
- "/tmp/output_binaries:/tmp/output_binaries"

steps:
- name: Checkout
uses: actions/checkout@v2
# Fetch depth 0 to get all history and be able to check mergepoint for bloat report
with:
fetch-depth: 0
submodules: true
- name: Build example nRF Connect SDK Lock App
run: scripts/examples/nrfconnect_lock_app.sh
- name: Copy aside build products
run: |
mkdir -p example_binaries/$BUILD_TYPE-build
cp examples/lock-app/nrfconnect/build/zephyr/zephyr.elf \
example_binaries/$BUILD_TYPE-build/chip-nrf52840-lock-example.elf
- name: Binary artifact suffix
id: outsuffix
uses: haya14busa/[email protected]
with:
cond: ${{ github.event.pull_request.number == '' }}
if_true: "${{ github.sha }}"
if_false: "pull-${{ github.event.pull_request.number }}"
- name: Copy aside bloat report & binaries
run: |
cp -r example_binaries/$BUILD_TYPE-build /tmp/output_binaries/
- name: Uploading Binaries
uses: actions/upload-artifact@v1
with:
name:
${{ env.BUILD_TYPE }}-example-build-${{
steps.outsuffix.outputs.value }}
path: /tmp/output_binaries/${{ env.BUILD_TYPE }}-build
45 changes: 45 additions & 0 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,48 @@ jobs:
steps.outsuffix.outputs.value }}
path: |
out/lock_app_debug/BRD4161A/chip-efr32-lock-example.out
nrfconnect:
name: nRF Connect SDK
env:
BUILD_TYPE: nrfconnect

runs-on: ubuntu-latest

container:
image: connectedhomeip/chip-build-nrf-platform:0.4.2
volumes:
- "/tmp/bloat_reports:/tmp/bloat_reports"
- "/tmp/output_binaries:/tmp/output_binaries"

steps:
- name: Checkout
uses: actions/checkout@v2
# Fetch depth 0 to get all history and be able to check mergepoint for bloat report
with:
fetch-depth: 0
submodules: true
- name: Build example nRF Connect SDK Lock App
run: scripts/examples/nrfconnect_lock_app.sh
- name: Copy aside build products
run: |
mkdir -p example_binaries/$BUILD_TYPE-build
cp examples/lock-app/nrfconnect/build/zephyr/zephyr.elf \
example_binaries/$BUILD_TYPE-build/chip-nrf52840-lock-example.elf
- name: Binary artifact suffix
id: outsuffix
uses: haya14busa/[email protected]
with:
cond: ${{ github.event.pull_request.number == '' }}
if_true: "${{ github.sha }}"
if_false: "pull-${{ github.event.pull_request.number }}"
- name: Copy aside bloat report & binaries
run: |
cp -r example_binaries/$BUILD_TYPE-build /tmp/output_binaries/
- name: Uploading Binaries
uses: actions/upload-artifact@v1
with:
name:
${{ env.BUILD_TYPE }}-example-build-${{
steps.outsuffix.outputs.value }}
path: /tmp/output_binaries/${{ env.BUILD_TYPE }}-build
29 changes: 29 additions & 0 deletions config/nrfconnect/.gn
Original file line number Diff line number Diff line change
@@ -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 = "zephyr"

import("//args.gni")
}
30 changes: 30 additions & 0 deletions config/nrfconnect/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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")

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

assert(current_os == "zephyr")

group("dummy") {
}

group("nrfconnect") {
deps = [ "${chip_root}/src/lib" ]
}

group("default") {
deps = [ ":nrfconnect" ]
}
38 changes: 38 additions & 0 deletions config/nrfconnect/args.gni
Original file line number Diff line number Diff line change
@@ -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")

nrfconnect_target = get_label_info(":nrfconnect", "label_no_toolchain")

chip_device_platform = "nrfconnect"
chip_logging_style = "external"

chip_config_network_layer_ble = true

chip_project_config_include = "<CHIPProjectConfig.h>"
chip_ble_project_config_include = chip_project_config_include
chip_device_project_config_include = chip_project_config_include
chip_inet_project_config_include = chip_project_config_include
chip_system_project_config_include = chip_project_config_include

chip_build_tests = false
chip_inet_config_enable_tun_endpoint = chip_build_tests
chip_inet_config_enable_raw_endpoint = chip_build_tests
chip_inet_config_enable_tcp_endpoint = chip_build_tests
chip_inet_config_enable_dns_resolver = chip_build_tests
chip_inet_config_enable_ipv4 = chip_build_tests
custom_toolchain = "//toolchain:zephyr"

mbedtls_target = "//:dummy"
1 change: 1 addition & 0 deletions config/nrfconnect/build_overrides
93 changes: 36 additions & 57 deletions config/nrfconnect/chip-lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@ include(ExternalProject)
# Directory for CHIP build artifacts
set(CHIP_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/chip")

# Helper macros to conditionally append a list
macro(append_if VAR CONDITION)
macro(chip_gn_arg_bool_if CONDITION ARGSTRING GN_VARNAME)
if (${${CONDITION}})
list(APPEND ${VAR} ${ARGN})
string(APPEND ${ARGSTRING} "${GN_VARNAME} = true\n")
else ()
string(APPEND ${ARGSTRING} "${GN_VARNAME} = false\n")
endif()
endmacro()

macro(append_if_not VAR CONDITION)
if (${${CONDITION}})
else()
list(APPEND ${VAR} ${ARGN})
endif()
macro(chip_gn_arg_string ARGSTRING GN_STRING)
string(APPEND ${ARGSTRING} "${GN_STRING}\n")
endmacro()

# Function to retrieve Zephyr compilation flags for the given language (C or CXX)
Expand All @@ -61,10 +59,10 @@ endfunction()
# ==================================================

function(chip_configure TARGET_NAME)
cmake_parse_arguments(CHIP
cmake_parse_arguments(CHIP
"BUILD_TESTS"
"ARCH;PROJECT_CONFIG"
"CFLAGS;CXXFLAGS"
"PROJECT_CONFIG"
"CFLAGS;CXXFLAGS"
${ARGN})

# Prepare CFLAGS & CXXFLAGS
Expand All @@ -75,67 +73,45 @@ function(chip_configure TARGET_NAME)
list(FILTER CHIP_CXXFLAGS EXCLUDE REGEX -std.*) # CHIP adds gnu++11 anyway...
convert_list_of_flags_to_string_of_flags(CHIP_CXXFLAGS CHIP_CXXFLAGS)

# Prepare command line arguments passed to the CHIP's ./configure script
set(CHIP_CONFIGURE_ARGS
AR=${CMAKE_AR}
AS=${CMAKE_AS}
CC=${CMAKE_C_COMPILER}
CXX=${CMAKE_CXX_COMPILER}
LD=${CMAKE_LINKER}
OBJCOPY=${CMAKE_OBJCOPY}
RANLIB=${CMAKE_RANLIB}
CFLAGS=${CHIP_CFLAGS}
CXXFLAGS=${CHIP_CXXFLAGS}
--prefix=${CHIP_OUTPUT_DIR}
--exec-prefix=${CHIP_OUTPUT_DIR}
--host=${CHIP_ARCH}
--with-device-layer=nrfconnect
--with-network-layer=all
--with-target-network=sockets
--with-inet-endpoint=udp
--with-logging-style=external
--with-target-style=embedded
--with-chip-project-includes=${CHIP_PROJECT_CONFIG}
--with-chip-system-project-includes=${CHIP_PROJECT_CONFIG}
--with-chip-inet-project-includes=${CHIP_PROJECT_CONFIG}
--with-chip-ble-project-includes=${CHIP_PROJECT_CONFIG}
--with-chip-warm-project-includes=${CHIP_PROJECT_CONFIG}
--with-chip-device-project-includes=${CHIP_PROJECT_CONFIG}
--enable-debug
--enable-optimization=no
--disable-tools
--disable-docs
--disable-java
--disable-device-manager
--with-crypto=mbedtls
)

append_if(CHIP_CONFIGURE_ARGS CONFIG_NET_L2_OPENTHREAD --with-openthread=${ZEPHYR_BASE}/../modules/lib/openthread)
append_if(CHIP_CONFIGURE_ARGS CONFIG_NORDIC_SECURITY_BACKEND --with-mbedtls=${ZEPHYR_BASE}/../mbedtls)
append_if_not(CHIP_CONFIGURE_ARGS CHIP_BUILD_TESTS --disable-tests)
append_if_not(CHIP_CONFIGURE_ARGS CONFIG_NET_IPV4 --disable-ipv4)
append_if_not(CHIP_CONFIGURE_ARGS CONFIG_NORDIC_SECURITY_BACKEND --with-mbedtls=${ZEPHYR_BASE}/../modules/crypto/mbedtls)
set(GN_ARGS "")
chip_gn_arg_string(GN_ARGS "target_cflags_c = string_split(\"${CHIP_CFLAGS}\")")
chip_gn_arg_string(GN_ARGS "target_cflags_cc = string_split(\"${CHIP_CXXFLAGS}\")")
chip_gn_arg_string(GN_ARGS "zephyr_ar = \"${CMAKE_AR}\"")
chip_gn_arg_string(GN_ARGS "zephyr_cc = \"${CMAKE_C_COMPILER}\"")
chip_gn_arg_string(GN_ARGS "zephyr_cxx = \"${CMAKE_CXX_COMPILER}\"")

if (NOT "${CHIP_PROJECT_CONFIG}" STREQUAL "")
chip_gn_arg_string(GN_ARGS "chip_project_config_include = \"<${CHIP_PROJECT_CONFIG}>\"")
endif ()

chip_gn_arg_bool_if(CONFIG_NET_L2_OPENTHREAD GN_ARGS "chip_enable_openthread")
chip_gn_arg_bool_if(CHIP_BUILD_TESTS GN_ARGS "chip_build_tests")

file(
GENERATE OUTPUT ${CHIP_OUTPUT_DIR}/args.gn
CONTENT "${GN_ARGS}"
)
# Define target
ExternalProject_Add(
${TARGET_NAME}
PREFIX ${CHIP_OUTPUT_DIR}
SOURCE_DIR ${CHIP_ROOT}
BINARY_DIR ${CHIP_OUTPUT_DIR}
CONFIGURE_COMMAND ${CHIP_ROOT}/configure ${CHIP_CONFIGURE_ARGS}
CONFIGURE_COMMAND gn --root=${CHIP_ROOT}/config/nrfconnect gen ${CHIP_OUTPUT_DIR}
BUILD_COMMAND ""
INSTALL_COMMAND ""
BUILD_ALWAYS TRUE
USES_TERMINAL_CONFIGURE TRUE
)
endfunction()

# ==================================================
# Define chip build target
# ==================================================
# ==================================================

function(chip_build TARGET_NAME BASE_TARGET_NAME)
cmake_parse_arguments(CHIP "" "" "BUILD_COMMAND;BUILD_ARTIFACTS" ${ARGN})

# Define build target
ExternalProject_Add(
${TARGET_NAME}Build
Expand All @@ -147,6 +123,7 @@ function(chip_build TARGET_NAME BASE_TARGET_NAME)
INSTALL_COMMAND ""
BUILD_BYPRODUCTS ${CHIP_BUILD_ARTIFACTS}
BUILD_ALWAYS TRUE
USES_TERMINAL_BUILD TRUE
)

# Define interface library containing desired CHIP byproducts
Expand All @@ -156,12 +133,14 @@ function(chip_build TARGET_NAME BASE_TARGET_NAME)
${CHIP_ROOT}/src/lib
${CHIP_ROOT}/src/lib/core
${CHIP_ROOT}/src/include
${CHIP_OUTPUT_DIR}/include
${CHIP_OUTPUT_DIR}/src/include
${CHIP_ROOT}/third_party/nlassert/repo/include
${CHIP_OUTPUT_DIR}/gen/include
${CHIP_OUTPUT_DIR}/gen/third_party/connectedhomeip/src/lib/support/include
${CHIP_OUTPUT_DIR}/gen/third_party/connectedhomeip/src/app/include
)
target_link_directories(${TARGET_NAME} INTERFACE ${CHIP_OUTPUT_DIR}/lib)
target_link_libraries(${TARGET_NAME} INTERFACE -Wl,--start-group ${CHIP_BUILD_ARTIFACTS} -Wl,--end-group)

add_dependencies(${TARGET_NAME}Build ${BASE_TARGET_NAME})
add_dependencies(${TARGET_NAME} ${TARGET_NAME}Build)
endfunction()
endfunction()
Loading

0 comments on commit 90bc94c

Please sign in to comment.