Making custom boot.prc

I am trying to use SWI prolog embedded into by own application. Currently it loads from SWI prolog installation directory and loads standard boot.prc with it. Ultimately I want to make portable version of SWI Prolog to be deployed along with my appliocation without need of full-fledged SWI Prolog installation.

I also want to minimize redistributed codebase, so I want to make my own boot saved state.
However, I still can’t understand how to make Prolog to ignore default boot.prc and compile sources from my own boot source tree to make “clean” saved state which contains only needed code.

I also don’t understand how to make “prc” file, as saved states are qlf files.

I don’t know about prc or qlf files, but I use this code for accessing directories and excluding paths.



% Specify directories to ignore
ignore_paths_from(library).
ignore_paths_from(pce_boot).

% Defines library directories by searching user-defined file paths
lib_dir(D) :-
    ignore_paths_from(Category),
    user:file_search_path(Category, X),
    expand_path(X, D0),
    absolute_file_name(D0, D).  % Canonicalizes the path

lib_dir(D) :- user_source_file(D).



% Expands file paths for use in the code
expand_path(X, X) :-
    atomic(X), !.

expand_path(Term, D) :-
    Term =.. [New, Sub],
    user:file_search_path(New, D0),
    expand_path(D0, D1),
    atomic_list_concat([D1, /, Sub], D).


The boot.prc file is basically just a .qlf file. You can of course try to change the files loaded during the boot compilation, but I cannot recommend that. The order of definitions is fragile as the C part of the code only provides a partial compiler. Notably boot/init.pl extends the compiler. Som of the other files in boot further extend it.

To create a stand-alone version, use

 swipl -o myexe -c myloadfile.pl

The result should run, provided all shared objects/dlls are in a place where they can be found. There is a lot of tweaking that is platform dependent. If you really want you can end up with a single file executable for just about any program. Unfortunately, the process is not well documented and different for each OS :frowning:

Some options you typically want are

  • --no-pce to disable including the gui into the state
  • --stand-alone on non-Windows systems to use swipl as basis rather than generating a shell script.
  • --foreign=save to include foreign extensions into the state. This has advantages and disadvantages. As we cannot load them into the process from the state the system will create temporary files and load these at runtime.
1 Like

Okay, I see that I am going to do something dangerous )
Perhaps, I will abandon this idea )