What is an efficient build workflow with snapcraft

I’m trying to snap a project which takes over 30 minutes to build the binaries.

When I fail on the steps “stage” and “prime”, I have no good way to re-run those steps - and I end up with a super inefficient workflow as you can imagine. I use LXD.

Basically my workflow is:

$ snapcraft --use-lxd --debug
# Wait 30 minutes for build.
# Fail, edit snapcraft.yaml
$ snapcraft clean
# Repeat

I’m sure I’m doing this completely bogus, but I can’t find any information on how to clean/reset and re-run specific step(s) for a given part so to reduce the build time. I browsed the forum some and also tried to find docs for this, to no avail.

Does anyone have a good workflow to share so I can set myself straight here and avoid going mad about my inability to do this right?

snapcraft 7.3.2

You don’t need to run snapcraft clean everytime. But if you see, even after you tried to fix an error it stayed, you can try to clean the snapcraft then.

I find it most useful to run snapcraft --debug. This will run a build until it hits an error but then drop you into a shell within the (LXD) build-environment for troubleshooting. If you make changes, you can then run snapcraft within that environment to continue the build. This works even if you edit to the snapcraft.yaml (generally, as long as you don’t affect the scope too much).

Some of this is outlined here: https://snapcraft.io/docs/iterating-over-a-build

3 Likes

Is there no way to be able to see the build as it happens? The output from my compiler for example is useful for me to know where in the process I am and also helps me spot problems earlier. When my builds are hours, I can save shitloads of time to be able to introspect rather than having to wait for the process to either complete or die.

I know I could do this at some point in time - but no longer.

Adding --verbosity=debug to the snapcraft command should produce a stream of output similar to what you’re asking. This used to be default snapcraft behaviour, I think.

2 Likes

I’ll try this after this build (takes about an hour). Thanx for getting that info.

[UPDATE] - it worked! Thanx! Saves me tons of time. This should be default.

1 Like

you might want to click the “affects me too” at the top of:

this is sadly an annoying “new feature” of snapcraft 7.x … a build tool that only shows a spinner by default instead of proper build output kind of defeats the purpose …

2 Likes

I don’t mind a spinner if debug wasn’t specified. But if I need debug, I need debug.

Snap try might also be useful.

I did the following to avoid needing to rebuild the binaries in the snap when I was working on configuration files, wrapper scripts etc.

snapcraft prime
snapcraft try
snap try <path-to-prime-folder>

But I guess it doesn’t help if the snap fails to build or if the binaries needs to be rebuilt.