Nim: [TODO] could nimcache be generated out-of-source (in /tmp) like rdmd does in D?

Created on 23 Mar 2018  路  10Comments  路  Source: nim-lang/Nim

could nimcache be generated out-of-source (in /tmp) like rdmd does in D?

nim c -r util.nim
creates
util, nimcache

dmd -run util.d doesn't create anything (only in /tmp) which is nice
can be seen with: writeln(thisExePath);
eg:
dmd -run:
/private/var/tmp/dmd_run1WOziZ
rdmd:
/private/var/folders/ll/dtasdfasf30dny4y61tf_80000gn/T/.rdmd-501/rdmd-main.d-B6C80F6AC29F80D70F072890F37AA29E/main
which hashes all compiler options so it'll run instantly on next use

post close TODO

other aspects, eg generate the binary in nimcache, caching the resulting binary

Feature

Most helpful comment

@zah methods allows easy cache cleanups and speeds up running alternating debug and release builds by having independent caches.
It should be added as a commented out block in the nim.cfg file shipped with the compiler releases.

All 10 comments

this is not as good as in D case because --nimcache:PATH would have to be specified manually for each invocation to avoid clashing, whereas with rdmd, the path is computed based on a hash of passed in compiler options, cf https://github.com/dlang/tools/blob/master/rdmd.d#L413

because --nimcache:PATH would have to be specified manually for each invocation to avoid clashing

Not necessarily. You can place e.g. a nim.cfg with content --nimcache:PATH in your source directory structure and the compiler will use it automatically.

You can place e.g. a nim.cfg with content --nimcache:PATH in your source directory structure

Or add nimcache="path" to NimDir/config/nim.cfg

I'm using so:

@if release:
  nimcache:"/tmp/nimcache/release"
@else
  nimcache:"/tmp/nimcache/debug"
@end

I prefer nimcache folder in current location, because I often need to check what Nim compiler has generated. It will be a disaster to look for /tmp/autogen_can_be_anything_folder_you_will_never_find_me_as_I_look_as_200_other_folders

I used to configure nimcache in my/home/$user/.config/nim.cfg config file like this:

@if unix:
  @if debug:
    nimcache = "/tmp/nimcache/d/$projectName"
  @else:
    nimcache = "/tmp/nimcache/r/$projectName"
  @end
@end

@if windows:
  @if debug:
    nimcache = r"C:\Temp\nimcache\d\$projectName"
  @else:
    nimcache = r"C:\Temp\nimcache\r\$projectName"
  @end
@end

This solves pretty much all of the raised concerns here.

@zah
Does @if debug: in a cfg file work for you?
Very strange, it does not work for me.

@data-man, it works fine. The debug branch will be selected only when you compile with -d:debug.

@zah methods allows easy cache cleanups and speeds up running alternating debug and release builds by having independent caches.
It should be added as a commented out block in the nim.cfg file shipped with the compiler releases.

This has been implemented now

Was this page helpful?
0 / 5 - 0 ratings