As explained

=> in my previous post

, application sandboxing doesn't need to be relegated to the cloud and server space, desktop users can also enjoy a pain-free and transparent local app experience thanks to technologies like Flatpak and Snappy. Today I'll show you how this fantastic concept can come to fruition on your own desktop with the simplest packaging framework I know: AppImage. Let's talk a little about it before getting our hands dirty.

Why AppImage?

The aim behind packaged apps is to provide simplicity. Obtaining and using a packaged application should be equally simple tasks. All you should have to worry about is downloading a file from the vendor's website or a package from a repository, launching it et voilà. Major existing implementations such as Canonical's Snappy and Red Hat's favourite, Flatpak, provide a decent level of simplicity to the end user, although it is not a wholly no-frills experience. At the very least, you'll need to install a few packages on your system. And with Flatpak, you'll also need to install one or more runtimes before you can get any apps running. Equally, building and distributing Snappy and Flatpak packages is not as simple as it could be, in my humble opinion.

=> AppImage

, on the other hand, does promise the simplest achievable process for everyone, and it does get it right.

AppImage files are very easy to produce: all you need to do is to whack all your binaries, libraries and assets into a single directory and run a bundling application on them. This will give you a single, self-contained binary which you can directly upload to a public software repository for anyone to download and run. There is no installation process, no configuration steps, no installing appimage packages or dependencies for your end user. Just double-click the file and you're cooking. It's really that simple.

What does AppImage exactly bring to the table that other packaged app implementations don't? Well, glad you asked. Here's a list!3:

With all this in mind I want to commence this tutorial. We'll be sandboxing a simple C application with some library dependencies to make it a bit more interesting. Note these steps easily translate to C++, Fortran or any language that scatters -or not- dependencies all over your filesystem. I've decided to use one of my own projects, which is a basic C instant messaging application, although complex enough to include its own libraries, so you also get to see how that's done. The only things you need to get started are a working Linux distribution with GCC installed, a shell and your trusty text editor1. Right, let's get to it then.

Sandboxing an Application with AppImage

Firstly, let's clone the repository of the application we're going to be building for this tutorial

git clone git@github.com:dvejmz/cim.git

Now cd into the repository you just downloaded and make a new directory, which we'll use as a build workspace for our packaged app. By convention it should be called like the application you want to package and include the .AppDir suffix.

mkdir -p cimx/cimx.AppDir

cd cimx/cimx.AppDir

Let's copy the application's source files and assets into it

cp -r ../../cim-client/ ./src

cp -r ../../libcim/ ./libcim

cp -r ../../assets ./assets

Run this couple of sed commands to make the application's Makefiles aware of the AppImage directory structure.

sed -i -e 's#^LIB_DIR=/usr/local/lib/cim#LIB_DIR=../libcim/bin -L../usr/lib#' src/Makefile

sed -i -e 's#-lcrypto#lib/libcrypto.so.1.1#' libcim/Makefile

On to the build stage, starting with libcim, which provides all the code shared between the client and the server executables of our instant messaging application,

cd libcim

make

Create the directories where the library and binary files will live in the AppDir.

cd ../

mkdir -p ./usr/lib ./usr/bin

cp libcim/bin/libcim.so ./usr/lib

cp libcim/lib/*.so* ./usr/lib

We need to set the linker library path so that it can find our libraries when we compile the binary in the upcoming steps

export LD_LIBRARY_PATH=$(realpath ./usr/lib):$(realpath ./bin):$(realpath ./lib)

On to building the main application

cd ./src

make

Copy the resulting executable into the AppImage directory

cp ./bin/cimx ../usr/bin

Proxy Information
Original URL
gemini://dvejmz.srht.site/2017-10-09-discovering-appimages.gmi
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
148.799576 milliseconds
Gemini-to-HTML Time
1.343393 milliseconds

This content has been proxied by September (ba2dc).