Hi all,
This post explains how ALSA support can be added to a snap in a generic way.
If you’ve ever snapped something that uses ALSA or falls back to ALSA you’ll be aware that simply adding libasound2
to stage-packages:
is not the only required step because ALSA hardcodes paths to configuration files at build time.
I’ve been working on a few products and projects that use ALSA and have created this alsa-lib
part that builds alsa-lib
from source and creates the ALSA configuration files in a path relative to the snap. Here is the alsa-lib
part:
parts:
alsa-lib:
plugin: autotools
source: ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.1.5.tar.bz2
configflags:
- --prefix=/usr
- --sysconfdir=/etc
- --libexec=/usr/lib
- --libdir=/usr/lib
- --localstatedir=/var
- --with-configdir=/snap/$SNAPCRAFT_PROJECT_NAME/current/usr/share/alsa
- --with-plugindir=/snap/$SNAPCRAFT_PROJECT_NAME/current/usr/lib/alsa-lib
- --disable-static
stage:
- usr/include
- usr/lib
prime:
- -usr/bin
- -usr/include
- -usr/lib/pkgconfig
- -usr/share/alsa/alsa.conf
- -usr/share/alsa/pcm
- -usr/share/alsa/topology/broadwell
If you’re staging libasound2
then you can drop that and add alsa-lib
to the after:
keyword for the source part of the application that requires ALSA, as shown in this example:
mmplay:
plugin: make
source: http://www.michaelminn.com/linux/mmplay/mmplay-2009.01.01.tgz
build-packages:
- g++
- libmad0-dev
stage-packages:
- libmad0
after:
- alsa-lib
The apps:
that require ALSA will also need to use the environment:
keyword to set the path to the ALSA configuration files, here’s an example:
apps:
mmplay:
command: usr/local/bin/mmplay
environment:
ALSA_CONFIG_PATH: /snap/$SNAPCRAFT_PROJECT_NAME/current/usr/share/alsa
plugs:
- alsa
- home
Finally, when your snap is built the alsa
interface requires a manual connection or store assertion, for example:
snap connect mmplay:alsa
I’d like to draw this to the attention of @lucyllewy, it will help simplify the Audacity snap you’re working on and is way easier to maintain than messy solution I showed you the other day.
I hope others find this useful too