Normalley I compile my program with
nim c -d:danger --panics:on --gc:arc -d:useMalloc -d:lto --passL:"-static" --cc:clang --threads:on --run Nalwald.nim
Now I tried to write a nimscript for the build process:
task default, "default compile":
--define:danger
--panics:on
--gc:arc
--define:useMalloc
--define:lto
--passL:"-static"
--cc:clang
--threads:on
setCommand "c"
If I compile this with "nim default Nalwald.nim" the program is 25% slower that the program I get when compiling with the first above. Also, normally the LTO option improves the performance by roughly 25%. If I remove the line --define:lto from the nimscript the resulting program isn't slower than if compiling with the nimscript with --define:lto. So I suspect the LTO option isn't correctly handled by the nimscript.
But I am completely new to nimscripts, so my questions is, if I missed something, that would fix this issue, or if I rather should use nim.cfg for now.
you are correct about that.
dang.nim
var s = [0,1,2,3]
echo s[4]
config.nims
task default,"default compile":
--define:danger
--hints:off
--define:lto
--genScript:on
setCommand "c"
task manual,"manual compile":
--hints:off
exec "nim c --hints:off -d:danger -d:lto --genScript:on " & projectName() & ".nim"
task lastLine,"print last line":
--hints:off
exec "tail -n 1 ~/.cache/nim/" & projectName() & "_r/compile_" & projectName() & ".sh"
both compile, so d:danger worked (no bounds checks)
but:
❯ nim manual dang.nim && nim lastLine dang.nim
gcc -o dang stdlib_assertions.nim.c.o stdlib_io.nim.c.o stdlib_system.nim.c.o @mdang.nim.c.o -ldl -flto
❯ nim default dang.nim && nim lastLine dang.nim
gcc -o dang stdlib_assertions.nim.c.o stdlib_io.nim.c.o stdlib_system.nim.c.o @mdang.nim.c.o -ldl
lto is not being turned on.