pathschemeguileauto-compile

How to set up a compiled guile script so that it finds its bytecode and does not autocompile anymore?


I want to have an executable guile script prog somewhere in a filesystem.

I want to bytecompile it with guild compile -o prog.go prog so that it no longer needs to be compiled and thus starts quickly.

I can't figure out where to put the prog.go file so that the program does not auto-compile to $HOME/.cache/guile/... (I do not want to flood every user's HOME cache and let compile it redundantly). Since wherever I put the prog.go and point to it by GUILE_LOAD_COMPILED_PATH, guile wants to autocompile the program to my HOME cache (and that's exactly what I want to avoid and why I am asking).

Example:

PATH=$PWD GUILE_LOAD_COMPILED_PATH=$PWD prog
# => auto-compiles :(

While these cases work (OK, but why?):

PATH=. GUILE_LOAD_COMPILED_PATH=. prog
# works

PATH=. GUILE_LOAD_COMPILED_PATH=$PWD prog
# works

Seems the problem occurs when the prog needs to be searched for using PATH? Sounds rather like a bug?


Solution

  • PATH=$PWD GUILE_LOAD_COMPILED_PATH=$PWD prog
    

    This autocompiles because your shell uses the absolute path to prog when running the script (In general, a path made by joining a $PATH directory and the command name), and guile looks for that path in the %load-compiled-path list. So if your current working directory is /home/bob/bin, it'll look for /home/bob/bin/home/bob/bin/prog.go, which doesn't exist. When PATH and GUILE_LOAD_COMPILED_PATH are just ., it'll look for /home/bob/bin/prog.go, which does exist.

    Note: Ideally, you'd put compiled files in a path starting from the directory returned by (%site-ccache-dir) so you don't have to mess with setting up an environment variable to point to a custom location.