[WIP] extensions: add cleanup extension
Metadata
Current evaluation
Closed unmerged as maintainers shifted cleanup into core Snapcraft; merged PR snapcraft#3092 (ea9a58209) added core20 stage-package filtering using the base manifest.
Resolution: closed superseded
Reason: The cleanup-extension proof of concept was abandoned in favor of core Snapcraft behavior. PR #3092, merged as commit ea9a58209, filters core20 stage-packages against the base manifest, addressing the proposal's base-snap pruning path.
Evaluated by: mr-cal-bot
No scores available.
Issue body
This PR is a proof of concept to start a discussion.
I'd like to add a "cleanup" extensions which removes all the libraries from the prime folder which are already provided by the connected content snaps and the base snap. This turns out to be very useful for reducing the snap size. As an example; the SDLPoP snap size goes down from 31MB to 1 MB and the mc-installer snap size goes from 116MB to 40MB. This works best as an extension because extensions themselves might add content snaps and parts, so the person creating the snap doesn't know yet which content snaps need to be scanned and which parts the `cleanup` part needs to depend on in order to run last.
However, this means
1. the extension needs to run last, because other extensions might add parts and content snaps.
2. the extension needs to have a way to access to the *expanded* `snapcraft.yaml` instead of the original to see the changes of other extensions.
I'm not entirely sure how to do this.
1. I solved `1` in the `apply_extensions` function by supplying extensions with the already-modified `yaml_data` instead of `original_yaml_data`. However, this way all extensions will use the already-expanded data.
2. I solved `2` by prefixing the extension name with `z`. Either I could implement a system where an extension can specify its order using a number, or implementing a "two-stage" expansion process and a way for an extension to specify it should run in the second stage.
So do you think this is a good candidate for an extension? If so, how do I solve 1 and 2?
*Note: I'm thinking of improving the removal logic but I first want to make sure I can actually turn it into an extension. The new removal logic could be that when a library is already available in the base snap, it only removes that library when the version in the snap itself is identical to the one in the base snap. This way, a snap can still override libraries in the base snap and still use this extension.*
## Which snaps would use this?
This extension would be used by a regular snap to remove any libraries from the snap which already exist in the base and content snaps it will use. It's basically an extension which adds this post-build cleanup part. The mc-installer snap, for example, would use this extension to remove any libraries which are already present in the gnome-2-28 and the core18 snaps.
## Why is this `cleanup` extension important?
* It's a really easy way to reduce your snap size. The `mc-installer` snap goes from 104MB to 39MB using this extension.
* It GREATLY improves startup time. The `mc-installer` snap goes from a cold start of 5 seconds to 1 second using this extension.
Startup time and snap size are very dependent on each other because of the [decompression time](https://forum.snapcraft.io/t/squashfs-performance-effect-on-snap-startup-time/13920) and the [resolving of dynamically linked libraries](https://forum.snapcraft.io/t/effects-of-dynamic-library-caching-on-snap-startup-performance/14454/5). If you have less libraries in your snap, there is less to decompress and less to keep the dynamic linker busy.
- [x] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)?
- [x] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)?
- [x] Have you successfully run `./runtests.sh static`?
- [x] Have you successfully run `./runtests.sh tests/unit`?
-----
Evaluation history
| Date | Model | Scores | Action | Summary |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed superseded | Closed unmerged as maintainers shifted cleanup into core Snapcraft; merged PR snapcraft#3092 (ea9a58209) added core20 stage-package filtering using the base manifest. | |
| stealth/space-bunny-alpha | — | closed stale | Cleanup-extension WIP was closed unmerged; maintainers pursued the idea as core Snapcraft work, with PR #3092 covering base-package pruning. | |
| qwen/qwen3.6-35b-a3b | — | — | Closed without merging. The core team rejected the extension approach, proposing to integrate library cleanup directly into Snapcraft core via dynamic filesets or manifests. The feature was added to the backlog as a core enhancement. | |
| qwen3.6-35b-a3b-mtp-q6 | — | — | Proposed a cleanup extension to reduce snap size by removing duplicate libraries. Core team rejected the extension approach, prioritizing the feature as a core Snapcraft capability. Closed and superseded by internal backlog development. |
Update history
No update history recorded yet.
Related work
-
Superseded By:
snapcraft#3092
(confidence 94%)
Merged core20 base-manifest filtering replaced part of the proposed cleanup-extension approach, though content-snap pruning remained an undesigned backlog item.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #3679 Expand extensions | snapcraft | merged | Merged PR snapcore/snapcraft#3679 via commit 07a8d695c, expanding extensions for CRAFT-948 in the snapcraft/7.0 branch. | |
| #3781 extensions: refactor | snapcraft | merged | Merged in snapcraft#3781 via commit 986a9895b (merge 52155ff01), centralizing extension checks in the base class to prevent future cyclic imports. |