flatpak / flatpak-docs

Flatpak documentation
https://docs.flatpak.org
Other
79 stars 132 forks source link

document and recommend building less stuff #491

Closed skierpage closed 2 months ago

skierpage commented 2 months ago

I've made patches to keep the org.kde.skrooge flatpak working on flathub and kde-runtime-nightly. When I entered a shell in a running instance I found lots of files from modules that the app only needs when building. One module (sqlcipher) build system even requires tclsh, which means all kinds of tcl machinery showed up in the flatpak. I cry at all the wasted CPU cycles and disk space.

The flatpak Building docs talk about Cleanup these files, but in many cases it would be much better not to build them at all! I think adding something like the following in Cleanup, or in a build commands section.

Look at the built flatpak for unneeded files: man pages in /usr/share/man, documentation, other binaries in /app/bin , etc.

(I use flatpak enter <PID> /bin/bash to enter a working flatpak, but there's surely a way to look at the results of a flatpak build; there isn't a doc page about running a flatpak build.)

If the manifest is removing lots of files, it may be a sign that your manifest is building more artifacts in a module than the flatpak needs; use build-command, config-opts, make-args and other Module properties to build less stuff. It's a good idea to add a comment such as "//": "flatpak only needs library xyz from this module"

(I have yet to figure out how to get the flatpak manifest to only build tclsh in its tcl module.)

bbhtt commented 2 months ago

I'm not exactly sure what you want documented here?

"Building less stuff" and the "cleanups" are highly specific to an app and the source. Eg. One app may not need python bindings for some source, but an app written in python will need them.

It may be fine to cleanup typelib files for most, but some apps can use them at runtime. /share/docs is cleaned up for most apps but a documentation viewer app will need it.

It's hard to produce generic documentation that will cover all cases.

It's upto the maintainer to decide what should be build or not and what to cleanup. They know their app better.

skierpage commented 2 months ago

I'm not exactly sure what you want documented here?

Add something like the text I put in quotes. I understand there's no recipe for this, but looking at flatpaks it seems many don't even know to try. I think those sentences would improve the documentation.

To help manifest writers do less stuff and cleanup, flatpak build documentation could explain what happens during module build (what files it copies, do cleanup commands run in the source or destination directory, etc.). It would also be useful to know what the default commands for each build type are. But that's a lot of work; one step at a time.

bbhtt commented 2 months ago

Added a note to recommend building less stuff by default.

bbhtt commented 2 months ago

(I use flatpak enter /bin/bash to enter a working flatpak,

Yea that's fine, you can also use flatpak run --command=sh $FLATPAK_ID or directly look at the files in ~/.local/share/flatpak/app/$FLATPAK_ID/current/active/files/ (for a user install) /var/lib/flatpak/app/$FLATPAK_ID/current/active/files/ (for a system install)

but there's surely a way to look at the results of a flatpak build;

You can just check the contents like above or check the contents of the build directory. It should be builddir/files from where you ran flatpak-builder builddir --force-clean manifest

there isn't a doc page about running a flatpak build.)

https://docs.flatpak.org/en/latest/first-build.html#test-the-build

flatpak build documentation could explain what happens during module build (what files it copies

Whatever you specify via build-commands, post-install or whatever cmake/ninja/make installs, is installed.

do cleanup commands run in the source or destination directory, etc.).

No cleanups are run by default unless you added the property asking for it.

It would also be useful to know what the default commands for each build type are.

This would be done when https://github.com/flatpak/flatpak-docs/issues/101 is solved.