Hey! Some team members on my project are having an issue where linking 
sometimes (seemingly at random) fails because the .o files that were supposed 
to be produced by the Nim compiler aren't there.

An example of what this looks like:

The missing files in this case are ones whose .c sources have been 
{.compile.}'d into the app. But I don't think there's anything special about 
those particular files, I seem to recall it has happened for regular Nim 
modules in the past too.

My nimscript task to compile looks like this:
    
    
    task rom, "compile the GBA rom":
      let args = commandLineParams()[1..^1].join(" ")
      cd thisDir()
      try:
        rmFile("main_linkerArgs.txt")
        selfExec "c " & args & " -o:" & name & ".elf " & main
      except CatchableError as e:
        if fileExists("main_linkerArgs.txt"):
          let linkerPath = get "gcc.path"
          let linkerExe = get "gcc.linkerexe"
          echo "LINK FAILED, RETRYING"
          when defined(Windows): exec "timeout 1"
          else: exec "sleep 1"
          exec linkerPath / linkerExe & " @main_linkerArgs.txt"
        else:
          raise e
    
    
    Run

Initially I suspected it was some sort of race condition and we just needed to 
wait for the files to become visible. So I added code to retry the linking 
step, as you can see above (using the `<project>_linkerArgs.txt` that the Nim 
compiler produces during linking).

What I found was that this doesn't help at all, and in fact sometimes _more_ 
files have gone missing by the time we try linking again.

We tried setting an exclusion on the nimcache dir in Windows Defender in case 
that was it, but no difference.

We have a Linux-using teammate who it happened for occasionally, but apparently 
only when they modified source files when the game was building? (but I am 
doing that all the time and it's never happened to me!)

We also have another Windows-using teammate who it _used_ to happen for but no 
longer does, and we have no idea why.

I'm absolutely at my wit's end as to what could be causing this, so I figured 
it's time to ask here if anyone has ideas, or suggestions for how to narrow 
down the problem.

Thanks.

Reply via email to