From 2cc34df784a2c1b67fdd6fbae8cbf0dfbbcd0a2b Mon Sep 17 00:00:00 2001 From: Gris Ge Date: Jan 18 2024 00:46:32 +0000 Subject: rust: Add document on how to set SONAME for c library written in Rust There are many ways to set SONAME for rust C library, some of them requires you to modify `RUSTFLAGS` which is not suggested by Fedora rust packaging tools. Including suggestions for this use case which works with Fedora rust packaging tools. Signed-off-by: Gris Ge --- diff --git a/guidelines/modules/ROOT/pages/Rust.adoc b/guidelines/modules/ROOT/pages/Rust.adoc index 9a88e40..2aca701 100644 --- a/guidelines/modules/ROOT/pages/Rust.adoc +++ b/guidelines/modules/ROOT/pages/Rust.adoc @@ -819,6 +819,31 @@ that apply to the statically linked Python extension. The packager also *MUST* ensure that the default link:#_compiler_flags[compiler flags] are passed to rustc. +== Exposing C library written in Rust + +When exposing C library written in Rust through `cdylib` crate type, +due to https://github.com/rust-lang/cargo/issues/5045[a bug of cargo], +your C library will not have `SONAME` defined which will cause rpm build tools +setting the rpm dependency incorrectly. + +To workaround that, you could use +https://doc.rust-lang.org/cargo/reference/build-scripts.html[`build.rs`] with +content of + +.... +fn main() { + #[cfg(target_os = "linux")] + println!("cargo:rustc-cdylib-link-arg=-Wl,-soname=libabc.so.1"); +} +.... + +If you prefer doing it in downstream, you may use `patchelf` to fix the +`SONAME` during rpm packaging: + +.... +patchelf --set-soname libabc.so.1 %{buildroot}/%{_libdir}/libabc.so.%{version} +.... + == Mixed Rust / C/C++ projects Handling of projects that include both C/C++ and Rust code