plugin: export Qt plugin entry symbols from cdylib via --export-dynamic
This commit is contained in:
parent
dad977d4c5
commit
2a691aa66f
2 changed files with 7 additions and 12 deletions
|
|
@ -1,6 +1,13 @@
|
||||||
use cxx_qt_build::{CxxQtBuilder, PluginType, QmlModule};
|
use cxx_qt_build::{CxxQtBuilder, PluginType, QmlModule};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
// Rust cdylib uses a version script that hides everything not declared
|
||||||
|
// `#[no_mangle] pub extern "C"`. cxx-qt's QQmlEngineExtensionPlugin entry
|
||||||
|
// points (qt_plugin_instance, qt_plugin_query_metadata_v2) come from
|
||||||
|
// compiled C++ and would otherwise be stripped to local visibility, so Qt's
|
||||||
|
// plugin loader finds nothing exported. --export-dynamic re-exposes them.
|
||||||
|
println!("cargo:rustc-link-arg=-Wl,--export-dynamic");
|
||||||
|
|
||||||
CxxQtBuilder::new_qml_module(QmlModule::new("NovaStats").plugin_type(PluginType::Dynamic))
|
CxxQtBuilder::new_qml_module(QmlModule::new("NovaStats").plugin_type(PluginType::Dynamic))
|
||||||
.files(["src/system_stats.rs", "src/cpu_service.rs"])
|
.files(["src/system_stats.rs", "src/cpu_service.rs"])
|
||||||
.build();
|
.build();
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,7 @@ pub mod cpu_service;
|
||||||
pub mod stats;
|
pub mod stats;
|
||||||
pub mod system_stats;
|
pub mod system_stats;
|
||||||
|
|
||||||
// cxx-qt-build emits a QQmlEngineExtensionPlugin C++ class with Q_PLUGIN_METADATA
|
|
||||||
// alongside an `init_cxx_qt_qml_module_<name>_plugin()` symbol whose only purpose is
|
|
||||||
// to anchor that translation unit. Without referencing it from Rust, the linker
|
|
||||||
// drops the .o containing the plugin class - Qt then dlopens the .so, finds no
|
|
||||||
// plugin metadata, and never calls qml_register_types_NovaStats.
|
|
||||||
unsafe extern "C" {
|
|
||||||
fn init_cxx_qt_qml_module_NovaStats_plugin() -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[ctor::ctor(unsafe)]
|
#[ctor::ctor(unsafe)]
|
||||||
fn on_dylib_load() {
|
fn on_dylib_load() {
|
||||||
eprintln!("[nova-plugin] dylib loaded (libNovaStats.so)");
|
eprintln!("[nova-plugin] dylib loaded (libNovaStats.so)");
|
||||||
unsafe {
|
|
||||||
init_cxx_qt_qml_module_NovaStats_plugin();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue