Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Debloating gtk
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo Chat
View previous topic :: View next topic  

Are you interested in debloating gtk?
Yes
61%
 61%  [ 8 ]
No
38%
 38%  [ 5 ]
I don't use gtk
0%
 0%  [ 0 ]
Total Votes : 13

Author Message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 934
Location: Romania

PostPosted: Tue Sep 05, 2023 1:40 pm    Post subject: Debloating gtk Reply with quote

I will try to write this more or less up to the standards of the documentation forum. I posted it here because of the topic.
While this post will have some things about gtk2, most things will be about gtk3. The gtk2 stuff may be outdated, as I no longer used it for some time.
One of the purposes of this post is to shed some light on the khoverlay and their x11-libs/gtk3-classic-patches ebuild.
I hope this sheds some light on how bloated gtk is.

First some history:
A long time ago, the g in gtk used to stand for gimp. The graybeards on the forum may remember that time. I don't, but I will tell from the recorded history.
After some time the g in gtk started to stand for gnome, a project backed by Redhad, a company known for many evils and bloated software, most notably systemd.
As such, they want to get users used to absurd levels of bloat so that systemd looks usable in comparison.

About gtk2:
The least way of running a program is to not run it at all. However, there are some programs that insist on using gtk2 libs when they don't need them.
The programs I encountered were palemoon and basilisk.
To not needlessly build gtk2 when you don't have to, you can use this:
https://github.com/stefan11111/fake-gtk2

The palemoon devs said that this is the way to go in this situation:
https://forum.palemoon.org/viewtopic.php?f=5&t=30227

This isn't to say that one can build apps that actually need gtk2 with this. This is for those that don't need gtk2, but use its headers and link against its libs.
Your build will fail with ld errors about undefined symbols.
You can turn those into warnings and get the build to complete by adding LDFLAGS="${LDFLAGS} -Wl,--warn-unresolved-symbols" to your make.conf, but I'd be surprised if you get those apps to even start or pop our a window.

However, you may end up having to actually install gtk2 because of some app. To not install all the bloat, you can do this:
Add the following to package.provided:
Code:
virtual/freedesktop-icon-theme-0-r4
x11-themes/hicolor-icon-theme-0.17
dev-util/gtk-update-icon-cache-3.24.31
app-accessibility/at-spi2-core-2.46.0
gnome-base/librsvg-2.56.2
x11-themes/adwaita-icon-theme-44.0
x11-themes/gnome-themes-standard-3.28
x11-themes/gtk-engines-adwaita-3.28

Add >=dev-libs/atk-2.46 to /etc/portage/package.mask
run emerge -cav app-accessibility/at-spi2-core(use -C if you have to)
run emerge -av atk::gentoo(has to not be --oneshot)
And then emerge gtk+:2

No patching or overlays are needed so far.
While this gets rid of most of the bloat, it isn't enough to get rid of all the bloat from gtk+:2.
You will have to figure out what you need to pass to the configure script to disable unneeded things like print backends and other bloat. You will possible need some patches.
You are on your own here, as I don't use gtk2.

About gtk3:
As this section is quite big, I will split it into multiple sections. This will also better explain some things about gtk2.
The reason this section is so big is because of how much more bloat was pushed into gtk3.
I don't even want to imagine what "extras" gtk4 has bundled with it and hidden inside the codebase. At this point, even a full compiler wouldn't surprise me.
-Remove dbus:
Gtk3 does not depend on dbus directly, but it depends on app-accessibility/at-spi2-core, which depends on dbus, thus creating a soft dependency on dbus.
This dependency can be easily avoided by patching gtk3.
The patches for this have been included in x11-libs/gtk3-classic-patches from the khoverlay. The patches can also be manually added if desired:
Code:
--- 1/gtk/a11y/gtkaccessibility.c
+++ 1/gtk/a11y/gtkaccessibility.c
@@ -38,8 +38,10 @@
 #include <gtk/gtkaccessible.h>
 
 #ifdef GDK_WINDOWING_X11
+#ifdef HAVE_ATK_BRIDGE
 #include <atk-bridge.h>
 #endif
+#endif
 
 static gboolean gail_focus_watcher      (GSignalInvocationHint *ihint,
                                          guint                  n_param_values,
@@ -983,8 +985,10 @@ _gtk_accessibility_init (void)
   do_window_event_initialization ();
 
 #ifdef GDK_WINDOWING_X11
+#ifdef HAVE_ATK_BRIDGE
   atk_bridge_adaptor_init (NULL, NULL);
 #endif
+#endif
 
   atk_misc_instance = g_object_new (GTK_TYPE_MISC_IMPL, NULL);
 }

