Skip to content

Provide a way to specify nimcache dir via env variable #25529

@jakubgs

Description

@jakubgs

Nim Version

Any in the last 8 years.

Description

The use of a shared nimcache folder can be a source of very bizarre errors, especially when used on a CI host with jobs running in parallel. One such issue was encountered in:

Where either via some sort of corruption or other weird race condition the nimcache directory became broken and had to be remove to stop the following error from happening:

x86_64-w64-mingw32/bin/ld.exe:
  C:\Users\jenkins\nimcache\koch_d\@mlib@sstd@sprivate@swin_setenv.nim.c.o:@mlib@sstd@sprivate@swin_setenv.nim.c:
  (.rdata$.refptr.__imp__environ[.refptr.__imp__environ]+0x0): undefined reference to `__imp__environ'
collect2.exe: error: ld returned 1 exit status

On Linux this can be partially mitigated by pointing XDG_CACHE_HOME at something like WORKSPACE_TMP or similar, but in case of Windows it just uses os.getHomeDir():

Nim/compiler/options.nim

Lines 806 to 810 in ab00c56

proc getOsCacheDir(): string =
when defined(posix):
result = getEnv("XDG_CACHE_HOME", getHomeDir() / ".cache") / "nim"
else:
result = getHomeDir() / genSubDir.string

The issue with that is that overriding USERPROFILE on Windows can have way more unexpected results than just overriding XDG_CACHE_HOME on Linux. This is also not the first time I've encountered issues with shared nimcache in CI.

For this reason I'd like to propose either:

  • A NIMCACHE environment variable to specify the directory explicitly instead of indirectly.
  • A modification to getOsCacheDir that would prevent weird errors like above from happening.

Current Output


Expected Output


Known Workarounds

Remove nimcache after every build... except that can kill another parallel job running that uses it.

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions