Fix clib SONAME

Resolves: RHEL-32218

Signed-off-by: Gris Ge <fge@redhat.com>
This commit is contained in:
Gris Ge 2024-05-17 15:51:53 +08:00
parent e264db009a
commit 69503b6dd6
2 changed files with 65 additions and 10 deletions

View File

@ -0,0 +1,60 @@
From 0b530d4c8e75f60015d13c225b1c634389fbe798 Mon Sep 17 00:00:00 2001
From: Gris Ge <fge@redhat.com>
Date: Fri, 17 May 2024 13:12:14 +0800
Subject: [PATCH] clib: Use build.rs to fix SONAME
Use [`cargo:rustc-cdylib-link-arg`][1] to `build.rs` to fix the SONAME issue
of cargo.
Removed workarounds in rpm spec and `.cargo/config.toml`.
Changed Makefile to place `-lnmstate` after the source file to fix
compile issue on ubuntu 20.04 old gcc.
[1]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-cdylib-link-arg
Signed-off-by: Gris Ge <fge@redhat.com>
---
rust/.cargo/config.toml | 3 ---
rust/src/clib/Cargo.toml | 1 +
rust/src/clib/build.rs | 6 ++++++
3 files changed, 7 insertions(+), 3 deletions(-)
create mode 100644 rust/src/clib/build.rs
diff --git a/rust/.cargo/config.toml b/rust/.cargo/config.toml
index 018e59d4..ca6c72f7 100644
--- a/rust/.cargo/config.toml
+++ b/rust/.cargo/config.toml
@@ -1,5 +1,2 @@
-[build]
-rustflags = "-Clink-arg=-Wl,-soname=libnmstate.so.1"
-
[target.x86_64-unknown-linux-gnu]
runner = 'sudo -E'
diff --git a/rust/src/clib/Cargo.toml b/rust/src/clib/Cargo.toml
index 462757ca..0eb00922 100644
--- a/rust/src/clib/Cargo.toml
+++ b/rust/src/clib/Cargo.toml
@@ -6,6 +6,7 @@ authors = ["Gris Ge <fge@redhat.com>"]
license = "Apache-2.0"
edition = "2018"
rust-version = "1.58"
+build = "build.rs"
[lib]
name = "nmstate"
diff --git a/rust/src/clib/build.rs b/rust/src/clib/build.rs
new file mode 100644
index 00000000..74ad7e48
--- /dev/null
+++ b/rust/src/clib/build.rs
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: Apache-2.0
+
+fn main() {
+ #[cfg(target_os = "linux")]
+ println!("cargo:rustc-cdylib-link-arg=-Wl,-soname=libnmstate.so.1");
+}
--
2.45.1

View File

@ -4,7 +4,7 @@
Name: nmstate Name: nmstate
Version: 1.4.6 Version: 1.4.6
Release: 1%{?dist} Release: 2%{?dist}
Summary: Declarative network manager API Summary: Declarative network manager API
License: LGPLv2+ License: LGPLv2+
URL: https://github.com/%{srcname}/%{srcname} URL: https://github.com/%{srcname}/%{srcname}
@ -14,6 +14,7 @@ Source2: https://www.nmstate.io/nmstate.gpg
Source3: %{url}/releases/download/v%{version}/%{srcname}-vendor-%{version}.tar.xz Source3: %{url}/releases/download/v%{version}/%{srcname}-vendor-%{version}.tar.xz
# Patches 0X are reserved to downstream only # Patches 0X are reserved to downstream only
Patch0: BZ_2132570-nm-reverse-IPv6-order-before-adding-them-to-setting.patch Patch0: BZ_2132570-nm-reverse-IPv6-order-before-adding-them-to-setting.patch
Patch10: 0001-clib-Use-build.rs-to-fix-SONAME.patch
BuildRequires: python3-devel BuildRequires: python3-devel
BuildRequires: python3-setuptools BuildRequires: python3-setuptools
BuildRequires: gnupg2 BuildRequires: gnupg2
@ -83,15 +84,6 @@ gpgv2 --keyring ./gpgkey-mantainers.gpg %{SOURCE1} %{SOURCE0}
pushd rust pushd rust
# Source3 is vendored dependencies # Source3 is vendored dependencies
%cargo_prep -V 3 %cargo_prep -V 3
# The cargo_prep will create `.cargo/config` which take precedence over
# `.cargo/config.toml` shipped by upstream which fix the SONAME of cdylib.
# To workaround that, merge upstream rustflags into cargo_prep created one.
_FLAGS=`sed -ne 's/rustflags = "\(.\+\)"/\1/p' .cargo/config.toml`
sed -i -e "s/rustflags = \[\(.\+\), \]$/rustflags = [\1, \"$_FLAGS\"]/" \
.cargo/config
rm .cargo/config.toml
popd popd
%build %build
@ -150,6 +142,9 @@ popd
/sbin/ldconfig /sbin/ldconfig
%changelog %changelog
* Fri May 17 2024 Gris Ge <fge@redhat.com> - 1.4.6-2
- Fix clib SONAME. RHEL-32218
* Thu May 16 2024 Gris Ge <fge@redhat.com> - 1.4.6-1 * Thu May 16 2024 Gris Ge <fge@redhat.com> - 1.4.6-1
- Do not touch interface DNS if global DNS is used. RHEL-32218 - Do not touch interface DNS if global DNS is used. RHEL-32218