Snapping a multi-crate app

I'm trying to create snap packages (aka "snaps") for my app that consists of two crates: a CLI/lib crate (fclones) and a GUI crate (fclones-gui). The app uses cargo workspace. Building it with cargo works fine.

I'd like it to be two separate snaps because I'd like to give the choice to the user, which interface they want. The gui variant needs a bit more modern OS version, as GTK-4 / adwaita libs are required, when the CLI variant runs on almost anything.

If I put a snapcraft.yaml in the root dir of the project, set the source property to . and select the crate to build with rust-path, it builds fine, either of the snaps. But I'd like to be able to build both.

But unfortunately snap seems to not allow placing multiple snapcraft.yaml files in the top dir (correct me if I'm wrong - but I failed to find a way to tell it which file to use).

Therefore I tried making a separate snapcraft.yaml in each subcrate and build the snap from there. Unfortunately this doesn't work, because fclones-gui depends on the core fclones lib, and if building from the subdirectory, snap cannot find that dependency (I guess this is because it only copies its own directory to the VM and builds on the VM, so the dependency is not there).

I also tried specifying the source location with source: .. like that:

parts:
  rust-deps:
    plugin: nil
    build-packages:
      - curl
    override-pull: |
      curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

  fclones-gui:
    plugin: rust
    source: ..
    after: [rust-deps]
    build-packages:
      - pkg-config
      - libgtk-4-dev
      - libadwaita-1-dev
    stage-packages:
      - libgtk-4-1
      - libadwaita-1-0
    rust-path: 
      - fclones-gui

That also doesn't work:

2023-06-18 11:40:15.896 :: export CRAFT_STAGE="/root/stage"
2023-06-18 11:40:15.896 :: export CRAFT_PRIME="/root/prime"
2023-06-18 11:40:15.896 :: export CRAFT_PROJECT_NAME="fclones-gui"
2023-06-18 11:40:15.896 :: export CRAFT_PART_NAME="fclones-gui"
2023-06-18 11:40:15.896 :: export CRAFT_STEP_NAME="BUILD"
2023-06-18 11:40:15.896 :: export CRAFT_PART_SRC="/root/parts/fclones-gui/src"
2023-06-18 11:40:15.896 :: export CRAFT_PART_SRC_WORK="/root/parts/fclones-gui/src"
2023-06-18 11:40:15.896 :: export CRAFT_PART_BUILD="/root/parts/fclones-gui/build"
2023-06-18 11:40:15.896 :: export CRAFT_PART_BUILD_WORK="/root/parts/fclones-gui/build"
2023-06-18 11:40:15.896 :: export CRAFT_PART_INSTALL="/root/parts/fclones-gui/install"
2023-06-18 11:40:15.896 :: export PATH="/root/parts/fclones-gui/install/usr/sbin:/root/parts/fclones-gui/install/usr/bin:$PATH"
2023-06-18 11:40:15.896 :: export LDFLAGS="-L/root/parts/fclones-gui/install/usr/lib -L/root/parts/fclones-gui/install/usr/lib/x86_64-linux-gnu"
2023-06-18 11:40:15.896 :: export PKG_CONFIG_PATH="/root/parts/fclones-gui/install/usr/share/pkgconfig"
2023-06-18 11:40:15.896 :: ## Plugin environment
2023-06-18 11:40:15.896 :: export PATH="${HOME}/.cargo/bin:${PATH}"
2023-06-18 11:40:15.896 :: ## User environment
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.093 plugin validation command: 'rustc --version'
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.151 executed rustc --version with output rustc 1.70.0 (90c541806 2023-05-31)
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.152 Executing PosixPath('/root/parts/fclones-gui/run/build.sh')
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.158 :: + cargo install --locked --path fclones-gui --root /root/parts/fclones-gui/install --force
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.206 :: error: `/root/parts/fclones-gui/build/fclones-gui` is not a directory. --path must point to a directory containing a Cargo.toml file.
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.207 Failed to run the build script for part 'fclones-gui'.
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.214 Traceback (most recent call last):
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.214   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_parts/executor/step_handler.py", line 146, in _builtin_build
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.214     _create_and_run_script(
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.214   File "/snap/snapcraft/9362/lib/python3.8/site-packages/craft_parts/executor/step_handler.py", line 409, in _create_and_run_script
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.214     subprocess.run(
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.214   File "/snap/snapcraft/9362/usr/lib/python3.8/subprocess.py", line 516, in run
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.214     raise CalledProcessError(retcode, process.args,
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.214 subprocess.CalledProcessError: Command '[PosixPath('/root/parts/fclones-gui/run/build.sh')]' returned non-zero exit status 101.
2023-06-18 11:40:15.896 :: 2023-06-18 09:40:15.214

Any ideas how to do it? Maybe someone here already published a multicrate project?

The only thing that comes to my mind is writing a script that would copy a proper snapcraft.yaml file to the top directory, snap it in the root project dir, and then copy another one there, but that feels very hacky.

I also have no idea how to report those problems to the snacraft rust plugin authors.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.