[Qbs] Module adding source files to a project

Richard Weickelt richard at weickelt.de
Wed Nov 27 23:17:22 CET 2019

> Should the AppImageKit repository (or only the parts needed for building
> the runtime.c file) be imported into the QBS repository (maybe added as
> a git submodule)? Or should we fetch the sources at runtime?

Ideally, I think, the user would just invoke some tool and use a prebuilt
binary and not need to build the run-time from source. If building from
source is required, let the user install AppImageKit somewhere and just
point Qbs to the installation path in a property like shown below.

> Do we have examples of other modules having similar requirements?

Just a module would not be enough. You will need at least one separate
product item for the run-time binary. An appimage module makes sense if you
need common appimage properties in multiple product items, for instance the
AppImageKit install path.

>   I'd like to write a QBS module to package Linux applications into the
> AppImage format. This is a format in which the all application's files
> (and non-trivial dependencies) are packed into a single executable file,
> which, when executed, unpacks the application data by mounting into a
> squashfs filesystem and then executes the application's main binary.
> The trick here is how to create the "loader" part of the binary: the
> AppImage project provides the source code, which consists of a C file
> [1] and all of its dependencies (a slightly modified version of
> libsquashfs, and a few other utility files), but it's not clear to me on
> what would be the best way to bring these files into one's project.

Why do you need to build "runtime" from source? Is a prebuilt version not
shipped together with AppImageKit or at least available here:
https://github.com/AppImage/AppImageKit/releases ?

Presuming that runtime.c is shipped with AppImageKit, there are probably
many ways to implement that. Here is a very naive idea of a product item
that does both: building the run-time binary as well as packaging up the
application bundle:

// AppImage.qbs
CppApplication {
    type: [ "application", "appimage.runtime", "appimage.package ]
    property string appImageKitInstallPath

    Group {
        name: "runtime"
        prefix: appImageKitInstallPath + "/"
        files:  [ "runtime.c" ]

    // Have a look at
    // The rule will need to depend on all all installables and
    // appimage.runtime and will bake the run-time and the rest together
    // into an artifact of type "appimage.package".
    // You will specify the depencies later in yourproject.qbs
    Rule {}

// yourproject.qbs
Project {
    CppApplication { name: "yourapp"; /* ... */ }
    AppImage {
        appImageKitInstallPath: "/path/to/AppImageKit"
        Depends { name: "yourapp" }

Maybe that gives you an idea how and where to start.

You could also create a AppImageRuntime product item and an AppImagePackage
product item to separate the two tasks better. And you could also implement
a module if these items have common properties or you could put all rules
into the module.


More information about the Qbs mailing list