The rust plugin sets an invalid manifest path


#1

I’m trying to build a snap from rust project with a pretty standard setup and a snapcraft.yml derived from the example. The build fails with an obscure error message somewhere after calling /build/pyo3-pack/parts/pyo3-pack/rust/bin/cargo fetch --manifest-path /build/pyo3-pack/parts/pyo3-pack/src/Cargo.toml. This command can’t work since Cargo.toml must be and is in pyo3-pack/Cargo.toml, not in pyo3-pack/src/Cargo.toml.

I wonder, is there any way to tell the rust plugin to use pyo3-pack/Cargo.toml instead?

snapcraft.yml for reference:

name: pyo3-pack
version: 0.0.1
summary: Build and publish python packages from crates with pyo3 bindings
description: Build and publish crates with pyo3 bindings as python packages.

grade: stable
confinement: strict

parts:
  pyo3-pack:
    plugin: rust
    source: .
    build-attributes: [no-system-libraries]
    stage-packages: [libgmp10, libssl1.0.0, liblzma5, libgcrypt20, libgpg-error0]

apps:
  pyo3-pack:
    plugs: [home, network, dbus]
    command: pyo3-pack

#2

There isn’t currently any parameter that can change where snapcraft will point cargo to for the Cargo.toml file. This is expected to be in the root folder of your source's hierarchy. As you specified your source as . then the Cargo.toml is expected to be in your project folder containing along-side the snap folder (which contains the snapcraft.yaml file). If your Cargo.toml is in your project folder in a nested folder called pyo3-pack then you need to set your source parameter to pyo3-pack not .:

parts:
   pyo3-pack:
      plugin: rust
      source: pyo3-pack
      build-attributes: [no-system-libraries]
      stage-packages: [….]

This will require that your entire source tree is inside the folder containing the Cargo.toml file.


#3

The Cargo.toml is in the project root, that’s why I wondered why the src is showing up in the manifest path. I’ve moved the snapcraft.yaml from the project root to the snap folder, but that doesn’t seem to make any difference.

For reference, this is the project:

The output looks as follows:

/build/pyo3-pack/parts/pyo3-pack/rust/rustup.sh --prefix=/build/pyo3-pack/parts/pyo3-pack/rust --disable-sudo --save
/build/pyo3-pack/parts/pyo3-pack/rust/bin/cargo fetch --manifest-path /build/pyo3-pack/parts/pyo3-pack/src/Cargo.toml
Failed to run '/build/pyo3-pack/parts/pyo3-pack/rust/bin/cargo fetch --manifest-path /build/pyo3-pack/parts/pyo3-pack/src/Cargo.toml' for 'pyo3-pack': Exited with code 101.
Verify that the part is using the correct parameters and try again.
Build failed
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/lpbuildd/target/build_snap.py", line 199, in run
    self.pull()
  File "/usr/lib/python2.7/dist-packages/lpbuildd/target/build_snap.py", line 165, in pull
    env=env)
  File "/usr/lib/python2.7/dist-packages/lpbuildd/target/build_snap.py", line 69, in run_build_command
    return self.backend.run(args, env=full_env, **kwargs)
  File "/usr/lib/python2.7/dist-packages/lpbuildd/target/lxd.py", line 460, in run
    subprocess.check_call(cmd, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 541, in check_call
    raise CalledProcessError(retcode, cmd)
CalledProcessError: Command '['lxc', 'exec', 'lp-xenial-amd64', '--env', 'LANG=C.UTF-8', '--env', 'SHELL=/bin/sh', '--env', 'SNAPCRAFT_LOCAL_SOURCES=1', '--env', 'SNAPCRAFT_SETUP_CORE=1', '--env', 'SNAPCRAFT_BUILD_INFO=1', '--env', 'SNAPCRAFT_IMAGE_INFO={"build_url": "https://launchpad.net/~build.snapcraft.io/+snap/9044599915a43ebd1b24eb7e23763e2e-xenial/+build/290033"}', '--env', 'http_proxy=http://10.10.10.1:8222/', '--env', 'https_proxy=http://10.10.10.1:8222/', '--env', 'GIT_PROXY_COMMAND=/usr/local/bin/snap-git-proxy', '--', '/bin/sh', '-c', 'cd /build/pyo3-pack && linux64 snapcraft pull']' returned non-zero exit status 2
Revoking proxy token...
RUN: /usr/share/launchpad-buildd/slavebin/in-target scan-for-processes --backend=lxd --series=xenial --arch=amd64 SNAPBUILD-290033
Scanning for processes to kill in build SNAPBUILD-290033

#4

I think there might be a bug in the rust plugin. It looks like it’s trying to use the system rustc command and not the one it installed via rustup:

error: could not execute process `rustc -vV` (never executed)                   

Caused by:
  No such file or directory (os error 2)

The installed rustc binary should be located in <part-dir>/rust/bin/rustc. The problem is not related to your Cargo.toml at all.


#5

Indeed, I found that this has been reported on launchpad as #1778530. Unfortunately this makes snaps completely unusable for rust projects. It means that not even the example from official rust example can be build.


#6

I’ve also been experiencing issues. I think this bug might have been introduced recently because I have been having problems on my CI server after the introduction of Rust 1.27, but my local setup which I haven’t updated yet still works okay.


#7

Still happening with 1.28

Any workaround to build Rust snaps?


#8

I wonder what changed between 1.26.2 and 1.27 that causes it to break, or maybe they are unrelated and it is just a coincidence.

Oddly, I can build locally but it is just my CI server that continues to fail.