On Tuesday, 31 July 2018 at 15:19:19 UTC, Dan Barbarito wrote:
Hi all,
I am starting to write a command line tool.
Hi!
First, Vibe.d will increase your binary size because it contains
a lot of unnecessary things inside it. So instead of using the
entire vibe.d library, you may point dub to specific vibe.d
parts, like `vibe.d:core`, `vibe.d:http` etc.
If you put the whole vibe.d framework as a dub dependency and use
it like `import vibe;` the things like mongodb drivers, email
libraries, redis driver etc. will be linked to your binary as
well, even if you don't need them.
Second, you need to compile your code in the release mode to cut
all debug information out of it. Also, you can try to use the
`strip` command line tool to cut all export symbols if your
binary is an executable file, not a library. This will reduce the
size. In some cases a lot.
The third thing is already mentioned: by default, the DMD
compiler builds and links the code statically. In other words,
your binary contains parts of the DRuntime and the Phobos
libraries (those parts that you've used in your program).
This thing helps to distribute compiled binaries without external
dependencies (except libc and libpthread), because your binary is
already contains all needed stuff.
If you're not happy with it, you can try to use the LDC compiler,
which uses the dynamic linking by default. Your binary will be
really tiny, but in order to execute it, you'll need to have the
libdruntime.so and libphobos.so installed in your system. This
may add additional issues if you plan to distribute your program.
Sadly, we still don't have the D runtime libraries installed in
all popular OSes. Currently only the libc has this privilege 😀
I hope the situation will change in the future.