Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snapcraft custom LD_LIBRARY_PATH

Tags:

snapcraft

When building a snap package, the wrapper script automatically adds $SNAP/usr/lib to the LD_LIBRARY_PATH.

When building my package on docker, some libraries (in this case liblapack and libblas) are installed in subdirectories: $SNAP/usr/lib/lapackand $SNAP/usr/lib/libblas respectively.

Although all the dependencies are defined under stage-packages in my snapcraft.yaml, the paths above are not included in the wrapper script.

How can I force snapcraft to add the path to all the libraries to the wrapper script automatically?

like image 426
Geotob Avatar asked Mar 24 '17 04:03

Geotob


1 Answers

Snapcraft maintains a list of common library paths (e.g. /usr/lib/, /usr/lib/<arch>, etc.). If those directories exist, it will add them to LD_LIBRARY_PATH. Think of how Ubuntu "finds" libs in such unpredictable paths as the one you mentioned: this is one of the reasons behind /etc/ld.so.conf. However, the typical way packages notify Ubuntu of new libraries is in a hook that is run after the Debian package is installed. In the case of Snapcraft, those hooks are never run-- stage-packages are simply unpacked. This means Snapcraft has no easy way of learning that the stage-package it just unpacked has a library in an unpredictable place.

While Snapcraft cannot currently help you automatically, you can definitely do this yourself, using one of two ways:

  1. Create a wrapper script that sets LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/usr/lib/lapack and then execs the binary you actually want to run. Then use that wrapper script in your apps section.
  2. Make use of the new and as yet undocumented environment keyword, like this:

    apps:
      my-app:
        command: my-binary
        environment:
          LD_LIBRARY_PATH: $LD_LIBRARY_PATH:$SNAP/usr/lib/lapack
    
like image 170
kyrofa Avatar answered Oct 22 '22 00:10

kyrofa