From fa861a4399b27a7b0d75272023e2cdd4dfcfd18f Mon Sep 17 00:00:00 2001 From: Damocles Date: Sun, 3 May 2026 23:27:20 +0200 Subject: [PATCH] plugin: workaround cxx-qt 0.8.1 dyn plugin not calling qml_register_types --- plugin/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugin/src/lib.rs b/plugin/src/lib.rs index 6c837e5..eca2e48 100644 --- a/plugin/src/lib.rs +++ b/plugin/src/lib.rs @@ -2,7 +2,21 @@ pub mod cpu_service; pub mod stats; pub mod system_stats; +// cxx-qt 0.8.1's PluginType::Dynamic emits a QQmlEngineExtensionPlugin whose +// constructor only anchors qml_register_types_NovaStats with `volatile auto X = &X` +// (linker-keep, not a call), and the qmltyperegistrar static init doesn't call it +// either. Net effect: types never register, NS.* stays undefined in QML. Workaround: +// call it ourselves at .so load time. The function is mangled (returns void, no +// extern "C"), so go through #[link_name] using the itanium-mangled symbol seen in +// `nm libNovaStats.so | grep qml_register_types`. +unsafe extern "C" { + #[link_name = "_Z28qml_register_types_NovaStatsv"] + fn qml_register_types_nova_stats(); +} + #[ctor::ctor(unsafe)] fn on_dylib_load() { eprintln!("[nova-plugin] dylib loaded (libNovaStats.so)"); + unsafe { qml_register_types_nova_stats() }; + eprintln!("[nova-plugin] qml_register_types_NovaStats called"); }