5

I've got a snap that I'd like to build for multiple architectures. Right now, in the snapcraft.yaml file I define a wrapper as the binary to execute, which sets up environment variables required for the app to run.

One piece of script code that it contains is the following:

#!/bin/sh
ARCH='x86_64-linux-gnu'
export LD_LIBRARY_PATH=$SNAP/usr/lib/$ARCH:$LD_LIBRARY_PATH

Obviously, hardcoding ARCH is not optimal, as non-amd64 builds will not work correctly. However, arch detection using dpkg-architecture will not work when using Snapcraft.

How can I dynamically detect the host's architecture in my wrapper to set the correct library paths while building the snap with Snapcraft?

Code is available as part of the snappy desktop examples.

5

The binary wrappers (and service files) define the SNAP_ARCH environment variable for you. Unfortunately not an ideal solution since they're not triplets, but it should be enough information for you to get there with a case statement or something.

1

For the sake of completeness, I ended up using the following shell snippet:

#!/bin/sh

case "$SNAP_ARCH" in
    "amd64") ARCH='x86_64-linux-gnu'
    ;;
    "i386") ARCH='i386-linux-gnu'
    ;;
    *)
        echo "Unsupported architecture for this clock app build"
        exit 1
    ;;
esac

However, as the wrapper starts getting complicated, I'm rather looking at creating a Snapcraft plugin instead.

  • 1
    The link to the Snapcraft plugin docs is a 404. You probably want this one. I'd edit, but it's not enough characters :P . – Kyle Apr 22 '16 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.