-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support soname for cdylibs #5045
Comments
I'm interested for the same reason of @kornelski to be able to cross-compile rust libs on gentoo. |
The lack of support for linker flags is one of issues preventing librsvg from switching to Cargo. It needs flags like this:
|
Those are all libtool flags and not direct linker flags that |
Ah, ok. Still needs a post build script or something, since the vanilla cdylib crate type doesn't have it. |
@kornelski I'm updating my patch, then we can work on the installing phase together if you like :) I need it already for crav1e and the relibc developer seem interested as well. |
Add cargo:rustc-link-arg to pass custom linker arguments It is useful to produce correct `cdylibs` on platforms such as Linux and MacOS. Groundwork to address #5045 in the future.
From #6298, am I correct in understanding that the remaining work is to figure out platform-specific linker arguments to define the soname and such? |
The install phase rfc and this have more details on what is missing. I might take this weekend to publish my draft applet so we can experiment a bit outside cargo if you want to join me in this :) |
But this is about For example, |
What I'm preparing is something along the lines of:
No pollution at all :) |
But isn't that a workaround? It reminds me of ugly hacks like |
It is not. As a packager I enjoy having a working install target that gets all I need in the right places without having to reinvent the wheel every time. Nobody is forcing you to use what I'm writing :) |
Oh, you mean you're writing " |
yes, I try to make an applet to generate all that's needed (.pc files, .h files, etc) and install it without to have to repeat myself too much (currently we are having a small vlc workshop so I might or might not get to publish it this weekend) |
Now I have two ways to help on this:
Ideally I could make a separate crate for the |
new to rust/cargo: would there be a possibility to write a plugin that does set the soname as post-production step? (yes, it is a workaround until mainline can do it). Right now I try to do the same on the side consuming the .so |
it is, you may using cdylib-link-lines (even if it could enjoy an overhaul). |
I am facing exactly this issue when trying to use Rust-based libraries (i.e. I used the two Rust-based WebAssembly engines Wasmtime and Wasmer) in a C/C++ code-base. These Rust libraries have no SONAMES, which causes the CMake build to produce wrong binaries. I opened an issue at CMake, but these folks clearly confirmed that shared libraries without an SONAME entry are a bug that needs to be fixed by the one building the library: Could you please continue working on this topic? Otherwise consuming Rust-based libraries with the popular CMake build system will remain awkward. |
See wasmerio#2429 for more context. I'm copy-pasting the original comment from @MartinKolbAtWork here: > The shared library `libwasmer.so` does not have an `SONAME` > specified. This can be checked using this command: `objdump -p > libwasmer.so | grep SONAME` > > When `libwasmer.so` is consumed in CMake, the **linker produces a > wrong output file due to the missing SONAME**. There is a > workaround for this in CMake, but according to a reply from the > CMake folks, the missing SONAME is a bug that must be fixed by the > library provider: > https://gitlab.kitware.com/cmake/cmake/-/issues/22307#note_971562 > “_The libwasmer.so file should have a SONAME. If it doesn't, that's > a bug in the wasmer package_” > > The problem is **inherent for all Rust builds of cdylibs**: > rust-lang/cargo#5045 The Rust community > did not fix this since 2018 (see issue above), but fortunately it’s > **easy to fix** for library creators. You just need to put the > following code into the `build.rs` of the library: > > ``` > if cfg!(target_os = "linux") { > println!("cargo:rustc-cdylib-link-arg=-Wl,-soname,libwasmer.so"); > } > ``` > > I tried putting these lines into `lib/c-api/build.rs`, and then > `libwasmer.so` was built correctly, including a SONAME entry.
See wasmerio#2429 for more context. I'm copy-pasting the original comment from @MartinKolbAtWork here: > The shared library `libwasmer.so` does not have an `SONAME` > specified. This can be checked using this command: `objdump -p > libwasmer.so | grep SONAME` > > When `libwasmer.so` is consumed in CMake, the **linker produces a > wrong output file due to the missing SONAME**. There is a > workaround for this in CMake, but according to a reply from the > CMake folks, the missing SONAME is a bug that must be fixed by the > library provider: > https://gitlab.kitware.com/cmake/cmake/-/issues/22307#note_971562 > “_The libwasmer.so file should have a SONAME. If it doesn't, that's > a bug in the wasmer package_” > > The problem is **inherent for all Rust builds of cdylibs**: > rust-lang/cargo#5045 The Rust community > did not fix this since 2018 (see issue above), but fortunately it’s > **easy to fix** for library creators. You just need to put the > following code into the `build.rs` of the library: > > ``` > if cfg!(target_os = "linux") { > println!("cargo:rustc-cdylib-link-arg=-Wl,-soname,libwasmer.so"); > } > ``` > > I tried putting these lines into `lib/c-api/build.rs`, and then > `libwasmer.so` was built correctly, including a SONAME entry.
Ideally you might get around setting the For android you shouldn't have problems not using cargo-c for it. |
Out of curious. What's the missing part to make progress on this issue? From my understanding,
Sorry I am a bit lost on this thread… |
For me, it's this part from the opening post (emphasis mine):
So what's missing from my point of view is a decision if cargo could automatically set the soname for |
Another argument for having Cargo set the DT_SONAME: Only Cargo knows The gist of it is that one library that is built as a (This is not a contrived usecase but based on a real world product that |
Previously, without fix on SONAME[1], when installing rpm generated by `make rpm`, Fedora will complains: error: Failed dependencies: libnmstate.so()(64bit) is needed by nmstate-devel To fix the issue, we updated the nmstate.spec.in to hold: * Both Fedora and RHEL specific lines * Both official release and snapshot build(snapshot will use internet for crates.io access) Tested on CentOS stream 9, Fedora 38 and Fedora Rawhide(40). [1]: rust-lang/cargo#5045 Signed-off-by: Gris Ge <fge@redhat.com>
Previously, without fix on SONAME[1], when installing rpm generated by `make rpm`, Fedora will complains: error: Failed dependencies: libnmstate.so()(64bit) is needed by nmstate-devel To fix the issue, we updated the nmstate.spec.in to hold: * Both Fedora and RHEL specific lines * Both official release and snapshot build(snapshot will use internet for crates.io access) Tested on CentOS stream 9, Fedora 38 and Fedora Rawhide(40). Resolves: RHEL-5002 [1]: rust-lang/cargo#5045 Signed-off-by: Gris Ge <fge@redhat.com>
Previously, without fix on SONAME[1], when installing rpm generated by `make rpm`, Fedora will complains: error: Failed dependencies: libnmstate.so()(64bit) is needed by nmstate-devel To fix the issue, we updated the nmstate.spec.in to hold: * Both Fedora and RHEL specific lines * Both official release and snapshot build(snapshot will use internet for crates.io access) Tested on CentOS stream 9, Fedora 38 and Fedora Rawhide(40). Resolves: RHEL-5002 [1]: rust-lang/cargo#5045 Signed-off-by: Gris Ge <fge@redhat.com>
Previously, without fix on SONAME[1], when installing rpm generated by `make rpm`, Fedora will complains: error: Failed dependencies: libnmstate.so()(64bit) is needed by nmstate-devel To fix the issue, we updated the nmstate.spec.in to hold: * Both Fedora and RHEL specific lines * Both official release and snapshot build(snapshot will use internet for crates.io access) Tested on CentOS stream 9, Fedora 38 and Fedora Rawhide(40). Also removed copr build for RHEL/CentOS 8 due to no usage. Resolves: RHEL-5002 [1]: rust-lang/cargo#5045 Signed-off-by: Gris Ge <fge@redhat.com>
Previously, without fix on SONAME[1], when installing rpm generated by `make rpm`, Fedora will complains: error: Failed dependencies: libnmstate.so()(64bit) is needed by nmstate-devel To fix the issue, we updated the nmstate.spec.in to hold: * Both Fedora and RHEL specific lines * Both official release and snapshot build(snapshot will use internet for crates.io access) Tested on CentOS stream 9, Fedora 38 and Fedora Rawhide(40). Also removed copr build for RHEL/CentOS 8 due to no usage. Resolves: RHEL-5002 [1]: rust-lang/cargo#5045 Signed-off-by: Gris Ge <fge@redhat.com>
Previously, without fix on SONAME[1], when installing rpm generated by `make rpm`, Fedora will complains: error: Failed dependencies: libnmstate.so()(64bit) is needed by nmstate-devel To fix the issue, we updated the nmstate.spec.in to hold: * Both Fedora and RHEL specific lines * Both official release and snapshot build(snapshot will use internet for crates.io access) Tested on CentOS stream 9, Fedora 38 and Fedora Rawhide(40). Also removed copr build for RHEL/CentOS 8 due to no usage. Resolves: RHEL-5002 [1]: rust-lang/cargo#5045 Signed-off-by: Gris Ge <fge@redhat.com>
Previously, without fix on SONAME[1], when installing rpm generated by `make rpm`, Fedora will complains: error: Failed dependencies: libnmstate.so()(64bit) is needed by nmstate-devel To fix the issue, we updated the nmstate.spec.in to hold: * Both Fedora and RHEL specific lines * Both official release and snapshot build(snapshot will use internet for crates.io access) Tested on CentOS stream 9, Fedora 38 and Fedora Rawhide(40). Also removed copr build for RHEL/CentOS 8 due to no usage. Resolves: RHEL-5002 [1]: rust-lang/cargo#5045 Signed-off-by: Gris Ge <fge@redhat.com>
rustc
supports settingsoname
via-C link-arg
. However, it can't be used from Cargo, sinceRUSTFLAGS
affects all invocations of the compiler, and it could potentially setsoname
on dependencies.Some previous discussions about
soname
support were dismissed based on the fact that Rust's native ABI is not stable. That is not relevant for cdylibs, because the C ABI exposed by cdylibs is stable.I'm interested in using this feature in
cargo-deb
.soname
is required to build first-class Linux libraries (e.g. for Debian) with Rust.I think it'd be wonderful if Cargo automatically set
soname
ofcdylib
to semver-major when version is >= 1.0.0 (i.e. don't set any for 0.x.x), since soname and semver-major promise basically the same thing. However, a separate Cargo.toml field, command line flag, or env var would work as well.The text was updated successfully, but these errors were encountered: