I know performance is important, but program size is too. Microcontroller-code is likely to be a niche for Nim, so every byte counts (within reason). Golang is known for bloated executables: https://donatstudios.com/Golang-Binary-Sizes

On my Mac, the minimum do-nothing go program is 900kB. On WIndows, it can be 8MB. (This is because several key libraries cannot be removed.) A do-nothing Nim program with -d:release is only 16044 bytes. C is about 1/3 of that without being fancy, but 16kB is low enough as libraries and useful code will dominate. In fact, this is small enough that binary executables could actually be included in repositories. There are many use-cases for small static binaries.

I thought people might like to hear some good news.

2015-03-04 01:04:45
def

You can go down a bit further if you really want (at costs):

$ cat h.nim
echo "Hello World"
$ nim c h && ls -lha h
-rwxr-xr-x 1 def def 176K Mär  4 02:46 h*
$ nim -d:release c h && ls -lha h
-rwxr-xr-x 1 def def 57K Mär  4 02:46 h*
$ nim -d:release --opt:size c h && ls -lha h
-rwxr-xr-x 1 def def 25K Mär  4 02:47 h*
$ nim -d:release --opt:size c h && strip -s h && ls -lha h
-rwxr-xr-x 1 def def 19K Mär  4 02:48 h*
$ nim -d:release --opt:size c h && strip -s h && upx --best h && ls -lha h
-rwxr-xr-x 1 def def 11K Mär  4 02:48 h*

2015-03-04 01:52:09

@def, it looks like your first 2 release builds are the same command, yet different sizes.

And upx is cheating IMO, but it's nice to seen lean executables

Indeed compiling to a standalone static executable, with a high level Pythonesque language, is a very compelling feature to me.

2015-03-04 02:14:05
def

@def, it looks like your first 2 release builds are the same command, yet different sizes.

My bad, was missing a --opt:size.

2015-03-04 02:25:56

We should mention that executable size may depend on c compiler, gcc may give much larger files than clang with lto, that executables on windows may be significantly larger, and that dynamic linkings works file also. See

http://forum.nim-lang.org/t/679/1

2015-03-04 11:56:42
Supposedly, strip is considered unsafe for Go programs. I'll assume it's fine for Nim.
2015-03-04 16:29:55
def

I'll assume it's fine for Nim.

Yes, haven't had any problems with it. Except that I sometimes forget that I ran strip and why my symbols are gone when debugging.

2015-03-04 16:56:44
I had been wondering if nim defaulted to static or dynamically linking where is that documented? 2015-03-06 07:17:49

BTW this question is only ever asked by Go proponents. The default is static linking against Nim's stdlib, dynamic linking against libc.

Afaict Go doesn't use libc (Nim doesn't use much of it either) so Go proponents came up with this rather meaningless "But other programs are just as big if they link statically" argument. Well, but nobody does that.

Static linking against GNU's libc is not allowed by its license anyway.

2015-03-06 10:06:05