cc-rs icon indicating copy to clipboard operation
cc-rs copied to clipboard

Support some method of determining if a symbol is available in dynamic libraries

Open ericonr opened this issue 5 years ago • 1 comments

Hi!

As it stands, most -sys crates, together with even libc, can't query if an external library contains a certain symbol or not. This makes it so these crates target a specific version of a library, instead of being able to adapt to changes in such libraries (for example libgit2-sys and the issues in https://github.com/rust-lang/libc/issues/1848), unless one is using bindgen or similar.

I am aware this crate doesn't want to carry functionality for generating binaries or dynamic libraries (#46, #250, #458), but, as far as I know, those are the only two ways to make the linker check if all symbols can be resolved, which would in turn allow for "primitive" feature detection.

I'd like to use such a feature to implement https://github.com/rust-lang/libc/pull/2088#issuecomment-788403886. Do you think it's feasible to build it atop cc-rs, or, given this justification, do you think cc-rs could carry it?

ericonr avatar Mar 05 '21 04:03 ericonr

fyi I maintain rsconf which has only cc-rs as a dependency and implements the functionality required for build scripts, such as target.has_symbol() or target.has_library(). We built this for use in fish-shell when we ported from C++ to rust over the past two years.

Unlike libc's "based off target-triple" approach, we feature detect specific libc features such as pipe2() or posix_spawn() so we can more gracefully handle older versions of the same system/architecture.

mqudsi avatar May 21 '24 18:05 mqudsi