plugin: give moc qtdeclarative include path so QML attrs reach qmltyperegistrar

This commit is contained in:
Damocles 2026-05-04 00:55:42 +02:00
parent 78abe800ed
commit 1b07787764
3 changed files with 17 additions and 28 deletions

View file

@ -26,17 +26,9 @@ fn main() {
// Crane's deps-only build stubs out lib.rs and removes our bridge sources to
// build a dummy crate that only compiles dependencies. Skip cxx-qt codegen in
// that case - we just want cxx-qt-lib (the heavy dep) cached, not our own glue.
// Use CARGO_MANIFEST_DIR for a robust path that doesn't depend on cargo's CWD.
let manifest = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
let bridge_files = ["src/system_stats.rs", "src/cpu_service.rs"];
let present: Vec<bool> = bridge_files
.iter()
.map(|p| manifest.join(p).exists())
.collect();
println!("cargo:warning=build.rs manifest_dir={}", manifest.display());
println!("cargo:warning=build.rs bridge_files present: {present:?}");
if !present.iter().all(|b| *b) {
println!("cargo:warning=build.rs bailing: bridge files missing (deps-only build?)");
if !bridge_files.iter().all(|p| manifest.join(p).exists()) {
return;
}

View file

@ -2,21 +2,7 @@ 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");
}