Bundling runtime dependencies - Libraries

Application Snaps are expected to contain both applications, and the necessary libraries needed for the applications to function correctly. The developer specifies at build time what libraries to include. Libraries may be included as individual parts or can be included as stage-packages in the application part.

Compiling the libraries from source, or dumping individual pre-built libraries allows the snap developer to have fine-grained control over which versions of libraries are included in the snap. Developers can include libraries they’ve already built elsewhere in the build-chain, inside the snap. Placing libraries in the /lib directory within the snap will ensure they’re found in the library path at runtime.

In this snippet libraries are in the libs/ path of their project directory. At build time snapcraft will incorporate the libraries into the snap.

parts:
    libraries:
        plugin: dump
        source: ./libs
        organize: 
            "*.so": /lib/

Using stage-packages can be considered a convenience, saving the developer the time and effort of compiling each one from source. When building snaps to run with an Ubuntu 16 Core (base), the specified stage-packages will come from the Ubuntu 16.04 (Xenial) repository. The libraries are included at build-time, and will pull whatever the current version in the Ubuntu repository is.

In this snippet, some libraries are listed in the application part. Those (and in turn their dependencies) will be incorporated into the snap at build time.

parts:
    game:
        plugin: make
        source: ./sourcefiles
        stage-packages:
            - libgl1-mesa-dri
            - libgl1-mesa-glx

The Snap Store will send automated emails to developers using stage-packages when a security update occurs, recommending the affected snap(s) are rebuilt and published.

1 Like

We should update this to cover including stage-packages in Electron apps.

1 Like

Shouldn’t there be a slash after lib in:
“*.so”: /lib
above? Without it I get the following error:
Failed to organize part ‘libraries’: multiple files to be organized into ‘lib’. If this is supposed to be a directory, end it with a forward slash.

Thanks for taking the trouble to lets us know. And you’re right about the forward slash for directories. I’ll add this to the doc.

1 Like