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 <commits@restyled.io>
diff --git a/BUILD.gn b/BUILD.gn
index 8c7c5bd..587cf89 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -37,6 +37,10 @@
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 (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 58a7d5b..532da2a 100644
--- a/src/BUILD.gn
+++ b/src/BUILD.gn
@@ -19,7 +19,6 @@
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 08004fe..8d6c07f 100644
--- a/src/inet/BUILD.gn
+++ b/src/inet/BUILD.gn
@@ -20,7 +20,6 @@
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 @@
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 @@
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 df98b8e..1a167d7 100644
--- a/src/inet/tests/BUILD.gn
+++ b/src/inet/tests/BUILD.gn
@@ -18,7 +18,6 @@
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 9f210f9..2027ab2 100644
--- a/src/lwip/BUILD.gn
+++ b/src/lwip/BUILD.gn
@@ -18,7 +18,6 @@
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 @@
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 @@
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 @@
"${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 @@
]
}
} else {
+ import("${lwip_root}/lwip.gni")
+
config("lwip_config") {
include_dirs = [ lwip_platform ]
@@ -181,7 +194,7 @@
}
}
- lwip_target("lwip") {
+ lwip_target("legacy_lwip") {
public = [
"${lwip_platform}/arch/cc.h",
"${lwip_platform}/arch/perf.h",
@@ -233,4 +246,8 @@
"${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 9a0ac2d..e656a98 100644
--- a/src/platform/mt793x/ConnectivityManagerImpl.cpp
+++ b/src/platform/mt793x/ConnectivityManagerImpl.cpp
@@ -23,8 +23,6 @@
#include <platform/ConnectivityManager.h>
#include <platform/internal/BLEManager.h>
-#include <app/server/Dnssd.h>
-
#include <lwip/dns.h>
#include <lwip/ip_addr.h>
#include <lwip/nd6.h>
diff --git a/src/platform/mt793x/NetworkCommissioningWiFiDriver.cpp b/src/platform/mt793x/NetworkCommissioningWiFiDriver.cpp
index df8a372..97f79f1 100644
--- a/src/platform/mt793x/NetworkCommissioningWiFiDriver.cpp
+++ b/src/platform/mt793x/NetworkCommissioningWiFiDriver.cpp
@@ -33,6 +33,8 @@
namespace {
NetworkCommissioning::WiFiScanResponse * sScanResult;
GenioScanResponseIterator<NetworkCommissioning::WiFiScanResponse> 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 8582280..67bc6c1 100644
--- a/src/platform/mt793x/NetworkCommissioningWiFiDriver.h
+++ b/src/platform/mt793x/NetworkCommissioningWiFiDriver.h
@@ -122,7 +122,7 @@
CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen);
- chip::BitFlags<WiFiSecurityBitmap> ConvertSecuritytype(wifi_auth_mode_t auth_mode);
+ chip::BitFlags<app::Clusters::NetworkCommissioning::WiFiSecurityBitmap> 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 fc2f480..f77f02b 100644
--- a/src/platform/mt793x/args.gni
+++ b/src/platform/mt793x/args.gni
@@ -31,7 +31,7 @@
# 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 e6115b3..9c0a8cb 100644
--- a/src/platform/mt793x/lwip/BUILD.gn
+++ b/src/platform/mt793x/lwip/BUILD.gn
@@ -39,7 +39,7 @@
]
}
-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 @@
"${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 ef7155e..5d523bd 100644
--- a/src/platform/silabs/wifi_args.gni
+++ b/src/platform/silabs/wifi_args.gni
@@ -35,7 +35,7 @@
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 cc0293e..73acdf1 100644
--- a/src/system/BUILD.gn
+++ b/src/system/BUILD.gn
@@ -23,6 +23,10 @@
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 @@
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 0000000..b14b4e7
--- /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 0000000..1bb1263
--- /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 82db0af..709a00a 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 2e1b809..2326a73 100644
--- a/third_party/silabs/BUILD.gn
+++ b/third_party/silabs/BUILD.gn
@@ -16,6 +16,7 @@
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 @@
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 0000000..223ad94
--- /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" ]
+}