Skip to content
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

Merged
merged 5 commits into from
Apr 1, 2019

Conversation

ilammy
Copy link
Collaborator

@ilammy ilammy commented Mar 31, 2019

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.

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.
@ilammy ilammy added the W-RustThemis 🦀 Wrapper: Rust-Themis, Rust API, Cargo crates label Mar 31, 2019
Copy link
Contributor

@vixentael vixentael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up to @Lagovas

@vixentael vixentael added the installation Installation of Themis core and wrapper packages label Mar 31, 2019
Ok(_) => {
eprintln!(
"\
`libthemis-sys` tried using standard system paths and it seems that Themis
Copy link
Collaborator

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

Copy link
Collaborator Author

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().
@ilammy ilammy merged commit 55c9ec0 into cossacklabs:master Apr 1, 2019
@ilammy ilammy deleted the optional-pkg-config branch April 7, 2019 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
installation Installation of Themis core and wrapper packages W-RustThemis 🦀 Wrapper: Rust-Themis, Rust API, Cargo crates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants