nova-shell/plugin/build.rs

37 lines
1.9 KiB
Rust

use cxx_qt_build::{CxxQtBuilder, PluginType, QmlModule};
fn main() {
// 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
// nothing internal references those symbols (moc emits them as dlsym
// entry points), so the linker drops them entirely. --undefined=<sym>
// anchors them past --gc-sections.
// 2. Rust's cdylib link passes an explicit --version-script that exports
// only Rust-public symbols - everything else, including our anchored C++
// plugin symbols, is hidden as local. Neither --export-dynamic nor
// --export-dynamic-symbol overrides an explicit version script. The fix
// 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"] {
println!("cargo:rustc-link-arg=-Wl,--undefined={sym}");
}
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
// 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.
let bridge_files = ["src/system_stats.rs", "src/cpu_service.rs"];
if !bridge_files.iter().all(|p| std::path::Path::new(p).exists()) {
return;
}
CxxQtBuilder::new_qml_module(QmlModule::new("NovaStats").plugin_type(PluginType::Dynamic))
.files(bridge_files)
.build();
}