rust plugin crashes when trying to rebuild a snap package

Bug #1825858 reported by shahn
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Snapcraft
Fix Released
Undecided
Unassigned

Bug Description

To reproduce:

- create a rust project that will build and install executables (e.g. with `cargo init --bin`)
- add a snapcraft.yaml using the rust plugin
- run `snapcraft` (this works)
- run `snapcraft` again. This fails with:

```
/root/.cargo/bin/cargo +stable install --path /root/parts/scriptkeeper/build --root /root/parts/scriptkeeper/install
  Installing scriptkeeper v0.1.0 (/root/parts/scriptkeeper/build)
error: binary `scriptkeeper` already exists in destination as part of `scriptkeeper v0.1.0 (/root/parts/scriptkeeper/build)`
Add --force to overwrite
```

It seems as if the plugin runs `cargo install` on the same virtual machine, but that fails the second time, because `cargo` prevents you from overwriting executables without passing `--force`. `snapcraft clean scriptkeeper` fixes this, but it also means that I have to rebuild the entire project for every little change. Which is annoying when trying to debug the snap file.

Here's the project and commit where I'm seeing this: https://github.com/Originate/scriptkeeper/commit/2160eeeada5a44546e743f11a90798c8c19083e5

Using:
- snapcraft, version 3.4
- multipass 0.6.0
- multipassd 0.6.0
- Ubuntu 18.10
- base: core18

Tags: rust
Revision history for this message
Kenneth Koski (knkski) wrote :

I found this workaround that allows not doing a full rebuild:

parts:
  part-name:
    source: .
    plugin: rust
    # https://forum.snapcraft.io/t/issue-with-rebuilding-a-rust-snap/10830
    override-build: |
      [ -f "$SNAPCRAFT_PART_INSTALL/bin/juju-kubectl" ] && rm "$SNAPCRAFT_PART_INSTALL/bin/juju-kubectl"
      snapcraftctl build

Revision history for this message
Leonora Tindall (lfstindall) wrote :

A potential fix is to add --force to the cargo arguments.

Revision history for this message
Chris MacNaughton (chris.macnaughton) wrote :
Changed in snapcraft:
status: New → Fix Committed
Changed in snapcraft:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.