☰

Bundle management

Author(s): Jose F. Morales, The Ciao Development Team.

The ciao command implements most bundle management operations. The most important commands are:

$ ciao list              # List bundles in current workspaces
$ ciao build [<tgts>]    # Build
$ ciao build -r [<tgts>] # Build, including dependencies
$ ciao fetch [<tgts>]    # Fetch all dependencies of a bundle
$ ciao get [<tgts>]      # Fetch, build, and install a bundle
$ ciao rm [<tgts>]       # Remove a bundle
$ ciao install [<tgts>]  # Make bundles available (see below)
$ ciao update            # Update the downloaded bundles

Most commands accept one ore more targets (workspace paths, bundle directories, bundle names, or bundle aliases for location on the network). For example, valid targets are:

  • (empty) (in which case Ciao locates the bundle above the current directory)
  • bundle names (e.g., chat80)
  • paths to bundles (e.g., ~/ciao/chat80)
  • URL-like aliases to bundles (e.g., github.com/jfmc/chat80, where chat80 is the bundle name)

Execute ciao help to obtain a detailed list of commands.

Setting up workspaces

(See Bundles and workspaces for what bundles and workspaces are, and how bundles are found in a workspace.)

Ciao locates bundles by looking at one or more workspaces, given by the following (optional) environment variables:

  • CIAOPATH: colon-separated list of paths to individual workspaces
  • CIAOROOT: the root directory of this Ciao system (either in binary or source form)

Workspaces from CIAOPATH are consulted from left to right. If CIAOPATH is undefined, a default value of ~/.ciao will be used. The first encountered workspace directory is denoted as the top workspace. The variable CIAOROOT is not needed: the Ciao executables find the root from their own location (the variable overrides it).

Note: CIAOPATH should not point to CIAOROOT (it is not needed and it may produce inconsistent builds).

As mentioned in Installing Ciao, setting up the environment uses the ciao-env tool, which updates the PATH and other environment variables to make commands and documentation (man, info) accessible by default.

Configuring workspaces: The directory ~/ciao can be added permanently as a workspace as follows. Include the following at the ~/.emacs file:

(setenv "CIAOPATH" (expand-file-name "~/ciao"))

Then add these lines to the ~/.bashrc file:

export CIAOPATH=~/ciao

It is possible to change CIAOPATH temporarily from emacs (M-x setenv) or a shell in a terminal (executing export CIAOPATH=<path>)

Using and creating bundles

Creating new bundles: For creating new bundles it is recommended to define a workspace directory (e.g., ~/ciao) and set the CIAOPATH environment variable to that directory.

Bundles can be created from scratch or cloned from repositories, e.g.:

$ cd ~/ciao
$ git clone https://github.com/jfmc/chat80

At that point bundles can be managed with the ciao command. The ciao list should display chat80 as a recognized bundle, and it should be possible to configure, build, or install it (e.g., ciao build at chat80 directory or ciao build chat80 anywhere). Most commands will rescan the bundles at the workspace, but it can be done manually with:

$ ciao rescan-bundles
Note that existing toplevels may need to be restarted to recognize modules at the new bundles.

Network installation: It is possible to download, configure, build, and install automatically bundles from the network. For example:

ciao get github.com/jfmc/chat80
will fetch and install chat80 under the top workspace (~/.ciao if CIAOPATH is unset) (see bundle_fetch). The bundle name will be chat80, while the rest of the bundle alias is used to locate the location on the network. The command:
ciao rm chat80
removes the bundle (to prevent accidental data losses, only iff it has been marked as downloaded).

Installing and updating

A built system is made available with ciao install:

  • ciao install: in place; it registers the system for your user (your shell and emacs startup files), so that its commands, manuals and emacs mode are found;
  • ciao install --prefix=DIR: copies it to DIR/ciao/<version> and links it from DIR/bin, DIR/share/man, etc. (several versions can be installed under the same DIR; ciao activate selects the linked one).

ciao uninstall (with the same --prefix) undoes it. The downloaded bundles are updated with ciao update, and Ciao itself (a git clone) with ./ciao-boot.sh update (optionally to a branch, snapshot or release: ./ciao-boot.sh update REF). The ciao_builder manual describes the details: Configuration, Build, Installation, and Updating.

Workspaces during Ciao bootstrap

In the context of calls to <srcdir>/ciao-boot.sh, CIAOROOT is implicitly set to the directory where ciao-boot.sh is located (<srcdir>) and CIAOPATH is unset. Thus only bundles at <srcdir> (including bundle catalog directories) are considered.

This is useful to:

  • prevent existing CIAOPATH values interact with system builds
  • fetch bundles during system build (e.g., the devenv bundle)

Example: the following command will bootstrap Ciao from source, as well as fetch and install the full development environment:

./ciao-boot.sh get devenv

Generating binary distributions

The command ciaoc -S makes a standalone executable (with the engine) for the current platform. --po-embed says how it embeds the bytecode:

  • section (the default): the bytecode is a section of an executable linked with the C toolchain (the one of the engine, see ciao-config --cc) from the engine library and the foreign code of the modules (their .a, and those of the libraries they need): a single file, which can be signed and notarized on macOS (e.g., codesign --options runtime, xcrun notarytool submit, xcrun stapler staple). Without the C toolchain this is an error.
  • tail: the bytecode is appended to a copy of the engine executable, which needs no C compiler; it cannot be signed on macOS. The foreign libraries of its modules are copied as below.

