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:


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.


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.


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


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

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 .
    – kyrofa
    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.