plugin: anchor qt_plugin entry symbols past --gc-sections so qt finds them

This commit is contained in:
Damocles 2026-05-03 21:08:19 +02:00
parent bf5cb913fc
commit d47200932d

View file

@ -1,12 +1,17 @@
use cxx_qt_build::{CxxQtBuilder, PluginType, QmlModule};
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");
// cc-rs compiles with -ffunction-sections, Rust's cdylib link runs --gc-sections,
// and nothing internal references qt_plugin_instance/qt_plugin_query_metadata_v2
// - moc generates them as Qt's plugin entry points for dlopen, not for in-binary
// calls. So the linker drops them entirely (verified: `nm libNovaStats.so | grep
// qt_plugin_instance` returns nothing, only the static const inside the dropped
// function survives). --undefined anchors them past --gc-sections, then
// --export-dynamic-symbol exposes them for Qt's dlsym lookup.
for sym in ["qt_plugin_instance", "qt_plugin_query_metadata_v2"] {
println!("cargo:rustc-link-arg=-Wl,--undefined={sym}");
println!("cargo:rustc-link-arg=-Wl,--export-dynamic-symbol={sym}");
}
// 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