When the modules included in an executable that is not linked (in any other mode, or with --po-embed tail) have foreign libraries, they are copied into lib/ next to the executable (--foreign-libdir), with the shared libraries that they need (transitively, except those of the operating system), relocated, and loaded from there; so the directory of such an executable can be copied to another machine of the same platform (see nativelink__foreign).

Example:

ciaoc -S -o dist/YOURMAINEXEC src/YOURMAINEXEC
cp src/SOMEASSET dist/

This creates a platform specific binary dist/YOURMAINEXEC (with --po-embed tail, also dist/lib/ with the shared libraries of its dependencies).

Only our own libraries are copied or linked in (built by Ciao: the foreign dependencies built in third-party/, and the foreign code of bundles). A library of the system (e.g., from Homebrew, or of a Linux distribution) is referred to where it is, and ciaoc lists the ones the executable needs: it must exist where the executable runs. To carry it, build the dependency here (ciao configure --builder:foreign_origin=only_own), or, with --po-embed tail, copy it with ciaoc --system-libs copy.

Libraries to embed in C programs

ciaoc --lib archive (a .a) and ciaoc --lib shared (a .so or .dylib) make a library instead of an executable, with the bytecode of the program inside, its foreign code linked in (from the .a of its modules and of the libraries they need), and with -S the engine too; without -S the host links the engine (libciaoengine), and in the default mode the library modules are loaded from the Ciao that built the library (unless CIAOROOT is set). Next to it, libNAME.h declares ciao_ctx NAME_open(int argc, char **argv), which initializes Ciao, loads the program and runs the initialization of its modules, and void NAME_close(ciao_ctx ctx); the host then calls the program with the API of ciao_prolog.h (e.g., ciao_commit_call()). With -S that API is inlined in libNAME.h, since it is the API of the engine inside the library; otherwise libNAME.h includes the ciao_prolog.h of the Ciao whose engine the host links. libNAME.pc gives the flags to compile and link the host, relative to its own directory (${pcfiledir}): with pkg-config, or with ciao-config --pc, which needs no pkg-config (it is not part of the macOS command line tools). The same flags are written in a comment at the start of libNAME.h, and printed by ciaoc.

Example:

ciaoc -S --lib archive -o out/libmyprog.a src/myprog
cc $(ciao-config --pc out/libmyprog.pc --cflags) host.c -o host $(ciao-config --pc out/libmyprog.pc --libs)

The directory of a library made with -S (only libNAME.a or the shared library, libNAME.h and libNAME.pc) can be distributed as it is: a host is compiled with -I<dir> and linked with -L<dir> -lNAME (and, for an archive, the libraries of the system given in libNAME.h), with no Ciao installed. Without -S the host needs the engine of an installed Ciao (and, in the default mode, its libraries).

A shared library exports only NAME_open, NAME_close and the ciao_* API. A library made with -S contains its own engine: use one of them per process; several programs in one process share one engine with -s libraries (if they do not share modules) or the default mode.

Adding assets to binary distributions

The bundle_path/3 predicate (at bundle/bundle_paths) can be used to obtain the absolute path name of a bundle or a relative path in a bundle.

Example:

:- use_module(library(system), [file_exists/1]).
:- use_module(library(pathnames), [path_concat/3]).
:- use_module(library(bundle/bundle_paths), [bundle_path/3]).

% Find file X in the same directory as the executable
% or in the sources.
find_asset(Name, Path) :-
    ( current_executable(ExecPath),
      path_split(ExecPath, Dir, _)
    ; bundle_path(<SomeBundle>, 'images', Dir)
    ),
    path_concat(Dir, Name, Path0),
    file_exists(Path0),
    !,
    Path = Path0.

The example predicate find_assert/2 above will look for arbitrary files in either the images/ directory or the directory of the current executable.

find_asset('spaceship.png', Sprite)

Troubleshooting

Q: Moving a Ciao tree, a workspace, or a bundle.

A: A built Ciao tree or workspace can be moved or copied anywhere: it keeps working with no rebuild. If it was registered (see ciao install), register it again from its new location (ciao register), so that the startup files point to it. A bundle moved to another workspace has to be found, configured, and built again there (its registry, configuration, and compiled files stay in the build/ of the old workspace); go to the new workspace and type:

ciao rescan-bundles
ciao configure [<configuration-options>]
ciao build

Q: Compilation of some module complains about missing dependencies (to seemingly auto-generated code and third-party libraries).

A: Make sure that the bundle and its dependencies are properly configured and build (e.g., calling ciao build for each of them or with ciao build -r). Some bundles (e.g., interfaces to external solvers) require pre-build steps to download and compile third-party code. This part of the compilation is not currently handled by the Ciao compiler.

Q: Alias paths configured at .ciaorc are not visible in executables.

A: The .ciaorc file is read only by the Ciao toplevel (not arbitrary Ciao executables). Configure alias paths through manifest files instead.