plugin: use --dynamic-list to add qt entry symbols past rust's version script
This commit is contained in:
parent
12c5f3283f
commit
d2708087be
2 changed files with 20 additions and 10 deletions
|
|
@ -1,21 +1,27 @@
|
||||||
use cxx_qt_build::{CxxQtBuilder, PluginType, QmlModule};
|
use cxx_qt_build::{CxxQtBuilder, PluginType, QmlModule};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Two separate problems to defeat in the cdylib link:
|
// Two separate problems to defeat in the cdylib link for cxx-qt's QML plugin
|
||||||
|
// entry points (qt_plugin_instance / qt_plugin_query_metadata_v2):
|
||||||
// 1. cc-rs uses -ffunction-sections, Rust's cdylib runs --gc-sections, and
|
// 1. cc-rs uses -ffunction-sections, Rust's cdylib runs --gc-sections, and
|
||||||
// nothing internal references qt_plugin_instance / qt_plugin_query_metadata_v2
|
// nothing internal references those symbols (moc emits them as dlsym
|
||||||
// (moc emits them as dlsym entry points for Qt's plugin loader, not for
|
// entry points), so the linker drops them entirely. --undefined=<sym>
|
||||||
// in-binary calls), so the linker drops them entirely. --undefined=<sym>
|
|
||||||
// anchors them past --gc-sections.
|
// anchors them past --gc-sections.
|
||||||
// 2. Even once present, Rust's cdylib link hides C++ static-archive symbols by
|
// 2. Rust's cdylib link passes an explicit --version-script that exports
|
||||||
// default - they end up as local (lowercase t in nm), invisible to dlsym.
|
// only Rust-public symbols - everything else, including our anchored C++
|
||||||
// --export-dynamic-symbol=<sym> doesn't help: that flag only applies to
|
// plugin symbols, is hidden as local. Neither --export-dynamic nor
|
||||||
// -shared=no (executables). For shared libraries, bare --export-dynamic
|
// --export-dynamic-symbol overrides an explicit version script. The fix
|
||||||
// exports all global symbols and overrides the hide-by-default.
|
// is --dynamic-list=<file>, which is additive: it appends entries to the
|
||||||
|
// dynamic symtab without fighting the version script's hides.
|
||||||
for sym in ["qt_plugin_instance", "qt_plugin_query_metadata_v2"] {
|
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,--undefined={sym}");
|
||||||
}
|
}
|
||||||
println!("cargo:rustc-link-arg=-Wl,--export-dynamic");
|
let dynlist = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("qt_plugin_exports.txt");
|
||||||
|
println!("cargo:rerun-if-changed={}", dynlist.display());
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-arg=-Wl,--dynamic-list={}",
|
||||||
|
dynlist.display()
|
||||||
|
);
|
||||||
|
|
||||||
// Crane's deps-only build stubs out lib.rs and removes our bridge sources to
|
// 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
|
// build a dummy crate that only compiles dependencies. Skip cxx-qt codegen in
|
||||||
|
|
|
||||||
4
plugin/qt_plugin_exports.txt
Normal file
4
plugin/qt_plugin_exports.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
qt_plugin_instance;
|
||||||
|
qt_plugin_query_metadata_v2;
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue