Bug 416008

Summary: feature request: prepare kwin for unity build
Product: [Plasma] kwin Reporter: tom <a.pst>
Component: generalAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED NOT A BUG    
Severity: normal    
Priority: NOR    
Version First Reported In: 5.17.5   
Target Milestone: ---   
Platform: Chakra   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description tom 2020-01-08 16:36:06 UTC
salve

'single unit compilation' or 'unity build' or 'jumbo build' are a technique to reduce build time. 
how does unity build work, please read the explanation from the meson build system, this explanation is imo comfortable to read because its short and exact enough https://mesonbuild.com/Unity-builds.html
a propos meson build system, cmake 3.16 also support unity build https://cmake.org/cmake/help/v3.16/prop_tgt/UNITY_BUILD.html

as example how fast unity builds can be i compiled kactivities 5.65 with cmake:
#with set `-DCMAKE_UNITY_BUILD=TRUE`
real 66,03 - 68,91 - 68,93
user 92,77 - 98,05 - 68,93
sys 8,80 - 8,76 - 8,95```

#as normal build
real 128,53 - 125,27 - 129,16
user 219,17 - 215,70 - 219,40
sys 15,54 - 15,68 - 16,41

unfortunately i wasn't able to build kwin as unity build it breaks with error:

In file included from /usr/include/qt5/QtCore/qobject.h:54,
                 from /usr/include/qt5/QtWidgets/qwidget.h:45,
                 from /usr/include/qt5/QtWidgets/qdialog.h:44,
                 from /usr/include/qt5/QtWidgets/QDialog:1,
                 from /tmp/makepkg/kwin/src/kwin-5.17.5/kcmkwin/kwinrules/detectwidget.h:23,
                 from /tmp/makepkg/kwin/src/build/kcmkwin/kwinrules/kdeinit_kwin_rules_dialog_autogen/EWIEGA46WW/moc_detectwidget.cpp:10,
                 from /tmp/makepkg/kwin/src/build/kcmkwin/kwinrules/kdeinit_kwin_rules_dialog_autogen/mocs_compilation.cpp:2,
                 from /tmp/makepkg/kwin/src/build/kcmkwin/kwinrules/CMakeFiles/kdeinit_kwin_rules_dialog.dir/Unity/unity_0.cxx:3:
/tmp/makepkg/kwin/src/kwin-5.17.5/kcmkwin/kwinrules/ruleswidget.cpp:42:1: Fehler: Redefinition von »struct QMetaTypeId<NET::WindowType>«
 Q_DECLARE_METATYPE(NET::WindowType)
 ^~~~~~~~~~~~~~~~~~
/tmp/makepkg/kwin/src/kwin-5.17.5/kcmkwin/kwinrules/main.cpp:35:1: Anmerkung: vorherige Definition von »struct QMetaTypeId<NET::WindowType>«
 Q_DECLARE_METATYPE(NET::WindowType)
 ^~~~~~~~~~~~~~~~~~
In file included from /usr/include/qt5/QtCore/qobject.h:54,
                 from /usr/include/qt5/QtCore/QObject:1,
                 from /usr/include/KDecoration2/kdecoration2/decorationbutton.h:26,
                 from /usr/include/KDecoration2/KDecoration2/DecorationButton:1,
                 from /tmp/makepkg/kwin/src/kwin-5.17.5/kcmkwin/kwindecoration/declarative-plugin/buttonsmodel.h:23,
                 from /tmp/makepkg/kwin/src/build/kcmkwin/kwindecoration/kcm_kwindecoration_autogen/IEE35O66SJ/moc_buttonsmodel.cpp:10,
                 from /tmp/makepkg/kwin/src/build/kcmkwin/kwindecoration/kcm_kwindecoration_autogen/mocs_compilation.cpp:2,
                 from /tmp/makepkg/kwin/src/build/kcmkwin/kwindecoration/CMakeFiles/kcm_kwindecoration.dir/Unity/unity_0.cxx:3:
/tmp/makepkg/kwin/src/kwin-5.17.5/kcmkwin/kwindecoration/kcm.cpp:42:1: Fehler: Redefinition von »struct QMetaTypeId<KDecoration2::BorderSize>«
 Q_DECLARE_METATYPE(KDecoration2::BorderSize)
 ^~~~~~~~~~~~~~~~~~
/usr/include/KDecoration2/kdecoration2/decorationsettings.h:147:1: Anmerkung: vorherige Definition von »struct QMetaTypeId<KDecoration2::BorderSize>«
 Q_DECLARE_METATYPE(KDecoration2::BorderSize)
 ^~~~~~~~~~~~~~~~~~
/tmp/makepkg/kwin/src/kwin-5.17.5/kcmkwin/kwinrules/detectwidget.cpp:39:1: Fehler: Redefinition von »struct QMetaTypeId<NET::WindowType>«
 Q_DECLARE_METATYPE(NET::WindowType)
 ^~~~~~~~~~~~~~~~~~
/tmp/makepkg/kwin/src/kwin-5.17.5/kcmkwin/kwinrules/main.cpp:35:1: Anmerkung: vorherige Definition von »struct QMetaTypeId<NET::WindowType>«
 Q_DECLARE_METATYPE(NET::WindowType)
 ^~~~~~~~~~~~~~~~~~
make[2]: *** [kcmkwin/kwindecoration/CMakeFiles/kcm_kwindecoration.dir/build.make:63: kcmkwin/kwindecoration/CMakeFiles/kcm_kwindecoration.dir/Unity/unity_0.cxx.o] Fehler 1
make[1]: *** [CMakeFiles/Makefile2:4821: kcmkwin/kwindecoration/CMakeFiles/kcm_kwindecoration.dir/all] Fehler 2
make[1]: *** Es wird auf noch nicht beendete Prozesse gewartet....
make[2]: *** [kcmkwin/kwinrules/CMakeFiles/kdeinit_kwin_rules_dialog.dir/build.make:104: kcmkwin/kwinrules/CMakeFiles/kdeinit_kwin_rules_dialog.dir/Unity/unity_0.cxx.o] Fehler 1
make[1]: *** [CMakeFiles/Makefile2:4956: kcmkwin/kwinrules/CMakeFiles/kdeinit_kwin_rules_dialog.dir/all] Fehler 2
[ 35%] Built target kdecorationprivatedeclarative
make: *** [Makefile:130: all] Fehler 2

unfortunately again it will need some time to debug and review the code but the expected saved time is tremendous 

sincerely tom
Comment 1 Vlad Zahorodnii 2023-01-18 12:49:30 UTC
As far as I know, kde has no policy regarding unity builds. On the other hand, with the introduction of C++ modules, perhaps we don't need to care about unity builds, we're still miles away from using modules in our codebase though. Regardless, such things should be decided at kde level. Let's revisit if KDE's policies change.
Comment 2 tom 2023-01-31 16:31:43 UTC
(In reply to Vlad Zahorodnii from comment #1)
> As far as I know, kde has no policy regarding unity builds. On the other
> hand, with the introduction of C++ modules, perhaps we don't need to care
> about unity builds, we're still miles away from using modules in our
> codebase though. Regardless, such things should be decided at kde level.
> Let's revisit if KDE's policies change.

hi,

i don't know about C++ modules, but there is a short explanation what unity build is : https://mesonbuild.com/Unity-builds.html
unity build can shorten time to build massive, but i will need a code rewrite because it can handle only one definition per unit, so it's impossible to overload a identifier

cmake unity vuild:https://cmake.org/cmake/help/latest/variable/CMAKE_UNITY_BUILD.html