4 ms·
Yes! Zig's cross-compilation story is one of the reasons I chose it for this project. Zig can target x86-windows-gnu and lets you set os_version_min to .xp in
by bcorp 7mo ago
Yes! Zig's cross-compilation story is one of the reasons I chose it
for this project.
Zig can target x86-windows-gnu and lets you set os_version_min to .xp
in the build config. This tells the linker to use only APIs available
on XP SP3.
In practice there were a few things I had to deal with:
- RtlGetSystemTimePrecise doesn't exist on XP, so I wrote a
compatibility shim that redirects to GetSystemTimeAsFileTime
at startup
- The build uses -OReleaseSmall, strips symbols, and is
single-threaded to keep the binary small (~750 KB) and
compatible with XP's threading model
- There's a dedicated build-xp.zig that sets all the right flags,
but you can also just do:
zig build -Dtarget=x86-windows-gnu
- No UCRT or MSVC runtime dependency — this was critical because
XP doesn't ship with the Universal CRT, and you can't install
it reliably on minimal XP systems
The same codebase cross-compiles to Linux x86/x64/ARM with
"zig build cross" — that's where Zig really shines compared to
writing this in C with manual cross-compilation toolchains.
One thing I should mention: Zig 0.15 (currently in use) dropped
some older target support, but x86-windows with XP compat still
works. I'd recommend testing with the exact version in the repo
if you want to reproduce it.
- fithisux 7mo agoValuable information. Thanks!