Stream: compiler development

Topic: Windows Zig


view this post on Zulip Luke Boswell (Sep 10 2023 at 07:47):

I have a problem I'm not sure how to resolve. I am trying to get all the zig tests passing on Windows, however there is a conflict where if I make the changes required for the zig tests to pass, then at least one or more cli rust tests fail. And if I makes the changes to fix the rust cli tests then the zig tests now break again.

Zig tests PASS Rust tests FAIL

If I add the condition on windows in crates\compiler\builtins\bitcode\src\libc.zig on line 12 like follows in addition to some other changes all the zig tests will PASS.

if (arch != .wasm32 and builtin.os.tag != .windows) {
    @export(memcpy, .{ .name = "memcpy", .linkage = .Strong });
}

However the cli breakout test will fail with I don't know the address of the memcpy function! this may cause segfaults

Zig tests FAIL Rust tests PASS

Reverting it back to the below will fix the cli rust tests, but now zig tests will fail.

if (arch != .wasm32) {
    @export(memcpy, .{ .name = "memcpy", .linkage = .Strong });
}

e.g.

PS C:\Users\bosyl\Documents\GitHub\roc\crates\compiler\builtins\bitcode\src> zig test .\main.zig
lld-link: error: duplicate symbol: memcpy
>>> defined at C:\Users\bosyl\Documents\GitHub\roc\crates\compiler\builtins\bitcode\src\libc.zig:24
>>>            .\zig-cache\o\7a9d119939433d987663f08665e5df61\test.obj
>>> defined at c.lib(c.obj)
error: LLDReportedFailure

view this post on Zulip Brendan Hansknecht (Sep 10 2023 at 15:22):

Oh, interesting. We are trying to claim/overwrite the memcpy symbol. So fundamentally, we don't want the system memcpy dependency. We want instead to use a static definition of memcpy that we define.

view this post on Zulip Brendan Hansknecht (Sep 10 2023 at 15:23):

On windows when running zig test, we are pulling in both versions of memcpy and the are conflicting. Thus, the linker is complaining.

view this post on Zulip Brendan Hansknecht (Sep 10 2023 at 15:23):

So the correct solution is probably to tell zig not to link in the system memcpy when compiling tests.

view this post on Zulip Brendan Hansknecht (Sep 10 2023 at 15:24):

That probably requires us to tell zig not to link in libc at all on windows (which we shouldn't need, we want to statically link in all function of libc into the builtins just like we do with memcpy).

view this post on Zulip Luke Boswell (Sep 10 2023 at 19:26):

Thabk you Brendan

view this post on Zulip Brendan Hansknecht (Sep 12 2023 at 19:36):

This probably also needs to be updated to sysv: https://github.com/roc-lang/roc/blob/9507c527c8a69b17d3ba5bf6ef114fdfb2a23db9/crates/compiler/builtins/bitcode/src/libc/musl/memcpy.zig#L25

This is used if the cpu doesn't have avx2


Last updated: Jul 06 2025 at 12:14 UTC