Martin V\"ath <martin at mvath.de>

Honor atk_bridge option

--- 1/meson.build
+++ 2/meson.build
@@ -564,7 +564,12 @@
   xfixes_dep     = dependency('xfixes', required: false)
   xcomposite_dep = dependency('xcomposite', required: false)
   fontconfig_dep = dependency('fontconfig', fallback: ['fontconfig', 'fontconfig_dep'])
-  atkbridge_dep  = dependency('atk-bridge-2.0', version: at_spi2_atk_req)
+
+  atk_bridge_enabled = get_option('atk_bridge')
+  if atk_bridge_enabled
+    atkbridge_dep  = dependency('atk-bridge-2.0', version: at_spi2_atk_req)
+    cdata.set('HAVE_ATK_BRIDGE', 1)
+  endif
 
   backend_immodules += ['xim']
 
@@ -583,7 +588,9 @@
     x11_pkgs += ['xdamage']
   endif
 
-  atk_pkgs += ['atk-bridge-2.0']
+  if atk_bridge_enabled
+    atk_pkgs += ['atk-bridge-2.0']
+  endif
 
   cdata.set('HAVE_XDAMAGE', xdamage_dep.found() ? 1 : false)
   cdata.set('HAVE_XCURSOR', xcursor_dep.found() ? 1 : false)

Martin V\"ath <martin at mvath.de>

Add atk_bridge option

--- 1/meson_options.txt
+++ 2/meson_options.txt
@@ -47,3 +47,7 @@
 # input modules
 option('builtin_immodules', type: 'string',
        value: '', description: 'Build specified immodules into GTK so/DLL (comma-separated list), "all", "none" or "backend"')
+
+# Recommended dependencies
+option('atk_bridge', type: 'boolean', value: true,
+  description : 'Enable atk-bridge support')

After adding these patches to your /etc/portage/patches/x11-libs/gtk+:3, you must do this:

Add -Datk_bridge=false to MYMESONARGS in /etc/portage/env/x11-libs/gtk+.
Add app-accessibility/at-spi2-core-2.46.0 to /etc/portage/profile/package.provided
Add >=dev-libs/atk-2.46 to /etc/portage/package.mask
emerge -cav(to remove no longer needed app-accessibility/at-spi2-core, else it will conflict with the next step)
emerge dev-libs/atk(not --oneshot, must be in world file)
And then rebuild gtk+:3 to apply the patches.

Here you have a choice regarding the atk implementation.
dev-libs/atk from ::gentoo is the full implementation and you will see no issues running it(not even warnings printed by glib if you only apply the atk-bridge patches).
I also have an ebuild for dev-libs/atk in my overlay. However, glib prints a lot of warnings and you will get segfaults if you try to print something.
Which one you chose is up to you.
-Remove gdbus:
While this is related, gdbus is mostly an internal thing. As such, it will need patching to remove.
But before this, I'll mention gdbus-codegen.
You can remove the dependency on it by using this:
https://github.com/stefan11111/minimal-gtk3
You first have to add dev-util/gdbus-codegen-2.74.6 to package.provided and then remove it with emerge -cav or emerge -C.
Then go to the files from the git repo and run make install as root.

Note that it also comes with the patches to remove dbus, so if you don't want to use them or use the khoverlay ebuild, you will have to manually delete them. from /etc/portage/patches/x111-libs/gtk+:3
You can modify the Makefile to better suit your needs so that those patches are not installed in the first place.

To remove gdbus, you will have to use this patch:
https://github.com/stefan11111/pastebin/blob/main/remove_gdbus.patch

Note that it conflicts with some patches from the khoverlay, so you will have to either write a new patch or remove some other patches to make it work.
If there is interest, I can write a new patch to work with the khoverlay patches.
The way was written is:
Replace all calls to gdbus functions that return values with 0.
Remove all calls to gdbus functions that don't return values.

Don't optimize out if's that no longer apply if you want your patches to work for some time.
If you have to do that, wrap them if #if 0 ... #endif blocks.
-Remove dependency on rust:
There is work on doing in gentoo:
https://bugs.gentoo.org/911991

