Nim: Create binary file in temporary folder.

Created on 8 Sep 2018  路  7Comments  路  Source: nim-lang/Nim

Are there any plans to be able to run a source file without creating a binary file?
For example, when running nim c -r main.nim:
The results are a native binary and nimcache folder.

I like how golang handles this:
When running go run main.go:
It runs the program in a tmp directory: /tmp/go-build680322009/b001/exe/main and returns output.

Most helpful comment

Why is this feature reasonable? What's so bad about a binary being produced?

A better version of @Araq's command is:

nim c -r --out:/tmp/blah main.nim

All 7 comments

  • your title is a bit misleading ("without creating binary") ; instead, it should be: "create the binary in nimcache folder"
  • see also:
    cache compilation to avoid recompiling when possible #8912

nim c -r main.nim && rm ./main does the job.

  • not robust in case the binary generated by nim fails on foo bar: nim c -r main.nim foo bar => rm ./main won't be called
  • not cross platform
  • also could be an issue if multiple threads run this, although there's a bigger issue in this case (nimcache)
    i think the feature @DanielSokil wants is reasonable and probably trivial to implement

Why is this feature reasonable? What's so bad about a binary being produced?

A better version of @Araq's command is:

nim c -r --out:/tmp/blah main.nim

Let's say you have 50 nim files in a folder, it takes more time to find the file you want, when there is:
file.nim and file binary file, so now there are 100 files total.
@dom96 nim c -r --out:/tmp/blah main.nim Would work, but it is not as simple as go run main.go

You can easily create an alias in your shell for that command.

Thanks @dom96.

alias nimr='nim c -r --out:/tmp/nim-cache' Works perfectly.

Was this page helpful?
0 / 5 - 0 ratings