As my weekend's fun project I added an experimental new configuration system to the compiler. Unfortunately I had no time to document it, PRs welcome. So this is how it works:
Instead of foo.nim.cfg you can use foo.nims to provide a configuration file that uses Nim's VM. Within foo.nims the full power of Nim is available and system.nim provides additional tools for you like cd, mvFile and even task. Example:
# don't really execute 'gcc -v' mode = ScriptMode.Whatif exec "gcc -v" --forceBuild task listDirs, "lists every subdirectory": for x in listDirs("."): echo "DIR ", x task default, "default target": # 'nim default foo.nim' is an alias for 'nim c foo.nim' setCommand "c"
I'm quite proud of how few lines it took to get there, so study this piece of art
The extension to system.nim is here:
The support in the compiler is here:
An example here:
NimScript has been inspired by nake, but doesn't compile your build script, instead it runs it via Nim's virtual machine. It's my hope that we can deprecate the old configuration system soon.
PS: I'm not sure what this means for the Nimble - Nim interaction.
I tried this:
import os echo paramStr(1)But i get the following:
winlean.nim(468, 3) Error: cannot 'importc' variable at compile time
Which is a bad thing, because then it hardly can be used as a windows scripting language. Otherwise, i'd say this is a big achievement. It could kick python as a scripting lang.
Maybe .ns as an alternative ext?
On a practical note, I'd suggest a different extension instead of .nims. I'm not particularly picky about which one, but it should be easy to tell apart from .nim and easy to pick out of a directory listings.
Meh, alright, will call it .nimscript then.
It seems interesting, but I am not sure how to actually run it. I tried to download the example, and in fact when I compile tfoo with nim c tfoo I see that tfoo.nims is being processed - in fact [NimScript] exec: gcc -v is printed, and if I remove the speculative mode, gcc -v is run.
I am not sure, though, how to execute the tasks defined below