From 12c5f3283f82fe3634c6755d9d50427fe9e28967 Mon Sep 17 00:00:00 2001 From: Damocles Date: Sun, 3 May 2026 22:39:50 +0200 Subject: [PATCH] plugin: use bare --export-dynamic to expose qt_plugin syms (per-sym form is exec-only) --- plugin/build.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/plugin/build.rs b/plugin/build.rs index 6188563..f04019c 100644 --- a/plugin/build.rs +++ b/plugin/build.rs @@ -1,17 +1,21 @@ use cxx_qt_build::{CxxQtBuilder, PluginType, QmlModule}; fn main() { - // 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. + // Two separate problems to defeat in the cdylib link: + // 1. cc-rs uses -ffunction-sections, Rust's cdylib runs --gc-sections, and + // nothing internal references qt_plugin_instance / qt_plugin_query_metadata_v2 + // (moc emits them as dlsym entry points for Qt's plugin loader, not for + // in-binary calls), so the linker drops them entirely. --undefined= + // anchors them past --gc-sections. + // 2. Even once present, Rust's cdylib link hides C++ static-archive symbols by + // default - they end up as local (lowercase t in nm), invisible to dlsym. + // --export-dynamic-symbol= doesn't help: that flag only applies to + // -shared=no (executables). For shared libraries, bare --export-dynamic + // exports all global symbols and overrides the hide-by-default. 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}"); } + println!("cargo:rustc-link-arg=-Wl,--export-dynamic"); // 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