In the meantime, add this to your package.provided:
Code:

gnome-base/librsvg-2.56.2

To also remove the icon theme, you can add these to your package.provided:
Code:
virtual/freedesktop-icon-theme-0-r4
x11-themes/hicolor-icon-theme-0.17
dev-util/gtk-update-icon-cache-3.24.31
x11-themes/adwaita-icon-theme-44.0

-Remove printing and unneeded modules:
There is a pesky configure check that prevents the user from not building any printing backends.
To remove it you can use this patch:
Code:
diff --git a/modules/printbackends/meson.build b/modules/printbackends/meson.build
index f034963..47b5adf 100644
--- a/modules/printbackends/meson.build
+++ b/modules/printbackends/meson.build
@@ -34,11 +34,7 @@ endif

 print_backends = []

-if not enabled_print_backends.contains('file')
-  if os_unix
-    error('\'file\' print backed needs to be enabled')
-  endif
-else
+if enabled_print_backends.contains('file')
   print_backends += ['file']
 endif

After doing that, add -Dprint_backends="" -Dbuiltin_immodules=none to MYMESONARGS in /etc/portage/env/x11-libs/gtk+.
Despite what it says, some modules are always built. You can find them in /usr/lib64/gtk-3.0/3.0.0/immodules
I will try to remove them in a way that doesn't compile them and that doesn't need patching the ebuild, because sadly, while patching the source is easily done via /etc/portage/patches, there is no such easy way to patch ebuilds.

Note that the process of debloating gtk is an ongoing endeavor. There may be some things that slipped through the cracks.
Any improvements or suggestions are welcome in the comments. The gtk2 section could use some. The history section could use some insight from someone who remembers that time.
_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
CaptainBlood
Advocate
Advocate


Joined: 24 Jan 2010
Posts: 3831

PostPosted: Tue Sep 05, 2023 1:57 pm    Post subject: Reply with quote

Here media-sound/ardour-7.5 requires gtk2 still.
In the past upstream has claimed gtk3 will never be there.
Nowadays it may be WIP rather...

Thks 4 ur attention, interest & support.
_________________
USE="-* ..." in /etc/portage/make.conf here, i.e. a countermeasure to portage implicit braces, belt & diaper paradigm
LT: "I've been doing a passable imitation of the Fontana di Trevi, except my medium is mucus. Sooo much mucus. "
Back to top
View user's profile Send private message
stefan11111
l33t
l33t


Joined: 29 Jan 2023
Posts: 934
Location: Romania

PostPosted: Wed Dec 27, 2023 12:54 pm    Post subject: Reply with quote

Update after quite some time.
I added some patches here to fix the segfaults when trying to print something while using dev-libs/atk from my overlay:
https://github.com/stefan11111/minimal-gtk3/tree/main/patches/disable-print

Also I decided to check up on the state of gtk4 and I was pleasantly surprised.
All it needs to not be too bloated is to add:
Code:
app-accessibility/at-spi2-core-2.46.0
gnome-base/librsvg-2.56.2

to package.provided
And:
Code:
>=dev-libs/atk-2.46

to package.mask
And that's it. No patching needed.
Of course, dev-libs/atk must be installed on the system.
It doesn't even need the patches to fix the segfaults when printing.

It can be debloated further by removing gdbus-codegen, in a manner similar to gtk3, but it's not something big.
Another thing that can be done is patching the ebuilds for it's dependencies to accept python 3.12, but that will likely be fixed in ::gentoo at some point in the future:
Code:
  dev-lang/python-3.11.7 pulled in by:
    app-text/iso-codes-4.15.0 requires dev-lang/python:3.11
    dev-libs/libxml2-2.11.6 requires dev-lang/python:3.11[xml(+)]
    dev-util/itstool-2.0.7 requires dev-lang/python:3.11[xml(+)]
    media-libs/graphene-1.10.8 requires dev-lang/python:3.11


To sum it up, all that is needed to not have a bloated gtk4 is to add 2 lines to package.provided and 1 line to package.mask. I'd say this is a big improvement from gtk3.
_________________
My overlay: https://github.com/stefan11111/stefan_overlay
INSTALL_MASK="/etc/systemd /lib/systemd /usr/lib/systemd /usr/lib/modules-load.d *udev* /usr/lib/tmpfiles.d *tmpfiles* /var/lib/dbus /usr/bin/gdbus /lib/udev"
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo Chat All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum