# plasma-desktop 6.7.2 — provee el SHELL org.kde.plasma.desktop (corona/containment de escritorio) +
# los KCM del System Settings + kcminit. Es lo que separa "plasmashell corre" de "escritorio prende":
# sin él plasmashell reporta `starting invalid corona "org.kde.plasma.desktop"`. Patrón KF6 (dynamic,
# wrapper zig filtra -Wl,--fatal-warnings, Ninja, rm -rf po, WITH_X11=OFF Wayland-puro).
name    = "plasma-desktop"
version = "6.7.2"
license = "GPL-2.0-or-later"

[source]
tarball = "https://download.kde.org/stable/plasma/6.7.2/plasma-desktop-6.7.2.tar.xz"
sha256  = "6d1a0d5970b553329d26268f9eb3c84aa83358238afcfc2f8691147046569831"

[build]
compiler = "zig-cc"
target   = "x86_64-linux-musl"
link     = "dynamic"
flags    = []

[build.phases]
configure = '''
rm -rf po
# NetworkManagerQt REQUIRED → glib rabbit-hole (como plasma-workspace); DocTools → docs. A opcional.
sed -i 's/find_package(KF6NetworkManagerQt \([^)]*\)REQUIRED)/find_package(KF6NetworkManagerQt \1)/' CMakeLists.txt
sed -i 's/find_package(KF6NetworkManagerQt REQUIRED)/find_package(KF6NetworkManagerQt)/' CMakeLists.txt
# KF6DocTools: find_package (línea 104) ya es opcional; el bloqueo es su set_package_properties TYPE
# REQUIRED (feature_summary aborta). A OPTIONAL (docs, no runtime; kdoctools_install(po) ya está gated).
sed -i '/set_package_properties(KF6DocTools/,/)/ s/TYPE REQUIRED/TYPE OPTIONAL/' CMakeLists.txt
# doc/ construye handbooks con kdoctools_create_handbook (KF6DocTools, ahora opcional/ausente) y no está
# bien gated ⇒ falla. Docs no hacen falta para el shell. Removemos el subdir doc.
sed -i '/add_subdirectory(doc)/d' CMakeLists.txt
sed -i '/kdoctools_install(po)/d' CMakeLists.txt
# kaccess (daemon accesibilidad) incluye un header generado por el KCM access (subdir kcms removido) ⇒
# 'kcmaccessibilityactivationgestures.h' file not found. No hace falta para el shell. Removemos.
sed -i '/add_subdirectory(kaccess)/d' CMakeLists.txt
# runners/keys usa filteredmodel.h (generado por el KCM teclado removido). Los runners son plugins
# krunner opcionales, no el shell. Removemos el subdir.
sed -i '/add_subdirectory(runners)/d' CMakeLists.txt
# imports/activitymanager provee el módulo QML org.kde.plasma.activityswitcher que Desktop.qml del shell
# IMPORTA (sin él, el desktop no carga). switcherbackend.cpp incluye xwindowtasksmodel.h (X11), ausente en
# plasma-workspace wayland-puro; y HAVE_X11 queda =1 (detecta las libs X11 de deps) pese a WITH_X11=OFF, así
# que el guard #if HAVE_X11 no basta. Solución: borrar el include X11 y reemplazar sus usos por
# WaylandTasksModel (que SÍ está y ya se usa en la rama wayland) — el drag-drop de ventanas anda igual.
sed -i '\|#include <xwindowtasksmodel.h>|d' imports/activitymanager/switcherbackend.cpp
sed -i 's/#if HAVE_X11/#if 0/g' imports/activitymanager/switcherbackend.cpp
# applet pager: único que usa xwindowtasksmodel.h (X11, ausente en plasma-workspace wayland-puro; los
# applets esenciales taskmanager/kickoff usan el genérico windowtasksmodel.h que SÍ está). Podamos pager.
sed -i '/add_subdirectory(pager)/d' applets/CMakeLists.txt
# libwacom (tableta gráfica) REQUIRED → hardware opcional, sin receta. Quitar REQUIRED del
# pkg_check_modules del top-level CMakeLists (busybox grep del sandbox NO soporta --include, por eso
# un grep -rl fallaba silenciosamente; sed directo sobre el fichero conocido).
sed -i '/pkg_check_modules(LIBWACOM/ s/ REQUIRED//' CMakeLists.txt
# KSMServerDBusInterface: mi plasma-workspace es wayland-puro (sin ksmserver, deprecado en Wayland) ⇒ no
# provee ese cmake config. Su consumidor es el KCM de logout (subdir kcms, ya removido). A opcional.
sed -i '/find_package(KSMServerDBusInterface/ s/ REQUIRED//' CMakeLists.txt
# xkbregistry REQUIRED (lo consume el KCM de teclado, subdir kcms ya removido). A opcional.
sed -i '/pkg_check_modules(XKBREGISTRY/ s/ REQUIRED//' CMakeLists.txt
# El SHELL (org.kde.plasma.desktop) + containments + applets es lo que plasmashell necesita para la
# corona; los KCMs (System Settings: kaccounts/wacom/touchpad/… con su infierno de deps opcionales)
# NO. Desactivamos el subdir kcms para saltear ese tail de REQUIREDs (kaccounts6, libwacom, ibus, …).
sed -i '/add_subdirectory(kcms)/d' CMakeLists.txt
ZW="$PWD/.zwrap"; mkdir -p "$ZW"
cat > "$ZW/cc"  <<'W'
#!/bin/sh
a=""; for x in "$@"; do [ "$x" = "-Wl,--fatal-warnings" ] && continue; a="$a $x"; done
exec /opt/zig/zig cc -mcpu=baseline $a
W
cat > "$ZW/cxx" <<'W'
#!/bin/sh
a=""; for x in "$@"; do [ "$x" = "-Wl,--fatal-warnings" ] && continue; a="$a $x"; done
exec /opt/zig/zig c++ -mcpu=baseline $a
W
chmod +x "$ZW/cc" "$ZW/cxx"
PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/share/pkgconfig \
cmake -B build -G Ninja -Wno-dev \
  -DCMAKE_C_COMPILER="$ZW/cc" -DCMAKE_CXX_COMPILER="$ZW/cxx" -DCMAKE_ASM_COMPILER="$ZW/cc" \
  -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_PREFIX_PATH=/usr \
  -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \
  -DBUILD_TESTING=OFF \
  -DWITH_X11=OFF
'''
compile = "cmake --build build"
install = "DESTDIR=/out cmake --install build"

[deps]
build = ["cmake", "samurai", "python3", "pkgconf", "qtbase", "qtdeclarative", "qtsvg", "qtshadertools",
  "qtwayland", "qttools", "dbus", "extra-cmake-modules", "gettext-tiny",
  "mesa", "libdrm", "libxkbcommon", "wayland", "wayland-protocols", "plasma-wayland-protocols",
  "kded", "krunner", "ktexteditor", "prison",
  "plasma-activities-stats", "libksysguard", "libkscreen",
  "layer-shell-qt", "kscreenlocker",
  "karchive", "kauth", "kcoreaddons", "kcrash", "kdbusaddons", "kdeclarative", "kglobalaccel",
  "kguiaddons", "kholidays", "ki18n", "kiconthemes", "kidletime", "kitemmodels", "kcmutils",
  "kio", "knewstuff", "knotifications", "kpackage", "kparts", "ksvg", "ktextwidgets", "kwallet",
  "kcolorscheme",
  "libplasma", "kwayland", "plasma-activities", "knighttime", "kwin", "kirigami", "plasma5support",
  "qqc2-desktop-style",
  # plasma-workspace provee LibKLookAndFeel/LibKWorkspace/LibTaskManager/LibNotificationManager +
  # KRunnerAppDBusInterface/KSMServerDBusInterface (todos CONFIG REQUIRED en plasma-desktop):
  "plasma-workspace",
  "kconfig", "kconfigwidgets", "kcodecs", "kcompletion", "kwidgetsaddons", "kitemviews",
  "kxmlgui", "syntax-highlighting", "qtspeech", "qtmultimedia", "qt5compat", "knotifyconfig",
  "sonnet", "kjobwidgets", "kbookmarks", "kservice", "attica", "solid", "kdnssd",
  "kfilemetadata", "kwindowsystem", "kglobalacceld", "kdecoration", "kplotting",
  "qtpositioning", "kholidays",
  "libgcrypt", "libgpg-error", "openssl", "util-linux", "zlib", "zstd",
  "libX11", "xorgproto", "libXau", "libXdmcp", "libXext", "libXrender", "libXfixes", "libXi",
  "libxcb", "xcb-util", "xcb-util-cursor", "xcb-util-keysyms", "xcb-util-wm",
  "xcb-util-image", "xcb-util-renderutil",
  "libudev-zero", "pixman", "lcms2", "fontconfig", "freetype", "libcanberra", "xkeyboard-config"]
