Skip to content

Commit 88218c8

Browse files
committed
prep: Fix libdnf-sys linking and add workspace lints
Fix static library linking order in libdnf-sys build script. The C++ wrapper (libdnfcxx.a) depends on both libdnf and glib, but cargo's link order requires dependencies to come after dependents. Re-emit link directives after compiling the wrapper to ensure symbols are available. This was causing undefined reference errors for g_strndup, g_free, and hy_split_nevra when building tests. Also add workspace-level lints to Cargo.toml and minor Rust cleanups. Assisted-by: Claude Code (Sonnet 4.5) Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 5e46090 commit 88218c8

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/libdnf-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ cmake = "0.1.54"
1818
system-deps = "7.0"
1919
anyhow = "1.0"
2020
cxx-build = "1.0.158"
21+
pkg-config = "0.3"
2122

2223
# This currently needs to duplicate the libraries from libdnf
2324
[package.metadata.system-deps]

rust/libdnf-sys/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ fn main() -> Result<()> {
77
let with_zck: u8 = libs.get_by_name("zck").is_some().into();
88
let with_rhsm = std::env::var_os("CARGO_FEATURE_RHSM").is_some();
99

10+
// Query pkg-config for glib's full link flags (including transitive dependencies)
11+
// We'll need this later to ensure proper linking of the C++ wrapper.
12+
let glib_libs = pkg_config::Config::new().probe("glib-2.0")?;
13+
1014
// first, the submodule proper
1115
let libdnf = cmake::Config::new("../../libdnf")
1216
// Needed for hardened builds
@@ -61,5 +65,19 @@ fn main() -> Result<()> {
6165
libdnfcxx.includes(libs.all_include_paths());
6266
libdnfcxx.compile("libdnfcxx.a");
6367

68+
// The C++ wrapper (libdnfcxx.a) uses both glib functions (g_strndup, g_free)
69+
// and libdnf functions (hy_split_nevra). Due to static library linking order,
70+
// we need to ensure these libraries come after libdnfcxx in the link order.
71+
// Even though system_deps already emitted link directives earlier, cargo's
72+
// link order matters - we re-emit them here to ensure symbols are available.
73+
74+
// First, link libdnf again (for hy_split_nevra and other libdnf symbols)
75+
println!("cargo:rustc-link-lib=static=dnf");
76+
77+
// Then, link glib and all its transitive dependencies (for g_strndup, g_free, etc.)
78+
for lib in &glib_libs.libs {
79+
println!("cargo:rustc-link-lib={}", lib);
80+
}
81+
6482
Ok(())
6583
}

rust/src/builtins/apply_live.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//!
21
// SPDX-License-Identifier: LGPL-2.1-or-later
32

43
use crate::cxxrsutil::*;

rust/src/importer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl RpmImporter {
221221
}
222222

223223
pub fn rpmfi_overrides_contains(self: &RpmImporter, path: &str) -> bool {
224-
self.rpmfi_overrides.get(path).is_some()
224+
self.rpmfi_overrides.contains_key(path)
225225
}
226226

227227
pub fn rpmfi_overrides_get(&self, path: &str) -> u64 {

0 commit comments

Comments
 (0)