@@ -12,13 +12,7 @@ pub fn build(b: *std.Build) void {
1212 const mz_dep = b .dependency ("microzig" , .{});
1313 const mb = MicroBuild .init (b , mz_dep ) orelse return ;
1414
15- const targets = [_ ]TargetDescription {
16- .{ .prefix = "esp32_c3" , .target = mb .ports .esp .chips .esp32_c3 },
17- // .{ .prefix = "esp32_c3_direct_boot", .target = mb.ports.esp.chips.esp32_c3_direct_boot },
18- .{ .prefix = "esp32_c3_flashless" , .target = mb .ports .esp .chips .esp32_c3_flashless },
19- };
20-
21- const available_examples = [_ ]Example {
15+ const examples : []const Example = &.{
2216 .{ .name = "blinky" , .file = "src/blinky.zig" },
2317 .{ .name = "custom_clock_config" , .file = "src/custom_clock_config.zig" },
2418 .{ .name = "gpio_input" , .file = "src/gpio_input.zig" },
@@ -30,15 +24,25 @@ pub fn build(b: *std.Build) void {
3024 .{ .name = "stepper_driver_dumb" , .file = "src/stepper_driver_dumb.zig" },
3125 .{ .name = "systimer" , .file = "src/systimer.zig" },
3226 .{ .name = "ws2812_blinky" , .file = "src/ws2812_blinky.zig" },
27+ .{ .name = "rtos" , .file = "src/rtos.zig" },
28+ .{ .name = "tcp_server" , .file = "src/tcp_server.zig" , .features = .{
29+ .flashless = false ,
30+ .lwip = true ,
31+ } },
3332 };
3433
35- for (available_examples ) | example | {
34+ for (examples ) | example | {
3635 // If we specify example, only select the ones that match
3736 if (maybe_example ) | selected_example |
3837 if (! std .mem .containsAtLeast (u8 , example .name , 1 , selected_example ))
3938 continue ;
4039
41- for (targets ) | target_desc | {
40+ for (std .enums .values (TargetEnum )) | target_enum | {
41+ if (! example .features .flashless and std .mem .containsAtLeast (u8 , @tagName (target_enum ), 1 , "flashless" ))
42+ continue ;
43+
44+ const target_desc = target_enum .get_target_desc (mb );
45+
4246 // `add_firmware` basically works like addExecutable, but takes a
4347 // `microzig.Target` for target instead of a `std.zig.CrossTarget`.
4448 //
@@ -51,6 +55,28 @@ pub fn build(b: *std.Build) void {
5155 .root_source_file = b .path (example .file ),
5256 });
5357
58+ if (example .features .lwip ) {
59+ const target = b .resolveTargetQuery (firmware .target .zig_target );
60+
61+ const foundation_dep = b .dependency ("foundation_libc" , .{
62+ .target = target ,
63+ .optimize = optimize ,
64+ .single_threaded = true ,
65+ });
66+
67+ const lwip_dep = b .dependency ("lwip" , .{
68+ .target = target ,
69+ .optimize = optimize ,
70+ .include_dir = b .path ("src/lwip/include" ),
71+ });
72+
73+ const libc_lib = foundation_dep .artifact ("foundation" );
74+ const lwip_lib = lwip_dep .artifact ("lwip" );
75+
76+ lwip_lib .root_module .linkLibrary (libc_lib );
77+ firmware .app_mod .linkLibrary (lwip_lib );
78+ }
79+
5480 // `installFirmware()` is the MicroZig pendant to `Build.installArtifact()`
5581 // and allows installing the firmware as a typical firmware file.
5682 //
@@ -63,12 +89,146 @@ pub fn build(b: *std.Build) void {
6389 }
6490}
6591
92+ const TargetEnum = enum {
93+ esp32_c3 ,
94+ esp32_c3_direct_boot ,
95+ esp32_c3_flashless ,
96+
97+ fn get_target_desc (target_enum : TargetEnum , mb : * MicroBuild ) TargetDescription {
98+ return switch (target_enum ) {
99+ .esp32_c3 = > .{
100+ .prefix = "esp32_c3" ,
101+ .target = mb .ports .esp .chips .esp32_c3 ,
102+ },
103+ .esp32_c3_direct_boot = > .{
104+ .prefix = "esp32_c3_direct_boot" ,
105+ .target = mb .ports .esp .chips .esp32_c3_direct_boot ,
106+ },
107+ .esp32_c3_flashless = > .{
108+ .prefix = "esp32_c3_flashless" ,
109+ .target = mb .ports .esp .chips .esp32_c3_flashless ,
110+ },
111+ };
112+ }
113+ };
114+
66115const TargetDescription = struct {
67116 prefix : []const u8 ,
68117 target : * const microzig.Target ,
69118};
70119
71120const Example = struct {
121+ const Features = packed struct {
122+ flashless : bool = true ,
123+ lwip : bool = false ,
124+ };
125+
72126 name : []const u8 ,
73127 file : []const u8 ,
128+ features : Features = .{},
129+ };
130+
131+ const lwip_flags = [_ ][]const u8 { "-std=c99" , "-fno-sanitize=undefined" };
132+ const lwip_files = [_ ][]const u8 {
133+ // Core files
134+ "core/init.c" ,
135+ "core/def.c" ,
136+ "core/dns.c" ,
137+ "core/inet_chksum.c" ,
138+ "core/ip.c" ,
139+ "core/mem.c" ,
140+ "core/memp.c" ,
141+ "core/netif.c" ,
142+ "core/pbuf.c" ,
143+ "core/raw.c" ,
144+ "core/stats.c" ,
145+ "core/sys.c" ,
146+ "core/altcp.c" ,
147+ "core/altcp_alloc.c" ,
148+ "core/altcp_tcp.c" ,
149+ "core/tcp.c" ,
150+ "core/tcp_in.c" ,
151+ "core/tcp_out.c" ,
152+ "core/timeouts.c" ,
153+ "core/udp.c" ,
154+
155+ // IPv4 implementation:
156+ "core/ipv4/acd.c" ,
157+ "core/ipv4/autoip.c" ,
158+ "core/ipv4/dhcp.c" ,
159+ "core/ipv4/etharp.c" ,
160+ "core/ipv4/icmp.c" ,
161+ "core/ipv4/igmp.c" ,
162+ "core/ipv4/ip4_frag.c" ,
163+ "core/ipv4/ip4.c" ,
164+ "core/ipv4/ip4_addr.c" ,
165+
166+ // IPv6 implementation:
167+ "core/ipv6/dhcp6.c" ,
168+ "core/ipv6/ethip6.c" ,
169+ "core/ipv6/icmp6.c" ,
170+ "core/ipv6/inet6.c" ,
171+ "core/ipv6/ip6.c" ,
172+ "core/ipv6/ip6_addr.c" ,
173+ "core/ipv6/ip6_frag.c" ,
174+ "core/ipv6/mld6.c" ,
175+ "core/ipv6/nd6.c" ,
176+
177+ // Interfaces
178+ "netif/ethernet.c" ,
179+
180+ // Interfaces:
181+ // "netif/bridgeif.c",
182+ // "netif/ethernet.c",
183+ // "netif/slipif.c",
184+ // "netif/bridgeif_fdb.c",
185+
186+ // sequential APIs
187+ // "api/err.c",
188+ // "api/api_msg.c",
189+ // "api/netifapi.c",
190+ // "api/sockets.c",
191+ // "api/netbuf.c",
192+ // "api/api_lib.c",
193+ // "api/tcpip.c",
194+ // "api/netdb.c",
195+ // "api/if_api.c",
196+
197+ // 6LoWPAN
198+ // "netif/lowpan6.c",
199+ // "netif/lowpan6_ble.c",
200+ // "netif/lowpan6_common.c",
201+ // "netif/zepif.c",
202+
203+ // PPP
204+ // "netif/ppp/polarssl/arc4.c",
205+ // "netif/ppp/polarssl/des.c",
206+ // "netif/ppp/polarssl/md4.c",
207+ // "netif/ppp/polarssl/sha1.c",
208+ // "netif/ppp/polarssl/md5.c",
209+ // "netif/ppp/ipcp.c",
210+ // "netif/ppp/magic.c",
211+ // "netif/ppp/pppoe.c",
212+ // "netif/ppp/mppe.c",
213+ // "netif/ppp/multilink.c",
214+ // "netif/ppp/chap-new.c",
215+ // "netif/ppp/auth.c",
216+ // "netif/ppp/chap_ms.c",
217+ // "netif/ppp/ipv6cp.c",
218+ // "netif/ppp/chap-md5.c",
219+ // "netif/ppp/upap.c",
220+ // "netif/ppp/pppapi.c",
221+ // "netif/ppp/pppos.c",
222+ // "netif/ppp/eap.c",
223+ // "netif/ppp/pppol2tp.c",
224+ // "netif/ppp/demand.c",
225+ // "netif/ppp/fsm.c",
226+ // "netif/ppp/eui64.c",
227+ // "netif/ppp/ccp.c",
228+ // "netif/ppp/pppcrypt.c",
229+ // "netif/ppp/utils.c",
230+ // "netif/ppp/vj.c",
231+ // "netif/ppp/lcp.c",
232+ // "netif/ppp/ppp.c",
233+ // "netif/ppp/ecp.c",
74234};
0 commit comments