Architectures

By default, Snapcraft builds a snap to run on the same architecture as the build environment. This behaviour can be modified with an optional root architectures keyword which is added to a snap’s snapcraft.yaml.

The architectures keyword defines a set of both build and run architectures with the following syntax:

architectures:
  - build-on: [<build arch 1>, <build arch 2>]
    run-on: [<run arch 1>, <run arch 2>]
  • valid values include s390x, ppc64el, arm64, armhf, amd64 and i386
  • the default value for run-on is the value of build-on
  • run-on: supports a value of all to denote a snap that can run everywhere (e.g. a snap that is only shell scripts)
  • if the value list is a single item, it can be simplified to a scalar (e.g. build-on: amd64)

Even without local access to a specific hardware architecture, snapcraft remote-build enables anyone to run a multi-architecture snap build process on remote servers using Launchpad. See Remote build for more details.

CI systems and build-sets

Continuous Integration (CI) systems, such as build.snapcraft.io, can use the architectures keyword to determine which architectures to build a snap on. With none specified, a snap is built on all architectures.

A build-set is a set of snaps built at the same time from the same snapcraft.yaml, such as from a CI-build triggered by a git commit.

Rather than manage build revisions separately, a build-set’s revisions can be managed as a group. Assuming a CI system will fail when a single build fails within a build-set, build-error: ignore can be used to indicate an experimental or in-progress architecture that is included in a build-set if its build succeeds but not cause a CI build failure if it fails.

For example, without build-error: ignore, and given a build set of [amd64, i386, armhf]. If the armhf build fails, the entire build-set is considered to have failed, regardless of whether or not amd64 and i386 builds succeeded.

Examples

Example 1

architectures:
  - build-on: i386
    run-on: [amd64, i386]
Snapcraft’s interpretation

If running on an i386 host, Snapcraft will build a snap that claims it runs on both amd64 and i386. If running elsewhere, Snapcraft will follow its default behavior, building a snap that runs on the build architecture.

CI systems’ interpretation

As there is a single non-scalar object in this list, CI systems know to produce only a single snap. Checking the build-on key, they know that it needs to be built on i386.

Example 2

architectures:
  - build-on: amd64
    run-on: all
Snapcraft’s interpretation

If running on an amd64 host, Snapcraft will build a snap that claims it can run on all architectures. If running elsewhere, Snapcraft will follow its default behavior, building a snap that runs on the build architecture.

CI systems’ interpretation

CI systems can assume that the user only wants the snap built on amd64.

Example 3

architectures:
  - build-on: amd64
    run-on: amd64

  - build-on: i386
    run-on: i386

Which is the same as:

architectures:
  - build-on: amd64
  - build-on: i386
Snapcraft’s interpretation

As far as Snapcraft is concerned, this is no different from its default behavior.

CI systems’ interpretation

CI systems can assume that the user only wants the snap built on amd64 and i386, and the resulting snaps are to be considered a build set (e.g. if amd64 succeeds but i386 fails, the entire set should be considered to have failed).

Example 4

architectures:
  - build-on: amd64
    run-on: amd64

  - build-on: i386
    run-on: i386

  - build-on: armhf
    run-on: armhf
    build-error: ignore
Snapcraft’s interpretation

Again, as far as Snapcraft is concerned, this is no different from its default behavior.

CI systems’ interpretation

CI systems can assume that the user only wants the snap built on amd64, i386, and armhf. While the resulting snaps are considered a build set, armhf may fail. If it does, release the rest of the build set as normal (i.e. don’t fail the entire build set if armhf fails). If amd64 or i386 fails, however, still consider the entire build set to have failed.

Example 5

architectures:
  - build-on: [amd64, i386]
    run-on: all
Snapcraft’s interpretation

If building on amd64 or i386, Snapcraft will produce a snap that claims it runs on all architectures. If running elsewhere, Snapcraft will follow its default behavior, building a snap that runs on the build architecture.

CI systems’ interpretation

There is only a single non-scalar item in architectures, so CI systems know there is only a single snap to be produced from this, and the resulting snap will claim it runs on all architectures. However, the snap author has specified that either amd64 or i386 could be used to produce this snap, which leaves it up to the CI system to decide which architecture to use. Which one has a smaller build queue?

