Zero Install

0compile: Developers

This page explains how to publish source code using Zero Install. Publishing source this way means that:

  • Users can compile it easily using 0compile.
  • Build dependencies, such as header files and build tools, can be downloaded automatically.
  • 0release can automatically compile binaries for your software during the release process.

Making source available

To make source code available for others to use you need to add source implementations to the program's feed file. This is almost exactly the same as adding binaries, except that you give src as the machine type to 0publish:

$ 0publish /var/www/interfaces/MyProg.xml \
  --add-version=5 \
  --archive-url=http://mysite/downloads/myprog-5-src.tar.bz2 \
  --set-released=today \
  --set-arch=*-src

There are also some extra attributes you can add to the implementation element:

compile:command
This must be present. Its value is a shell command, executed inside the build directory. It must compile the source in $SRCDIR, putting the final result (ready for distribution) in $DISTDIR. If this command starts to get complicated, you should move it to a script (either inside the main source archive or in a separate dependency) and just set this attribute to the command to run the script.
compile:binary-main
This optional attribute gives the value of the main attribute on the binary feed that is created. If it is not given, then the binary created cannot be executed (e.g., it is a library).
compile:dup-src
Some programs insist on creating files in their source directory, which is typically a read-only directory when using Zero Install. In this case, set compile:dup-src='true' and 0compile will copy everything in $SRCDIR into 'build' before building.

The compile prefix must be bound to 0compile's namespace somewhere, e.g.:

xmlns:compile="http://zero-install.sourceforge.net/2006/namespaces/0compile"

Note: You can keep the source implementations in a separate file (MyProg-src.xml) and add a feed from the main feed, e.g.:

  <feed src='http://mysite/interfaces/MyProg-src.xml' arch='*-src'/>

The arch attribute lets the injector know that it doesn't need to fetch this file unless it's looking for source code.

Making library headers available (-dev packages)

See Make-headers for information about publishing library source and -dev packages.

Adding run-time dependencies

By default, the feed created for the new binary doesn't have any dependencies. There are two ways to add them:

  • You can annotate any <requires> element in your source feed with the 'include-binary' attribute. This causes the dependency to appear in the generated binary's feed, in addition to being made available at compile-time. e.g.
        <requires compile:include-binary='true' interface="http://my/library">
          <environment insert="lib" name="MY_LIBRARY_DIR" mode="replace"/>
        </requires>
    
  • You can edit the feed XML file directly during the build (it's in the $DISTDIR/0install directory).

Tips

Python distutils

You should use the --build-base option to make distutils build to 0compile's build directory, not under the source code (which is read-only). Unfortunately, this option isn't available with the install command, so you have to do the build in two steps. A typical command is:

cd "$SRCDIR" &&
python setup.py build --build-base="$BUILDDIR/build" &&
cd "$BUILDDIR" &&
python "$SRCDIR"/setup.py install --home="$DISTDIR" --skip-build

Further reading

Example: SCons
This example shows how to compile a simple "Hello world" program using the SCons build system. Both the source and SCons are fetched using Zero Install.