| 1 |
From b220b6d00afe2221cbe327eea3954f86a2c46eb8 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Wolfgang Silbermayr <[email protected]> |
| 3 |
Date: Thu, 13 Dec 2018 16:26:56 +0100 |
| 4 |
Subject: [PATCH] Update build.rs for shared library |
| 5 |
|
| 6 |
--- |
| 7 |
build.rs | 102 +------------------------------------------------------ |
| 8 |
1 file changed, 1 insertion(+), 101 deletions(-) |
| 9 |
|
| 10 |
Index: nitrokey-sys/build.rs |
| 11 |
=================================================================== |
| 12 |
--- nitrokey-sys.orig/build.rs |
| 13 |
+++ nitrokey-sys/build.rs |
| 14 |
@@ -1,94 +1,3 @@ |
| 15 |
-use std::env; |
| 16 |
-use std::fs; |
| 17 |
-use std::io; |
| 18 |
-use std::io::{Read, Write}; |
| 19 |
-use std::path; |
| 20 |
-use std::string; |
| 21 |
- |
| 22 |
-use cc; |
| 23 |
- |
| 24 |
-#[derive(Clone, Copy, Debug, PartialEq)] |
| 25 |
-struct Version { |
| 26 |
- major: u32, |
| 27 |
- minor: u32, |
| 28 |
- patch: Option<u32>, |
| 29 |
-} |
| 30 |
- |
| 31 |
-impl string::ToString for Version { |
| 32 |
- fn to_string(&self) -> String { |
| 33 |
- match self.patch { |
| 34 |
- Some(patch) => format!("v{}.{}.{}", self.major, self.minor, patch), |
| 35 |
- None => format!("v{}.{}", self.major, self.minor), |
| 36 |
- } |
| 37 |
- } |
| 38 |
-} |
| 39 |
- |
| 40 |
-const LIBNITROKEY_VERSION: Version = Version { |
| 41 |
- major: 3, |
| 42 |
- minor: 4, |
| 43 |
- patch: Some(1), |
| 44 |
-}; |
| 45 |
- |
| 46 |
-fn prepare_version_source( |
| 47 |
- version: Version, |
| 48 |
- out_path: &path::Path, |
| 49 |
- library_path: &path::Path, |
| 50 |
-) -> io::Result<path::PathBuf> { |
| 51 |
- let out = out_path.join("version.cc"); |
| 52 |
- let template = library_path.join("version.cc.in"); |
| 53 |
- |
| 54 |
- let mut file = fs::File::open(template)?; |
| 55 |
- let mut data = String::new(); |
| 56 |
- file.read_to_string(&mut data)?; |
| 57 |
- drop(file); |
| 58 |
- |
| 59 |
- let data = data |
| 60 |
- .replace("@PROJECT_VERSION_MAJOR@", &version.major.to_string()) |
| 61 |
- .replace("@PROJECT_VERSION_MINOR@", &version.minor.to_string()) |
| 62 |
- .replace("@PROJECT_VERSION_GIT@", &version.to_string()); |
| 63 |
- |
| 64 |
- let mut file = fs::File::create(&out)?; |
| 65 |
- file.write_all(data.as_bytes())?; |
| 66 |
- |
| 67 |
- Ok(out) |
| 68 |
-} |
| 69 |
- |
| 70 |
fn main() { |
| 71 |
- if env::var("USE_SYSTEM_LIBNITROKEY").is_ok() { |
| 72 |
- println!("cargo:rustc-link-lib=nitrokey"); |
| 73 |
- return; |
| 74 |
- } |
| 75 |
- |
| 76 |
- let out_dir = env::var("OUT_DIR").expect("Environment variable OUT_DIR is not set"); |
| 77 |
- let out_path = path::PathBuf::from(out_dir); |
| 78 |
- |
| 79 |
- let sources = [ |
| 80 |
- "DeviceCommunicationExceptions.cpp", |
| 81 |
- "NK_C_API.cc", |
| 82 |
- "NitrokeyManager.cc", |
| 83 |
- "command_id.cc", |
| 84 |
- "device.cc", |
| 85 |
- "log.cc", |
| 86 |
- "misc.cc", |
| 87 |
- ]; |
| 88 |
- let library_dir = format!("libnitrokey-{}", LIBNITROKEY_VERSION.to_string()); |
| 89 |
- let library_path = path::Path::new(&library_dir); |
| 90 |
- |
| 91 |
- let version_source = prepare_version_source(LIBNITROKEY_VERSION, &out_path, &library_path) |
| 92 |
- .expect("Could not prepare the version source file"); |
| 93 |
- |
| 94 |
- cc::Build::new() |
| 95 |
- .cpp(true) |
| 96 |
- .flag("-std=c++14") |
| 97 |
- .include(library_path.join("libnitrokey")) |
| 98 |
- .files(sources.iter().map(|s| library_path.join(s))) |
| 99 |
- .file(version_source) |
| 100 |
- .compile("libnitrokey.a"); |
| 101 |
- |
| 102 |
- let hidapi_library_name = if cfg!(target_os = "linux") { |
| 103 |
- "hidapi-libusb" |
| 104 |
- } else { |
| 105 |
- "hidapi" |
| 106 |
- }; |
| 107 |
- println!("cargo:rustc-link-lib={}", hidapi_library_name); |
| 108 |
+ println!("cargo:rustc-link-lib=nitrokey"); |
| 109 |
} |