Example 6

architectures: [amd64, i386]

Which is the same as:

architectures:
  - build-on: [amd64, i386]

Which is the same as:

architectures:
  - build-on: [amd64, i386]
    run-on: [amd64, i386]
Snapcraft’s interpretation

If building on amd64 or i386, Snapcraft will produce a snap that claims it runs on both amd64 and i386. If running elsewhere, Snapcraft will follow its default behavior, building a snap that runs on the build architecture.

CI systems’ interpretation

There is only a single non-scalar item in architectures, so CI systems know there is only a single snap to be produced from this, and the resulting snap will claim it runs on both amd64 and i386. However, the snap author has specified that either amd64 or i386 could be used to produce this snap, which leaves it up to the CI system to decide which architecture to use. Which one has a smaller build queue?

Example 7

architectures:
  - build-on: amd64
    run-on: all

  - build-on: i386
    run-on: i386
Snapcraft’s interpretation

Technically Snapcraft could work with this, and treat it similarly to Example 5. However, in this proposal it is an error, mostly to inform the user because of the CI systems’ interpretation of this.

CI systems’ interpretation

There are two non-scalar items in architectures, which implies that two snaps will be built. However, one of the snaps to be produced would claim it runs on i386, while the other would claim it runs everywhere (including i386). That means they would both be released to i386, which is likely not what the developer intended (since the user will only receive the latest). This is an error case.

6 Likes

What about cross compilation? Shouldn’t there also be a build-for keyword?

well, the combination fo build-on and run-on is essentially that …

if you cross build for armhf you’d use “build-on: amd64” and “run-on: armhf” like here:

@kyrofa it would be very helpful if this doc could have some cross reference to the architecture specific bits in stage-packages: (and/or build-packages) often you use the more exotic build-on/run-on combinations together with arch specific entries in build/stage-packages entries.

1 Like

Thanks @ogra I am still a bit confused though. What is the relationship between the root keyword architectures and the command line --target-arch flag?

For example snapcraft --target-arch=armhf and also how about snaps which are “cross platform” (say Bash scripts or interpretted programs) versus programs which need to be compiled separately and linked to platform specific dynamic libraries?

Once you have the proper build-on and run-on lines, there is no need for --target-architecture anymore since you defined it in your snapcraft.yaml already.

if you read the first post carefully you will see “run-on: all” … that is for bash scripts and friends :wink:

2 Likes

This is work in progress, and documents behavior that does not yet exist in its entirety. The snapcraft CLI gained support for this in v2.42, but it’s not yet fully integrated with build.snapcraft.io.

This is now supported by build.snapcraft.io: that is, builds will be dispatched for the set of architectures requested in snapcraft.yaml, provided that they’re supported by BSI. (In most cases, I expect that the main use case for this will be to disable builds for architectures that you know can’t work, although it will later be a useful building block for build sets.)

This will allow us to enable builds for ppc64el and s390x on BSI (the remaining Ubuntu architectures that we don’t yet support there), but we’ll do that early next week rather than making a significant change like that just before the weekend.

4 Likes

This will allow us to enable builds for ppc64el and s390x on BSI (the remaining Ubuntu architectures that we don’t yet support there), but we’ll do that early next week rather than making a significant change like that just before the weekend.

Now done.

2 Likes

Is it possible to specify an architecture that we want it not build on? Enumerating all other arches doesn’t seem to be desirable.

For example I know a certain snap won’t build on armhf architecture, is there a way to disable it without enumerating all other architectures in the build-on key?

What are all the supported architectures?

This should also more explicitly explain What is the proper way to build and support multi-architecture snap in store (year 2018)? and the $SNAP_ARCH_TRIPLET variable.

The ‘Architectures’ page isn’t visible in the ‘contents’ down the page’s left-hand column. Is that deliberate?

It hasn’t been deliberately left off, and adding it is certainly something we should do if it’s considered important enough (it is linked to from the snapcraft yaml reference pages).

I think it probably is important enough, but needs a little work (I can do this).

1 Like