I was surprised by the big difference in file size amongst different targets. Why is the Linux binary so huge relative to the others?
❯ zig init
info: created build.zig
info: created build.zig.zon
info: created src/main.zig
info: created src/root.zig
info: see `zig build --help` for a menu of options
❯ zig build -Doptimize=ReleaseSafe
❯ l zig-out/bin/foo
-rwxr-xr-x 1 jecolon staff 228K Mar 19 15:53 zig-out/bin/foo
❯ zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-linux-gnu
❯ l zig-out/bin/foo
-rwxr-xr-x 1 jecolon staff 1.8M Mar 19 15:53 zig-out/bin/foo
❯ zig build -Doptimize=ReleaseSafe -Dtarget=x86_64-windows-gnu
❯ l zig-out/bin/foo.exe
-rwxr-xr-x 1 jecolon staff 431K Mar 19 15:55 zig-out/bin/foo.exe
It is debug, dwarf, elf, unwind, flate and other debug related functionality.
Windows and macOS provide most of this code in dynamic libraries.
Linux ReleaseSmall is 9.8k and is the only mode that does not include that code.
Use readelf -a zig-out/bin/foo to diplay information about the executable, most interesting is the symbol table .symtab that shows the size and the type of each symbol.
You are right, the biggest contribution to size is the debugging symbols/information.
After running strip zig-out/bin/foo the size is 197k (from 1.7M).
Also in windows the exe size is 505k plus a 1.2M pdb file.