diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2018-12-10 12:42:48 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2018-12-10 13:46:42 +0100 |
commit | 4615f5ecf96ef4637d814a4dfeab9c404b4a3667 (patch) | |
tree | 5bd65c78c1c913d44e8917c29e91895a9de450f6 /build.rs | |
parent | b126c5ba1e5a9f00859868d75900043d02a0031c (diff) | |
download | nitrokey-sys-rs-4615f5ecf96ef4637d814a4dfeab9c404b4a3667.tar.gz nitrokey-sys-rs-4615f5ecf96ef4637d814a4dfeab9c404b4a3667.tar.bz2 |
Update to libnitrokey v3.4v3.4.0
Besides the changes listed in the changelog, this patch also changes the
build system to be able to generate the version.cc file containing the
library version.
Diffstat (limited to 'build.rs')
-rw-r--r-- | build.rs | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -1,6 +1,9 @@ extern crate cc; use std::env; +use std::io; +use std::io::{Read, Write}; +use std::fs; use std::path; struct Version { @@ -41,7 +44,34 @@ fn get_version() -> Result<Version, String> { }) } +fn prepare_version_source( + version: &Version, + out_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"); + + let mut file = fs::File::open(template)?; + let mut data = String::new(); + file.read_to_string(&mut data)?; + drop(file); + + let data = data + .replace("@PROJECT_VERSION_MAJOR@", &version.major) + .replace("@PROJECT_VERSION_MINOR@", &version.minor) + .replace("@PROJECT_VERSION_GIT@", &version.git); + + let mut file = fs::File::create(&out)?; + file.write_all(data.as_bytes())?; + + Ok(out) +} + fn main() { + 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 = [ @@ -56,10 +86,14 @@ fn main() { let library_dir = format!("libnitrokey-{}", version.git); let library_path = path::Path::new(&library_dir); + let version_source = prepare_version_source(&version, &out_path, &library_path) + .expect("Could not prepare the version source file"); + cc::Build::new() .cpp(true) .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"); |