The rust plugin

The rust plugin is useful for building Rust-based parts using the Cargo package manager to drive the build. This plugin uses the common plugin keywords as well as those for sources. For more information, see Snapcraft parts metadata.

Additional features and syntax are dependent on which base is being used, as outlined below:

See Rust applications for a simple example, or search GitHub for projects using the plugin.

ⓘ This is a snapcraft plugin. See Snapcraft plugins and Supported plugins for further details on how plugins are used.

base: core24 | core22

  • rust-features (list of strings) Features used to build optional dependencies
  • rust-path (list of strings) Defaults to the current working directory. Can be set to the relative path for the crate to build when using workspaces. Only one item is currently supported.

Requires Snapcraft version 8.0+ for core24.

Requires Snapcraft version 7.0+ for core22.

base: core20

  • rust-features (list of strings) Features used to build optional dependencies
  • rust-path (list of strings) Defaults to the current working directory. Can be set to the relative path for the crate to build when using workspaces. Only one item is currently supported.

Requires Snapcraft version 4.0+.

base: core18 | core

  • rust-channel (string) Used to select which rust channel (stable, beta, nightly)
  • rust-features (list of strings) Features used to build optional dependencies
  • rust-revision (string) Used to select which rust version

If a rust-toolchain file is detected, the toolchain it specifies will be used by default. However, if rust-channel or rust-revision are set, the rust-toolchain file will be overridden.

If neither a rust-toolchain exists nor rust-channel or rust-revision are set, the latest stable toolchain will be used.

Requires Snapcraft version 3.x+.

1 Like

I’m having trouble getting the rust plugin to work, reported a bug here: https://bugs.launchpad.net/snapcraft/+bug/1813618

It looks like maybe rustup has changed and the plugin needs to be updated. Anyone else having this issue?

What exactly does this mean / how do I use this functionality?

If a rust-toolchain file is detected, the toolchain it specifies will be used by default otherwise the latest stable toolchain will be used.

According to https://rust-lang.github.io/rustup/configuration.html (which I assume is what that’s referring to), The schema for this file is not part of the public interface for rustup.

I’m not sure how to set default_toolchain, as rustup will look in ${RUSTUP_HOME}/settings.toml and /etc/rustup/settings.toml, but that’s happening within the build VM/container. I don’t see how I can add a settings.toml anywhere in my Rust codebase such that rustup will see it when building the snap.

I was looking at slightly the wrong page, https://rust-lang.github.io/rustup/overrides.html#the-toolchain-file is the relevant section about adding a rust-toolchain file to the repo to have rustup use that version automatically. Updated the OP with a link.

2 Likes

How can I disable default features? Ie. I want to pass --no-default-features flag to the cargo

@surv - There isn’t a good way to do this right now. You are welcome to add this in Launchpad so we can track it.

I believe this explanation about how to install a specific Rust version (rustc + cargo) should be included in this doc. It’s the most useful example I’ve seen, to the point it defeats whatever info about the Rust plugin you can find on the snapcraft site.

Really appreciate it, @svet!

1 Like

The plugin was recently rewritten, (re)introducing a few features: