buggins / dlangui

Cross Platform GUI for D programming language
Boost Software License 1.0
815 stars 121 forks source link

Binary files size #688

Open homerestis opened 4 weeks ago

homerestis commented 4 weeks ago

OS: Arch linux. Compiler: dmd.

git clone --recursive https://github.com/buggins/dlangui.git
cd dlangui/examples/helloworld
dub build -b release

The size of the binary file is 12M. Isn't it too much for a helloworld? How can I reduce this size?

FreeSlave commented 4 weeks ago

You can use strip on the binary to reduce its size (this should save around 4M) Also try using ldc2 instead of dmd (ldc generally produces smaller binaries than dmd).

dub build -b release --compiler=ldc2

For me the stripped release binary built with ldc is 4,3M.

homerestis commented 4 weeks ago

Thanks. Now the size is 4M. I think it's because the ldc2 uses shared libraries:

ldd ./helloworld
    linux-vdso.so.1 (0x00007b5a72492000)
    libz.so.1 => /usr/lib/libz.so.1 (0x00007b5a72473000)
    libphobos2-ldc-shared.so.109 => /usr/lib/libphobos2-ldc-shared.so.109 (0x00007b5a71a00000)
    libdruntime-ldc-shared.so.109 => /usr/lib/libdruntime-ldc-shared.so.109 (0x00007b5a71ec3000)
    libm.so.6 => /usr/lib/libm.so.6 (0x00007b5a71911000)
    libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007b5a72445000)
    libc.so.6 => /usr/lib/libc.so.6 (0x00007b5a71720000)
    /lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007b5a72494000)
GrimMaple commented 4 weeks ago

I were about to suggest both using strip (honestly, it's very powerful), and using shared libraries. IIRC, dmd links in druntime and phobos in by default

4MB is fairly OK for a hello world, considering that it doesn't grow much afterwards :)