From b58488e59fdbf9db93794b6fc97ad101abded960 Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Sun, 17 Dec 2023 10:49:30 -0500 Subject: [PATCH] Make wholesale replacement of lwIP more straightforward (#31025) * Make wholesale replacement of lwIP more straightforward Instead of everyone directly adjusting the definintions in src/lwip, which only works in-tree, clean up the dependencies so that overriding lwip_root works cleanly (ie, without introducing dependencies on $chip_root/src/lwip). See docs in third_party/lwip/BUILD.gn * Fix use of vendored lwip from EFR32 builds * Fix potential .o file naming conflicts If multiple libraries compile src/lwip/freertos/sys_arch.c, this causes problems from having the same .o file name. Use different library names to make sure this does not happen. * Fixups for genio-lighting-app build * Clarify ways to set lwip_root * Restyled by gn --------- Co-authored-by: Restyled.io --- BUILD.gn | 6 +- src/BUILD.gn | 1 - src/inet/BUILD.gn | 7 +- src/inet/tests/BUILD.gn | 1 - src/lwip/BUILD.gn | 23 ++++++- .../mt793x/ConnectivityManagerImpl.cpp | 2 - .../mt793x/NetworkCommissioningWiFiDriver.cpp | 2 + .../mt793x/NetworkCommissioningWiFiDriver.h | 2 +- src/platform/mt793x/args.gni | 2 +- src/platform/mt793x/lwip/BUILD.gn | 6 +- src/platform/silabs/wifi_args.gni | 2 +- src/system/BUILD.gn | 6 +- third_party/lwip/BUILD.gn | 64 +++++++++++++++++++ third_party/mt793x_sdk/mt793x_lwip/BUILD.gn | 44 +++++++++++++ third_party/mt793x_sdk/mt793x_sdk.gni | 3 +- third_party/silabs/BUILD.gn | 7 ++ third_party/silabs/silabs_lwip/BUILD.gn | 51 +++++++++++++++ 17 files changed, 213 insertions(+), 16 deletions(-) create mode 100644 third_party/lwip/BUILD.gn create mode 100644 third_party/mt793x_sdk/mt793x_lwip/BUILD.gn create mode 100644 third_party/silabs/silabs_lwip/BUILD.gn diff --git a/BUILD.gn b/BUILD.gn index 8c7c5bd4f32c7c..587cf891e81efa 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -37,6 +37,10 @@ import("${build_root}/config/compiler/compiler.gni") import("//src/crypto/crypto.gni") +if (chip_with_lwip) { + import("//build_overrides/lwip.gni") +} + if (current_toolchain != "${dir_pw_toolchain}/default:default") { declare_args() { chip_enable_python_modules = @@ -152,7 +156,7 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") { } if (chip_with_lwip) { - deps += [ "${chip_root}/src/lwip" ] + deps += [ "${lwip_root}:lwip" ] } if (chip_build_tools) { diff --git a/src/BUILD.gn b/src/BUILD.gn index 58a7d5b1707bf8..532da2a4d8db3f 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -19,7 +19,6 @@ import("${build_root}/config/compiler/compiler.gni") import("${chip_root}/build/chip/java/config.gni") import("${chip_root}/build/chip/tests.gni") import("${chip_root}/src/ble/ble.gni") -import("${chip_root}/src/lwip/lwip.gni") import("${chip_root}/src/platform/device.gni") import("${chip_root}/src/tracing/tracing_args.gni") diff --git a/src/inet/BUILD.gn b/src/inet/BUILD.gn index 08004fe337d519..8d6c07f40e3412 100644 --- a/src/inet/BUILD.gn +++ b/src/inet/BUILD.gn @@ -20,7 +20,6 @@ import("//build_overrides/nlio.gni") import("${chip_root}/build/chip/buildconfig_header.gni") import("${chip_root}/build/chip/tests.gni") -import("${chip_root}/src/lwip/lwip.gni") import("${chip_root}/src/platform/device.gni") import("inet.gni") @@ -28,6 +27,10 @@ if (chip_system_config_use_open_thread_inet_endpoints) { import("//build_overrides/openthread.gni") } +if (chip_system_config_use_lwip) { + import("//build_overrides/lwip.gni") +} + declare_args() { # Extra header to include in SystemConfig.h for project. chip_inet_project_config_include = "" @@ -105,7 +108,7 @@ static_library("inet") { if (chip_system_config_use_lwip) { sources += [ "EndPointStateLwIP.cpp" ] - public_deps += [ "${chip_root}/src/lwip" ] + public_deps += [ "${lwip_root}:lwip" ] } if (chip_system_config_use_open_thread_inet_endpoints) { diff --git a/src/inet/tests/BUILD.gn b/src/inet/tests/BUILD.gn index df98b8ee30deb6..1a167d738bd257 100644 --- a/src/inet/tests/BUILD.gn +++ b/src/inet/tests/BUILD.gn @@ -18,7 +18,6 @@ import("//build_overrides/nlunit_test.gni") import("${chip_root}/build/chip/chip_test_suite.gni") import("${chip_root}/build/chip/tests.gni") -import("${chip_root}/src/lwip/lwip.gni") import("${chip_root}/src/platform/device.gni") config("tests_config") { diff --git a/src/lwip/BUILD.gn b/src/lwip/BUILD.gn index 9f210f9760f71a..2027ab241f6e05 100644 --- a/src/lwip/BUILD.gn +++ b/src/lwip/BUILD.gn @@ -18,7 +18,6 @@ import("//build_overrides/lwip.gni") import("${chip_root}/build/chip/buildconfig_header.gni") import("${chip_root}/src/lwip/lwip.gni") -import("${lwip_root}/lwip.gni") assert(chip_with_lwip) @@ -97,6 +96,12 @@ buildconfig_header("lwip_buildconfig") { if (current_os == "zephyr" || current_os == "mbed") { group("lwip") { } +} else if (get_path_info(lwip_root, "abspath") != + get_path_info("${chip_root}/third_party/lwip", "abspath")) { + # Redirect old dependencies on ${chip_root}/src/lwip onto ${lwip_root}:lwip + group("lwip") { + public_deps = [ "${lwip_root}:lwip" ] + } } else if (lwip_platform == "external" || lwip_platform == "mw320") { group("lwip") { public_deps = [ ":lwip_buildconfig" ] @@ -115,11 +120,13 @@ if (current_os == "zephyr" || current_os == "mbed") { public_configs += [ "${psoc6_sdk_build_root}:psoc6_sdk_config" ] } } else if (lwip_platform == "qpg") { + import("${lwip_root}/lwip.gni") + config("lwip_config") { include_dirs = [ "freertos" ] } - lwip_target("lwip") { + lwip_target("legacy_lwip") { public = [ "${qpg_sdk_root}/Components/ThirdParty/Lwip/arch/cc.h", "${qpg_sdk_root}/Components/ThirdParty/Lwip/arch/perf.h", @@ -136,6 +143,10 @@ if (current_os == "zephyr" || current_os == "mbed") { "${chip_root}/src:includes", ] } + + group("lwip") { + public_deps = [ ":legacy_lwip" ] + } } else if (lwip_platform == "bl602") { group("lwip") { public_deps = [ ":lwip_buildconfig" ] @@ -173,6 +184,8 @@ if (current_os == "zephyr" || current_os == "mbed") { ] } } else { + import("${lwip_root}/lwip.gni") + config("lwip_config") { include_dirs = [ lwip_platform ] @@ -181,7 +194,7 @@ if (current_os == "zephyr" || current_os == "mbed") { } } - lwip_target("lwip") { + lwip_target("legacy_lwip") { public = [ "${lwip_platform}/arch/cc.h", "${lwip_platform}/arch/perf.h", @@ -233,4 +246,8 @@ if (current_os == "zephyr" || current_os == "mbed") { "${chip_root}/src:includes", ] } + + group("lwip") { + public_deps = [ ":legacy_lwip" ] + } } diff --git a/src/platform/mt793x/ConnectivityManagerImpl.cpp b/src/platform/mt793x/ConnectivityManagerImpl.cpp index 9a0ac2d727a274..e656a98e0e60bd 100644 --- a/src/platform/mt793x/ConnectivityManagerImpl.cpp +++ b/src/platform/mt793x/ConnectivityManagerImpl.cpp @@ -23,8 +23,6 @@ #include #include -#include - #include #include #include diff --git a/src/platform/mt793x/NetworkCommissioningWiFiDriver.cpp b/src/platform/mt793x/NetworkCommissioningWiFiDriver.cpp index df8a372e021c45..97f79f19c38ac3 100644 --- a/src/platform/mt793x/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/mt793x/NetworkCommissioningWiFiDriver.cpp @@ -33,6 +33,8 @@ namespace NetworkCommissioning { namespace { NetworkCommissioning::WiFiScanResponse * sScanResult; GenioScanResponseIterator mScanResponseIter(sScanResult); + +using chip::app::Clusters::NetworkCommissioning::WiFiSecurityBitmap; } // namespace CHIP_ERROR GenioWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeCallback) diff --git a/src/platform/mt793x/NetworkCommissioningWiFiDriver.h b/src/platform/mt793x/NetworkCommissioningWiFiDriver.h index 85822801c4212a..67bc6c114ffda4 100644 --- a/src/platform/mt793x/NetworkCommissioningWiFiDriver.h +++ b/src/platform/mt793x/NetworkCommissioningWiFiDriver.h @@ -122,7 +122,7 @@ class GenioWiFiDriver final : public WiFiDriver CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen); - chip::BitFlags ConvertSecuritytype(wifi_auth_mode_t auth_mode); + chip::BitFlags ConvertSecuritytype(wifi_auth_mode_t auth_mode); void OnConnectWiFiNetwork(); static GenioWiFiDriver & GetInstance() diff --git a/src/platform/mt793x/args.gni b/src/platform/mt793x/args.gni index fc2f48024d00fd..f77f02b0e1b2b0 100644 --- a/src/platform/mt793x/args.gni +++ b/src/platform/mt793x/args.gni @@ -31,7 +31,7 @@ lwip_platform = "mt793x" # Use our porting instad of //third_party/lwip -lwip_root = "${chip_root}/third_party/mt793x_sdk/lwip" +lwip_root = "${mt793x_sdk_build_root}/mt793x_lwip" chip_mdns = "platform" chip_inet_config_enable_ipv4 = true diff --git a/src/platform/mt793x/lwip/BUILD.gn b/src/platform/mt793x/lwip/BUILD.gn index e6115b33340cde..9c0a8cb326c02a 100644 --- a/src/platform/mt793x/lwip/BUILD.gn +++ b/src/platform/mt793x/lwip/BUILD.gn @@ -39,7 +39,7 @@ config("lwip_config") { ] } -lwip_target("lwip") { +lwip_target("mt793x_lwip") { public = [ "${mt793x_sdk_root}/project/mt7933_hdk/apps/${mt793x_project_name}/inc/lwipopts.h" ] sources = [] @@ -53,3 +53,7 @@ lwip_target("lwip") { "${chip_root}/src:includes", ] } + +group("lwip") { + public_deps = [ ":mt793x_lwip" ] +} diff --git a/src/platform/silabs/wifi_args.gni b/src/platform/silabs/wifi_args.gni index ef7155e54132aa..5d523bd3a65d8c 100644 --- a/src/platform/silabs/wifi_args.gni +++ b/src/platform/silabs/wifi_args.gni @@ -35,7 +35,7 @@ if (chip_crypto == "") { chip_use_transitional_commissionable_data_provider = false # Use GSDK lwip instead of CHIP -lwip_root = "${efr32_sdk_build_root}" +lwip_root = "${efr32_sdk_build_root}/silabs_lwip" #lwip_platform = "external" lwip_platform = "silabs" diff --git a/src/system/BUILD.gn b/src/system/BUILD.gn index cc0293ea864642..73acdf1bc24d42 100644 --- a/src/system/BUILD.gn +++ b/src/system/BUILD.gn @@ -23,6 +23,10 @@ import("${chip_root}/build/chip/tests.gni") import("${chip_root}/src/platform/device.gni") import("system.gni") +if (chip_system_config_use_lwip) { + import("//build_overrides/lwip.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. @@ -175,7 +179,7 @@ source_set("system_config_header") { if (target_cpu != "esp32") { if (chip_system_config_use_lwip) { - public_deps += [ "${chip_root}/src/lwip" ] + public_deps += [ "${lwip_root}:lwip" ] } else { if (chip_device_platform == "efr32") { public_deps += [ "${efr32_sdk_build_root}:efr32_sdk" ] diff --git a/third_party/lwip/BUILD.gn b/third_party/lwip/BUILD.gn new file mode 100644 index 00000000000000..b14b4e7a7baca6 --- /dev/null +++ b/third_party/lwip/BUILD.gn @@ -0,0 +1,64 @@ +# 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") + +# Re-export the Matter lwip integration as "lwip" +# +# To depend on lwip while keeping the implementation target +# encapsulated: +# +# import("//build_overrides/lwip.gni") +# +# source_set("foo") { +# public_deps = [ +# "${lwip_root}:lwip", +# ... +# ] +# } +# +# and set up the build_overrides appropriately (a typical lwip_root +# would be //third_party/lwip). +# +# To help define the library, a reusable template is provided as +# lwip_target() in third_party/lwip/lwip.gni. Example usage: +# +# //example/lwip/BUILD.gn: +# +# config("lwip_config") { +# include_dirs = [ "include" ] +# } +# +# lwip_target("lwip") { +# public = [ +# "include/lwipopts.h" +# ] +# +# sources = [ "sys_arch.c" ] +# +# public_configs = [ +# ":lwip_config", +# ] +# } +# +# Then set lwip_root = "//example/lwip" in build_overrides (or, +# if declared as an argument in build_overrides, via args). +# +# Defining the library directly works too. +# +# If there's no include paths to add, defines to set, sources to +# compile, or libraries to link, then an empty group target suffices. +group("lwip") { + public_deps = [ "${chip_root}/src/lwip:lwip" ] +} diff --git a/third_party/mt793x_sdk/mt793x_lwip/BUILD.gn b/third_party/mt793x_sdk/mt793x_lwip/BUILD.gn new file mode 100644 index 00000000000000..1bb1263d5973fe --- /dev/null +++ b/third_party/mt793x_sdk/mt793x_lwip/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 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/mt793x_sdk.gni") + +import("${mt793x_sdk_build_root}/lwip/lwip.gni") + +config("lwip_config") { + include_dirs = [ + "${chip_root}/src/lwip/mt793x", + "${chip_root}/src/lwip/freertos", + ] +} + +lwip_target("lwip") { + public = [ + "${chip_root}/src/lwip/mt793x/arch/cc.h", + "${chip_root}/src/lwip/mt793x/arch/perf.h", + "${chip_root}/src/lwip/mt793x/lwipopts.h", + ] + + sources = [] + + public_deps = [ + "${chip_root}/src/lwip:lwip_buildconfig", + "${mt793x_sdk_build_root}:mt793x_sdk", + ] + + public_configs = [ + ":lwip_config", + "${chip_root}/src:includes", + ] +} diff --git a/third_party/mt793x_sdk/mt793x_sdk.gni b/third_party/mt793x_sdk/mt793x_sdk.gni index 82db0affed9cf9..709a00afeb5bd0 100644 --- a/third_party/mt793x_sdk/mt793x_sdk.gni +++ b/third_party/mt793x_sdk/mt793x_sdk.gni @@ -13,10 +13,11 @@ # limitations under the License. # import("//build_overrides/chip.gni") +import("//build_overrides/lwip.gni") import("//build_overrides/mbedtls.gni") import("//build_overrides/mt793x_sdk.gni") import("${chip_root}/src/crypto/crypto.gni") -import("${chip_root}/src/platform/mt793x/args.gni") +import("${chip_root}/src/platform/device.gni") import("${chip_root}/src/platform/mt793x/lwip/lwip.gni") # diff --git a/third_party/silabs/BUILD.gn b/third_party/silabs/BUILD.gn index 2e1b8092e81ed3..2326a73ab09121 100644 --- a/third_party/silabs/BUILD.gn +++ b/third_party/silabs/BUILD.gn @@ -16,6 +16,7 @@ import("//build_overrides/chip.gni") import("//build_overrides/efr32_sdk.gni") import("//build_overrides/jlink.gni") import("//build_overrides/openthread.gni") +import("${chip_root}/src/lwip/lwip.gni") import("${chip_root}/src/platform/device.gni") import("${efr32_sdk_build_root}/silabs_board.gni") @@ -53,6 +54,12 @@ group("efr32_sdk") { public_configs = [ ":silabs_config" ] } +if (chip_with_lwip) { + group("lwip") { + public_deps = [ "silabs_lwip:lwip" ] + } +} + if (wifi_soc != true) { # CCP board # Openthread GSDK libraries configurations diff --git a/third_party/silabs/silabs_lwip/BUILD.gn b/third_party/silabs/silabs_lwip/BUILD.gn new file mode 100644 index 00000000000000..223ad948e0d85d --- /dev/null +++ b/third_party/silabs/silabs_lwip/BUILD.gn @@ -0,0 +1,51 @@ +# Copyright (c) 2023 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/efr32_sdk.gni") + +import("../lwip.gni") + +config("lwip_config") { + include_dirs = [ + "${chip_root}/src/lwip/silabs", + "${chip_root}/src/lwip/freertos", + ] +} + +lwip_target("silabs_lwip") { + public = [ + "${chip_root}/src/lwip/freertos/arch/sys_arch.h", + "${chip_root}/src/lwip/silabs/arch/cc.h", + "${chip_root}/src/lwip/silabs/arch/perf.h", + "${chip_root}/src/lwip/silabs/lwipopts.h", + "${chip_root}/src/lwip/silabs/lwippools.h", + ] + + sources = [ "${chip_root}/src/lwip/freertos/sys_arch.c" ] + + public_deps = [ + "${chip_root}/src/lwip:lwip_buildconfig", + "${efr32_sdk_build_root}:efr32_sdk", + ] + + public_configs = [ + ":lwip_config", + "${chip_root}/src:includes", + ] +} + +group("lwip") { + public_deps = [ ":silabs_lwip" ] +}