aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nitrocli/CHANGELOG.md1
-rw-r--r--nitrocli/Cargo.lock4
-rw-r--r--nitrokey-sys/CHANGELOG.md10
-rw-r--r--nitrokey-sys/Cargo.toml3
-rw-r--r--nitrokey-sys/README.md24
-rw-r--r--nitrokey-sys/build.rs86
-rw-r--r--nitrokey-sys/src/lib.rs4
7 files changed, 69 insertions, 63 deletions
diff --git a/nitrocli/CHANGELOG.md b/nitrocli/CHANGELOG.md
index fcb126e..ef0e1f7 100644
--- a/nitrocli/CHANGELOG.md
+++ b/nitrocli/CHANGELOG.md
@@ -3,6 +3,7 @@ Unreleased
- Store cached PINs on a per-device basis to better support multi-device
scenarios
- Further decreased binary size by using system allocator
+- Bumped `nitrokey-sys` dependency to `3.4.3`
0.2.2
diff --git a/nitrocli/Cargo.lock b/nitrocli/Cargo.lock
index c3a73d0..a14111c 100644
--- a/nitrocli/Cargo.lock
+++ b/nitrocli/Cargo.lock
@@ -86,13 +86,13 @@ name = "nitrokey"
version = "0.3.1"
dependencies = [
"libc 0.2.45",
- "nitrokey-sys 3.4.1",
+ "nitrokey-sys 3.4.3",
"rand 0.6.1",
]
[[package]]
name = "nitrokey-sys"
-version = "3.4.1"
+version = "3.4.3"
dependencies = [
"cc 1.0.28",
]
diff --git a/nitrokey-sys/CHANGELOG.md b/nitrokey-sys/CHANGELOG.md
index 00f832b..a11d168 100644
--- a/nitrokey-sys/CHANGELOG.md
+++ b/nitrokey-sys/CHANGELOG.md
@@ -1,3 +1,13 @@
+# v3.4.3 (2019-10-12)
+- Link directly against `libnitrokey` if the `USE_SYSTEM_LIBNITROKEY`
+ environment variable is set.
+
+# v3.4.2 (2019-01-01)
+- Use the -std=c++14 compiler flag.
+- Change the build script to link to `-lhidapi` on non-Linux operating systems
+ (while still using `-lhidapi-libusb` on Linux).
+- Decouple the libnitrokey and nitrokey-sys-rs versions.
+
# v3.4.1 (2018-12-10)
- Update to libnitrokey 3.4.1. There are no changes affecting this crate.
diff --git a/nitrokey-sys/Cargo.toml b/nitrokey-sys/Cargo.toml
index 2486b77..f9d304b 100644
--- a/nitrokey-sys/Cargo.toml
+++ b/nitrokey-sys/Cargo.toml
@@ -1,7 +1,8 @@
[package]
name = "nitrokey-sys"
-version = "3.4.1"
+version = "3.4.3"
authors = ["Robin Krahl <robin.krahl@ireas.org>"]
+edition = "2018"
homepage = "https://code.ireas.org/nitrokey-rs/"
repository = "https://git.ireas.org/nitrokey-sys-rs/"
description = "Low-level bindings to libnitrokey for communication with Nitrokey devices"
diff --git a/nitrokey-sys/README.md b/nitrokey-sys/README.md
index 9b4f654..343b7b5 100644
--- a/nitrokey-sys/README.md
+++ b/nitrokey-sys/README.md
@@ -3,17 +3,23 @@
Low-level Rust bindings for `libnitrokey`, providing access to Nitrokey
devices.
-```toml
-[dependencies]
-nitrokey-sys = "3.4.1"
-```
+This crate contains a copy of the [`libnitrokey`][] library, builds it from
+source and links it statically. The host system must provide its dependencies
+in the library search path:
-The version of this crate corresponds to the wrapped `libnitrokey` version.
-This crate contains a copy of the `libnitrokey` library, builds it from source
-and links it statically. The host system must provide its dependencies in the
-library search path:
+- `libhidapi-libusb0` (on Linux)
+- `libhidapi` (on non-Linux systems)
-- `libhidapi-libusb0`
+If you set the `USE_SYSTEM_LIBNITROKEY` environment variable when building this
+crate, it links directly against `libnitrokey` instead of building it from
+source. In this case, `libnitrokey` must be available in the library search
+path.
+
+## Versioning
+
+The major and minor version of the `nitrokey-sys` crate map to the major and
+minor version of `libnitrokey`. The `nitrokey-sys` patch version may be
+increased independently.
## Contact
diff --git a/nitrokey-sys/build.rs b/nitrokey-sys/build.rs
index a22bbd0..defce72 100644
--- a/nitrokey-sys/build.rs
+++ b/nitrokey-sys/build.rs
@@ -1,57 +1,38 @@
-extern crate cc;
-
use std::env;
+use std::fs;
use std::io;
use std::io::{Read, Write};
-use std::fs;
use std::path;
+use std::string;
-struct Version {
- major: String,
- minor: String,
- git: String,
-}
+use cc;
-fn stringify(err: env::VarError) -> String {
- format!("{}", err)
+#[derive(Clone, Copy, Debug, PartialEq)]
+struct Version {
+ major: u32,
+ minor: u32,
+ patch: Option<u32>,
}
-fn extract_git_version(pre: &str) -> Result<String, String> {
- // If a pre-release version is set, it is expected to have the format
- // pre.v<maj>.<min>.<n>.g<hash>, where <maj> and <min> are the last major and minor version,
- // <n> is the number of commits since this version and <hash> is the hash of the last commit.
- let parts: Vec<&str> = pre.split('.').collect();
- if parts.len() != 5 {
- return Err(format!("'{}' is not a valid pre-release version", pre));
+impl string::ToString for Version {
+ fn to_string(&self) -> String {
+ match self.patch {
+ Some(patch) => format!("v{}.{}.{}", self.major, self.minor, patch),
+ None => format!("v{}.{}", self.major, self.minor),
+ }
}
- Ok(format!("{}.{}-{}-{}", parts[1], parts[2], parts[3], parts[4]))
}
-fn get_version() -> Result<Version, String> {
- let major = env::var("CARGO_PKG_VERSION_MAJOR").map_err(stringify)?;
- let minor = env::var("CARGO_PKG_VERSION_MINOR").map_err(stringify)?;
- let patch = env::var("CARGO_PKG_VERSION_PATCH").map_err(stringify)?;
- let pre = env::var("CARGO_PKG_VERSION_PRE").map_err(stringify)?;
-
- let git = match pre.is_empty() {
- true => match patch.is_empty() {
- true => format!("v{}.{}", major, minor),
- false => format!("v{}.{}.{}", major, minor, patch),
- },
- false => extract_git_version(&pre)?,
- };
-
- Ok(Version {
- major,
- minor,
- git,
- })
-}
+const LIBNITROKEY_VERSION: Version = Version {
+ major: 3,
+ minor: 4,
+ patch: Some(1),
+};
fn prepare_version_source(
- version: &Version,
+ version: Version,
out_path: &path::Path,
- library_path: &path::Path
+ library_path: &path::Path,
) -> io::Result<path::PathBuf> {
let out = out_path.join("version.cc");
let template = library_path.join("version.cc.in");
@@ -62,9 +43,9 @@ fn prepare_version_source(
drop(file);
let data = data
- .replace("@PROJECT_VERSION_MAJOR@", &version.major)
- .replace("@PROJECT_VERSION_MINOR@", &version.minor)
- .replace("@PROJECT_VERSION_GIT@", &version.git);
+ .replace("@PROJECT_VERSION_MAJOR@", &version.major.to_string())
+ .replace("@PROJECT_VERSION_MINOR@", &version.minor.to_string())
+ .replace("@PROJECT_VERSION_GIT@", &version.to_string());
let mut file = fs::File::create(&out)?;
file.write_all(data.as_bytes())?;
@@ -73,11 +54,14 @@ fn prepare_version_source(
}
fn main() {
+ if env::var("USE_SYSTEM_LIBNITROKEY").is_ok() {
+ println!("cargo:rustc-link-lib=nitrokey");
+ return;
+ }
+
let out_dir = env::var("OUT_DIR").expect("Environment variable OUT_DIR is not set");
let out_path = path::PathBuf::from(out_dir);
- let version = get_version().expect("Could not extract library version");
-
let sources = [
"DeviceCommunicationExceptions.cpp",
"NK_C_API.cc",
@@ -87,18 +71,24 @@ fn main() {
"log.cc",
"misc.cc",
];
- let library_dir = format!("libnitrokey-{}", version.git);
+ let library_dir = format!("libnitrokey-{}", LIBNITROKEY_VERSION.to_string());
let library_path = path::Path::new(&library_dir);
- let version_source = prepare_version_source(&version, &out_path, &library_path)
+ let version_source = prepare_version_source(LIBNITROKEY_VERSION, &out_path, &library_path)
.expect("Could not prepare the version source file");
cc::Build::new()
.cpp(true)
+ .flag("-std=c++14")
.include(library_path.join("libnitrokey"))
.files(sources.iter().map(|s| library_path.join(s)))
.file(version_source)
.compile("libnitrokey.a");
- println!("cargo:rustc-link-lib=hidapi-libusb");
+ let hidapi_library_name = if cfg!(target_os = "linux") {
+ "hidapi-libusb"
+ } else {
+ "hidapi"
+ };
+ println!("cargo:rustc-link-lib={}", hidapi_library_name);
}
diff --git a/nitrokey-sys/src/lib.rs b/nitrokey-sys/src/lib.rs
index 2740cc9..a179da8 100644
--- a/nitrokey-sys/src/lib.rs
+++ b/nitrokey-sys/src/lib.rs
@@ -4,7 +4,7 @@
mod ffi;
-pub use ffi::*;
+pub use crate::ffi::*;
#[cfg(test)]
mod tests {
@@ -14,8 +14,6 @@ mod tests {
#[test]
fn login_auto() {
unsafe {
- // logout required due to https://github.com/Nitrokey/libnitrokey/pull/115
- NK_logout();
assert_eq!(0, NK_login_auto());
}
}