Dynamic Linker Cache

This utility will cache your shared libraries into an ld.so.cache file. Caching the shared libraries in this way should help to speed up your application start times.

This library is meant to be used in combination with the Extensible Hooks.

Usage with sc-jsonnet

Applying the utility with sc-jsonnet is the easiest method. To use, simply import the library and add linker-cache() to your snapcraft tag. The following code shows a trivial example of using it:

local snapcraft = import 'snapcraft.libsonnet';
local extensible_hooks = import 'https://raw.githubusercontent.com/diddlesnaps/snapcraft-utils-library/master/lib/extensible-hooks.libsonnet';
local ld_precache = import 'https://raw.githubusercontent.com/diddlesnaps/snapcraft-utils-library/master/lib/ld-precache.libsonnet';

snapcraft {
    name: ld-precache-example,
    version: "0.1",
    summary: "Example of using the 'ld-precache' library",
    description: |||
        This is my-snap's description. You have a paragraph or two to tell the
        most important story about your snap. Keep it under 100 words though,
        we live in tweetspace and your description wants to look good in the snap
        store.
    |||,

    base: core18,

    # Add the rest of your snapcraft build config here
}
+ extensible_hooks()
+ ld_precache()

If you are using multiple utilities then put the cleanup utility last in the chain. This library expects you to apply Extensible Hooks, too.

Manually adding to snapcraft.yaml

Add the following part into your snapcraft.yaml, and change my-part to a list of all of your snap’s other parts:

parts:
  ld-precache:
    after: [my-part]
    plugin: dump
    source: https://github.com/diddlesnaps/snapcraft-utils-library.git
    source-subdir: snapcraft-assets/ld-precache

Ensure you set the environment block’s FINAL_BINARY to the path of your application executable file. This must be prefixed with $SNAP/:

environment:
  FINAL_BINARY: $SNAP/usr/bin/my-app

Add the layout definition for the ld.so.cache file:

layout:
  /etc/ld.so.cache:
    bind-file: $SNAP_DATA/etc/ld.so.cache

This library expects you to have added the Extensible Hooks customisations, too.