-
Notifications
You must be signed in to change notification settings - Fork 144
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
Try standard system path when pkg-config fails #444
Conversation
We're going to rely not only on pkg-config for locating Themis, but we cannot construct pkg_config::Library instances (it has private fields). Use a custom type with the same API instead.
We're going to provide an alternative code path for when pkg-config fails, so instead of panicking with an error message just output it to stderr and panic later. This enables us to insert some actions in between and prevent the panic.
Currently Rust-Themis requires pkg-config to successfully find Themis. If it doesn't (for whatever reason) then the crate won't compile. However, the library might be correctly installed in the system under standard paths. This allows us to easily link against it dynamically. Let's support this use case to allow non-packaged installations. If pkg-config successfully locates core Themis library then we just go with it. Otherwise we effectively try to run cc -shared src/dummy.c -lthemis and see if that compiles. If it does then apparently Themis is installed and we can use it by emitting appropriate instructions to Cargo. Note that we support only dynamic linkage in this case. Static linkage will not work because we will have to figure out transitive dependencies like Soter and OpenSSL, which is the reason for preferring pkg-config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
up to @Lagovas
Ok(_) => { | ||
eprintln!( | ||
"\ | ||
`libthemis-sys` tried using standard system paths and it seems that Themis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho this message should be printed from get_themis
function, not here. function try_system_themis
just check is themis exists in themis and doesn't know anything about high-level concerns like libthemis-sys
existence. here just return success/error code and maybe print how it was checked and why it is failed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I'll move these error/status messages up the call stack.
We're printing status messages only there so let's keep it like that. Make try_system_themis() simply a utility function. Though, it will still print Cargo instructions if successful, like pkg_config::probe().
Currently Rust-Themis requires pkg-config to successfully find Themis. If it doesn't (for whatever reason) then the crate won't compile. However, the library might be correctly installed in the system under standard paths. This allows us to easily link against it dynamically. Let's support this use case to allow non-packaged installations.
If pkg-config successfully locates core Themis library then we just go with it. Otherwise we effectively try to run
and see if that compiles. If it does then apparently Themis is installed and we can use it by emitting appropriate instructions to Cargo.
Note that we support only dynamic linkage in this case. Static linkage will not work because we will have to figure out transitive dependencies like Soter and OpenSSL, which is the reason for preferring pkg-config.