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
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/wrappers/themis/rust/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

The version currently in development.

## Internal improvements

- `libthemis-sys` is now able to use core Themis library installed in
standard system paths, without _pkg-config_ assistance. ([#444])

[#444]: https://github.com/cossacklabs/themis/pull/444

Version 0.11.0 — 2019-03-28
===========================

Expand Down
69 changes: 58 additions & 11 deletions src/wrappers/themis/rust/libthemis-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
use std::env;
use std::path::{Path, PathBuf};

use pkg_config::Library;

fn main() {
let themis = get_themis();

Expand All @@ -38,6 +36,11 @@ fn main() {
.expect("writing bindings!");
}

struct Library {
include_paths: Vec<PathBuf>,
link_paths: Vec<PathBuf>,
}

/// Embarks on an incredible adventure and returns with a suitable Themis (or dies trying).
fn get_themis() -> Library {
#[cfg(feature = "vendored")]
Expand All @@ -50,15 +53,20 @@ fn get_themis() -> Library {
pkg_config.statik(true);

match pkg_config.probe("libthemis") {
Ok(library) => return library,
Err(error) => panic!(format!(
"

Ok(library) => {
return Library {
include_paths: library.include_paths,
link_paths: library.link_paths,
};
}
Err(error) => {
eprintln!(
"
`libthemis-sys` could not find Themis installation in your system.

Please make sure you have appropriate development package installed.
On Linux it's called `libthemis-dev`, not just `libthemis`.
On macOS Homebrew formula is called `themis` or `themis-openssl`.
On macOS Homebrew formula is called `libthemis`.

Please refer to the documentation for installation instructions:

Expand All @@ -68,11 +76,16 @@ This crate uses `pkg-config` to locate the library. If you use
non-standard installation of Themis then you can help pkg-config
to locate your library by setting the PKG_CONFIG_PATH environment
variable to the path where `libthemis.pc` file is located.
"
);
eprintln!("{}", error);

if let Some(library) = try_system_themis() {
return library;
}

{}
",
error
)),
panic!("Themis Core not installed");
}
}
}

Expand Down Expand Up @@ -111,3 +124,37 @@ impl CCBuildEx for cc::Build {
self
}
}

fn try_system_themis() -> Option<Library> {
let mut build = cc::Build::new();
build.file("src/dummy.c");
build.flag("-lthemis");

match build.try_compile("dummy") {
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.

is available on your system. (However, pkg-config failed to find it.)
We will link against the system library.
"
);
println!("cargo:rustc-link-lib=dylib=themis");

// Use only system paths for header and library lookup.
Some(Library {
include_paths: vec![],
link_paths: vec![],
})
}
Err(_) => {
eprintln!(
"\
`libthemis-sys` also tried to use standard system paths, but without success.
It seems that Themis is really not installed in your system.
"
);
None
}
}
}
22 changes: 22 additions & 0 deletions src/wrappers/themis/rust/libthemis-sys/src/dummy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2019 (c) rust-themis developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Dummy file used to verify that the compiler sees native Themis library.

#include <themis/themis.h>

void libthemis_sys_unused(void)
{
themis_gen_ec_key_pair(NULL, NULL, NULL, NULL);
}