I have found a way to share the cache with the project, but since very few 
people will benefit from this, I will only report on it.

> After some trial and error(ccache -o debug=true), I think the ccache manual 
> needs to turn off the inclusion of the current directory in the hash in 
> hash_dir(ccache -o hash_dir=false). It also seems to be 
> "-I/cwd/path/to/headers" in the c compiler options so that nim can import c 
> source files and header files, and I assume it is also necessary to avoid 
> including this in the hash that is keyed to the ccache cache.(I don't 
> know/find how to do that.)
    
    
    # Add the -c and --nimcache options when compiling the source.
    $ cd ex1
    $ nim --nimcache=./build -c c src/ex1.nim
    
    # Set ccache not to do hash dir.
    $ ccache -o hash_dir=false
    # Set the parent directories of the two or more different project parents 
on which to base ccache at the first point. Normally only /home seems to be 
good, but it says not to set /
    $ ccache -o base_dir=/home
    
    $ cd build # Second point, ccache's base_dir setting changes absolute paths 
to relative paths, so cd to one or more inner project directories to do this
    
    # Compile using gcc symbolically linked to ccache. The json file is created 
in the same directory, so execute the command for the array of the compile. 
Wildcards are not allowed. One file at a time.
    $ gcc -c  -I/home/xxx/.choosenim/toolchains/nim-1.6.10/lib 
-I/home/xxx/src/ex1/src -o 
/home/xxx/src/ex1/nimcache/@m..@s..@[email protected]@[email protected]@slib@[email protected]
 
/home/xxx/src/ex1/nimcache/@m..@s..@[email protected]@[email protected]@slib@[email protected]
    
    # Now all that's left is to link the objects
    
    # Do the same for different projects as well.
    $ cd ex2
    $ nim --nimcache=./build -c c src/ex2.nim
    # (...snip)
    
    
    Run

If you can use jq or something to extract the commands from the json and 
prepare a Makefile or something, you can automate it, but it would be faster to 
compile with nimble as usual than the time to do that, and it would take more 
time to set up than the time you can reduce by having ccache share it. Perhaps 
even if you build with nimble build, if you cd to the internal directory of the 
project with nimscript or something and start gcc, it will be cached. But I 
tried cd("src"), but it didn't work.

Sorry for the disturbance. 

Reply via email to