Exclude parts for architecture

Is it possible with snapcraft.yml to exclude certain parts to be uilt for certain architecture? In my case I have a part defined which provides an optional dependency. However this part does not build on all architectures, so I would like to just leave it out if unsupported.

1 Like

You could make a custom build stanza, something like this.

parts:
  foo:
  plugin: autotools
  build: |
    if [[ `arch` = "x86_64" ]]; then
      # Do x86_64 magic here
    fi

With whatever shell script you need in there to make it happen.

Ok, that might work. There is no way to call the default script in this section, right? So I basically have to reimplement the build script from the plugin used? In my case this is the rust plugin, I will try to figure out what it does in the build step.

Another option would be to ommit the architecture entirely. In my case this is armhf, is there a way to tell build.snapcraft.io to only build certain architectures?

Create you custom plugin inheriting from the rust plugin. Then define pull and build, check for the architecture and if it is in your white list or not in your black list call super().pull() or super().build().

2 Likes

I got this working for my case by using this:

parts:
  gifski:
    plugin: rust
    source: https://github.com/ImageOptim/gifski.git
    source-tag: 0.6.2
    rust-channel: stable
    build: |
      if [ `arch` = "x86_64" ] || [ `arch` = "i686" ]
      then
        export RUST_PATH=../rust
        export RUSTC=${RUST_PATH}/bin/rustc
        export RUSTDOC=${RUST_PATH}/bin/rustdoc
        ${RUST_PATH}/bin/cargo install -j$(nproc --all) --root "${SNAPCRAFT_PART_INSTALL}" --path .
      else
        echo "Not building gifksi on $(arch)"
      fi

Thanks for the support here. Still I think Snapcraft should offer some parameters for this, Flatpak does this nicely by allowing both a skip-arches (blacklist) and only-arches (whitelist) parameter per built component.

3 Likes