Skip to content

Commit ded46fb

Browse files
committed
fix network module build
Partially reverting changes from #861. Macros set on net module are not visible when building lwip. For example setting `net_mod.addCMacro("MEM_ALIGNMENT", "4");` gets lwip build with default 1 of MEM_ALIGNMENT. Changed to setting that on lwip module instead of net module. Later I also copied that to the net module because it is needed when using cImport in net package. Without that it also gets default if I check `lwip.MEM_ALIGNMENT` somewhere in src/root.zig.
1 parent 9463e8a commit ded46fb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

modules/network/build.zig

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,22 @@ pub fn build(b: *std.Build) void {
6464
lwip_lib.root_module.linkLibrary(foundation_dep.artifact("foundation"));
6565
net_mod.linkLibrary(lwip_lib);
6666

67+
const lwip_mod = lwip_lib.root_module;
6768
// MEM_ALIGNMENT of 4 bytes allows us to use packet buffers in u32 dma.
68-
net_mod.addCMacro("MEM_ALIGNMENT", "4");
69-
net_mod.addCMacro("MEM_SIZE", to_s(&buf, mem_size));
70-
net_mod.addCMacro("PBUF_POOL_SIZE", to_s(&buf, pbuf_pool_size));
71-
net_mod.addCMacro("PBUF_LINK_HLEN", to_s(&buf, ethernet_header));
72-
net_mod.addCMacro("PBUF_POOL_BUFSIZE", to_s(&buf, pbuf_length));
73-
net_mod.addCMacro("PBUF_LINK_ENCAPSULATION_HLEN", to_s(&buf, pbuf_header_length));
69+
lwip_mod.addCMacro("MEM_ALIGNMENT", "4");
70+
lwip_mod.addCMacro("MEM_SIZE", to_s(&buf, mem_size));
71+
lwip_mod.addCMacro("PBUF_POOL_SIZE", to_s(&buf, pbuf_pool_size));
72+
lwip_mod.addCMacro("PBUF_LINK_HLEN", to_s(&buf, ethernet_header));
73+
lwip_mod.addCMacro("PBUF_POOL_BUFSIZE", to_s(&buf, pbuf_length));
74+
lwip_mod.addCMacro("PBUF_LINK_ENCAPSULATION_HLEN", to_s(&buf, pbuf_header_length));
7475
// 40 bytes IPv6 header, 20 bytes TCP header
75-
net_mod.addCMacro("TCP_MSS", to_s(&buf, mtu - 40 - 20));
76+
lwip_mod.addCMacro("TCP_MSS", to_s(&buf, mtu - 40 - 20));
77+
78+
// Copy macros from lwip to net, so we have same values when calling
79+
// translate-c from cImport.
80+
for (lwip_mod.c_macros.items) |m| {
81+
net_mod.c_macros.append(b.allocator, m) catch @panic("out of memory");
82+
}
7683

7784
const options = b.addOptions();
7885
options.addOption(u16, "mtu", mtu);

0 commit comments

Comments
 (0)