Skip to content

Commit b58488e

Browse files
Make wholesale replacement of lwIP more straightforward (project-chip#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>
1 parent ea52241 commit b58488e

File tree

17 files changed

+213
-16
lines changed

17 files changed

+213
-16
lines changed

BUILD.gn

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import("${build_root}/config/compiler/compiler.gni")
3737

3838
import("//src/crypto/crypto.gni")
3939

40+
if (chip_with_lwip) {
41+
import("//build_overrides/lwip.gni")
42+
}
43+
4044
if (current_toolchain != "${dir_pw_toolchain}/default:default") {
4145
declare_args() {
4246
chip_enable_python_modules =
@@ -152,7 +156,7 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
152156
}
153157

154158
if (chip_with_lwip) {
155-
deps += [ "${chip_root}/src/lwip" ]
159+
deps += [ "${lwip_root}:lwip" ]
156160
}
157161

158162
if (chip_build_tools) {

src/BUILD.gn

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import("${build_root}/config/compiler/compiler.gni")
1919
import("${chip_root}/build/chip/java/config.gni")
2020
import("${chip_root}/build/chip/tests.gni")
2121
import("${chip_root}/src/ble/ble.gni")
22-
import("${chip_root}/src/lwip/lwip.gni")
2322
import("${chip_root}/src/platform/device.gni")
2423
import("${chip_root}/src/tracing/tracing_args.gni")
2524

src/inet/BUILD.gn

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ import("//build_overrides/nlio.gni")
2020

2121
import("${chip_root}/build/chip/buildconfig_header.gni")
2222
import("${chip_root}/build/chip/tests.gni")
23-
import("${chip_root}/src/lwip/lwip.gni")
2423
import("${chip_root}/src/platform/device.gni")
2524
import("inet.gni")
2625

2726
if (chip_system_config_use_open_thread_inet_endpoints) {
2827
import("//build_overrides/openthread.gni")
2928
}
3029

30+
if (chip_system_config_use_lwip) {
31+
import("//build_overrides/lwip.gni")
32+
}
33+
3134
declare_args() {
3235
# Extra header to include in SystemConfig.h for project.
3336
chip_inet_project_config_include = ""
@@ -105,7 +108,7 @@ static_library("inet") {
105108

106109
if (chip_system_config_use_lwip) {
107110
sources += [ "EndPointStateLwIP.cpp" ]
108-
public_deps += [ "${chip_root}/src/lwip" ]
111+
public_deps += [ "${lwip_root}:lwip" ]
109112
}
110113

111114
if (chip_system_config_use_open_thread_inet_endpoints) {

src/inet/tests/BUILD.gn

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import("//build_overrides/nlunit_test.gni")
1818

1919
import("${chip_root}/build/chip/chip_test_suite.gni")
2020
import("${chip_root}/build/chip/tests.gni")
21-
import("${chip_root}/src/lwip/lwip.gni")
2221
import("${chip_root}/src/platform/device.gni")
2322

2423
config("tests_config") {

src/lwip/BUILD.gn

+20-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import("//build_overrides/lwip.gni")
1818

1919
import("${chip_root}/build/chip/buildconfig_header.gni")
2020
import("${chip_root}/src/lwip/lwip.gni")
21-
import("${lwip_root}/lwip.gni")
2221

2322
assert(chip_with_lwip)
2423

@@ -97,6 +96,12 @@ buildconfig_header("lwip_buildconfig") {
9796
if (current_os == "zephyr" || current_os == "mbed") {
9897
group("lwip") {
9998
}
99+
} else if (get_path_info(lwip_root, "abspath") !=
100+
get_path_info("${chip_root}/third_party/lwip", "abspath")) {
101+
# Redirect old dependencies on ${chip_root}/src/lwip onto ${lwip_root}:lwip
102+
group("lwip") {
103+
public_deps = [ "${lwip_root}:lwip" ]
104+
}
100105
} else if (lwip_platform == "external" || lwip_platform == "mw320") {
101106
group("lwip") {
102107
public_deps = [ ":lwip_buildconfig" ]
@@ -115,11 +120,13 @@ if (current_os == "zephyr" || current_os == "mbed") {
115120
public_configs += [ "${psoc6_sdk_build_root}:psoc6_sdk_config" ]
116121
}
117122
} else if (lwip_platform == "qpg") {
123+
import("${lwip_root}/lwip.gni")
124+
118125
config("lwip_config") {
119126
include_dirs = [ "freertos" ]
120127
}
121128

122-
lwip_target("lwip") {
129+
lwip_target("legacy_lwip") {
123130
public = [
124131
"${qpg_sdk_root}/Components/ThirdParty/Lwip/arch/cc.h",
125132
"${qpg_sdk_root}/Components/ThirdParty/Lwip/arch/perf.h",
@@ -136,6 +143,10 @@ if (current_os == "zephyr" || current_os == "mbed") {
136143
"${chip_root}/src:includes",
137144
]
138145
}
146+
147+
group("lwip") {
148+
public_deps = [ ":legacy_lwip" ]
149+
}
139150
} else if (lwip_platform == "bl602") {
140151
group("lwip") {
141152
public_deps = [ ":lwip_buildconfig" ]
@@ -173,6 +184,8 @@ if (current_os == "zephyr" || current_os == "mbed") {
173184
]
174185
}
175186
} else {
187+
import("${lwip_root}/lwip.gni")
188+
176189
config("lwip_config") {
177190
include_dirs = [ lwip_platform ]
178191

@@ -181,7 +194,7 @@ if (current_os == "zephyr" || current_os == "mbed") {
181194
}
182195
}
183196

184-
lwip_target("lwip") {
197+
lwip_target("legacy_lwip") {
185198
public = [
186199
"${lwip_platform}/arch/cc.h",
187200
"${lwip_platform}/arch/perf.h",
@@ -233,4 +246,8 @@ if (current_os == "zephyr" || current_os == "mbed") {
233246
"${chip_root}/src:includes",
234247
]
235248
}
249+
250+
group("lwip") {
251+
public_deps = [ ":legacy_lwip" ]
252+
}
236253
}

src/platform/mt793x/ConnectivityManagerImpl.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#include <platform/ConnectivityManager.h>
2424
#include <platform/internal/BLEManager.h>
2525

26-
#include <app/server/Dnssd.h>
27-
2826
#include <lwip/dns.h>
2927
#include <lwip/ip_addr.h>
3028
#include <lwip/nd6.h>

src/platform/mt793x/NetworkCommissioningWiFiDriver.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace NetworkCommissioning {
3333
namespace {
3434
NetworkCommissioning::WiFiScanResponse * sScanResult;
3535
GenioScanResponseIterator<NetworkCommissioning::WiFiScanResponse> mScanResponseIter(sScanResult);
36+
37+
using chip::app::Clusters::NetworkCommissioning::WiFiSecurityBitmap;
3638
} // namespace
3739

3840
CHIP_ERROR GenioWiFiDriver::Init(NetworkStatusChangeCallback * networkStatusChangeCallback)

src/platform/mt793x/NetworkCommissioningWiFiDriver.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class GenioWiFiDriver final : public WiFiDriver
122122

123123
CHIP_ERROR ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, const char * key, uint8_t keyLen);
124124

125-
chip::BitFlags<WiFiSecurityBitmap> ConvertSecuritytype(wifi_auth_mode_t auth_mode);
125+
chip::BitFlags<app::Clusters::NetworkCommissioning::WiFiSecurityBitmap> ConvertSecuritytype(wifi_auth_mode_t auth_mode);
126126

127127
void OnConnectWiFiNetwork();
128128
static GenioWiFiDriver & GetInstance()

src/platform/mt793x/args.gni

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ lwip_platform = "mt793x"
3131

3232
# Use our porting instad of //third_party/lwip
3333

34-
lwip_root = "${chip_root}/third_party/mt793x_sdk/lwip"
34+
lwip_root = "${mt793x_sdk_build_root}/mt793x_lwip"
3535

3636
chip_mdns = "platform"
3737
chip_inet_config_enable_ipv4 = true

src/platform/mt793x/lwip/BUILD.gn

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ config("lwip_config") {
3939
]
4040
}
4141

42-
lwip_target("lwip") {
42+
lwip_target("mt793x_lwip") {
4343
public = [ "${mt793x_sdk_root}/project/mt7933_hdk/apps/${mt793x_project_name}/inc/lwipopts.h" ]
4444

4545
sources = []
@@ -53,3 +53,7 @@ lwip_target("lwip") {
5353
"${chip_root}/src:includes",
5454
]
5555
}
56+
57+
group("lwip") {
58+
public_deps = [ ":mt793x_lwip" ]
59+
}

src/platform/silabs/wifi_args.gni

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ if (chip_crypto == "") {
3535
chip_use_transitional_commissionable_data_provider = false
3636

3737
# Use GSDK lwip instead of CHIP
38-
lwip_root = "${efr32_sdk_build_root}"
38+
lwip_root = "${efr32_sdk_build_root}/silabs_lwip"
3939

4040
#lwip_platform = "external"
4141
lwip_platform = "silabs"

src/system/BUILD.gn

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import("${chip_root}/build/chip/tests.gni")
2323
import("${chip_root}/src/platform/device.gni")
2424
import("system.gni")
2525

26+
if (chip_system_config_use_lwip) {
27+
import("//build_overrides/lwip.gni")
28+
}
29+
2630
declare_args() {
2731
# Extra header to include in CHIPConfig.h for project.
2832
# TODO - This should probably be in src/core but src/system also uses it.
@@ -175,7 +179,7 @@ source_set("system_config_header") {
175179

176180
if (target_cpu != "esp32") {
177181
if (chip_system_config_use_lwip) {
178-
public_deps += [ "${chip_root}/src/lwip" ]
182+
public_deps += [ "${lwip_root}:lwip" ]
179183
} else {
180184
if (chip_device_platform == "efr32") {
181185
public_deps += [ "${efr32_sdk_build_root}:efr32_sdk" ]

third_party/lwip/BUILD.gn

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright (c) 2020 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
17+
# Re-export the Matter lwip integration as "lwip"
18+
#
19+
# To depend on lwip while keeping the implementation target
20+
# encapsulated:
21+
#
22+
# import("//build_overrides/lwip.gni")
23+
#
24+
# source_set("foo") {
25+
# public_deps = [
26+
# "${lwip_root}:lwip",
27+
# ...
28+
# ]
29+
# }
30+
#
31+
# and set up the build_overrides appropriately (a typical lwip_root
32+
# would be //third_party/lwip).
33+
#
34+
# To help define the library, a reusable template is provided as
35+
# lwip_target() in third_party/lwip/lwip.gni. Example usage:
36+
#
37+
# //example/lwip/BUILD.gn:
38+
#
39+
# config("lwip_config") {
40+
# include_dirs = [ "include" ]
41+
# }
42+
#
43+
# lwip_target("lwip") {
44+
# public = [
45+
# "include/lwipopts.h"
46+
# ]
47+
#
48+
# sources = [ "sys_arch.c" ]
49+
#
50+
# public_configs = [
51+
# ":lwip_config",
52+
# ]
53+
# }
54+
#
55+
# Then set lwip_root = "//example/lwip" in build_overrides (or,
56+
# if declared as an argument in build_overrides, via args).
57+
#
58+
# Defining the library directly works too.
59+
#
60+
# If there's no include paths to add, defines to set, sources to
61+
# compile, or libraries to link, then an empty group target suffices.
62+
group("lwip") {
63+
public_deps = [ "${chip_root}/src/lwip:lwip" ]
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright (c) 2023 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/mt793x_sdk.gni")
16+
17+
import("${mt793x_sdk_build_root}/lwip/lwip.gni")
18+
19+
config("lwip_config") {
20+
include_dirs = [
21+
"${chip_root}/src/lwip/mt793x",
22+
"${chip_root}/src/lwip/freertos",
23+
]
24+
}
25+
26+
lwip_target("lwip") {
27+
public = [
28+
"${chip_root}/src/lwip/mt793x/arch/cc.h",
29+
"${chip_root}/src/lwip/mt793x/arch/perf.h",
30+
"${chip_root}/src/lwip/mt793x/lwipopts.h",
31+
]
32+
33+
sources = []
34+
35+
public_deps = [
36+
"${chip_root}/src/lwip:lwip_buildconfig",
37+
"${mt793x_sdk_build_root}:mt793x_sdk",
38+
]
39+
40+
public_configs = [
41+
":lwip_config",
42+
"${chip_root}/src:includes",
43+
]
44+
}

third_party/mt793x_sdk/mt793x_sdk.gni

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
# limitations under the License.
1414
#
1515
import("//build_overrides/chip.gni")
16+
import("//build_overrides/lwip.gni")
1617
import("//build_overrides/mbedtls.gni")
1718
import("//build_overrides/mt793x_sdk.gni")
1819
import("${chip_root}/src/crypto/crypto.gni")
19-
import("${chip_root}/src/platform/mt793x/args.gni")
20+
import("${chip_root}/src/platform/device.gni")
2021
import("${chip_root}/src/platform/mt793x/lwip/lwip.gni")
2122

2223
#

third_party/silabs/BUILD.gn

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import("//build_overrides/chip.gni")
1616
import("//build_overrides/efr32_sdk.gni")
1717
import("//build_overrides/jlink.gni")
1818
import("//build_overrides/openthread.gni")
19+
import("${chip_root}/src/lwip/lwip.gni")
1920
import("${chip_root}/src/platform/device.gni")
2021
import("${efr32_sdk_build_root}/silabs_board.gni")
2122

@@ -53,6 +54,12 @@ group("efr32_sdk") {
5354
public_configs = [ ":silabs_config" ]
5455
}
5556

57+
if (chip_with_lwip) {
58+
group("lwip") {
59+
public_deps = [ "silabs_lwip:lwip" ]
60+
}
61+
}
62+
5663
if (wifi_soc != true) { # CCP board
5764
# Openthread GSDK libraries configurations
5865

0 commit comments

Comments
 (0)