aboutsummaryrefslogtreecommitdiff
path: root/nitrokey-sys/build.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2020-04-04 14:39:19 -0700
committerDaniel Mueller <deso@posteo.net>2020-04-04 14:39:19 -0700
commitd0d9683df8398696147e7ee1fcffb2e4e957008c (patch)
tree4baa76712a76f4d072ee3936c07956580b230820 /nitrokey-sys/build.rs
parent203e691f46d591a2cc8acdfd850fa9f5b0fb8a98 (diff)
downloadnitrocli-d0d9683df8398696147e7ee1fcffb2e4e957008c.tar.gz
nitrocli-d0d9683df8398696147e7ee1fcffb2e4e957008c.tar.bz2
Remove vendored dependencies
While it appears that by now we actually can get successful builds without Cargo insisting on Internet access by virtue of using the --frozen flag, maintaining vendored dependencies is somewhat of a pain point. This state will also get worse with upcoming changes that replace argparse in favor of structopt and pull in a slew of new dependencies by doing so. Then there is also the repository structure aspect, which is non-standard due to the way we vendor dependencies and a potential source of confusion. In order to fix these problems, this change removes all the vendored dependencies we have. Delete subrepo argparse/:argparse Delete subrepo base32/:base32 Delete subrepo cc/:cc Delete subrepo cfg-if/:cfg-if Delete subrepo getrandom/:getrandom Delete subrepo lazy-static/:lazy-static Delete subrepo libc/:libc Delete subrepo nitrokey-sys/:nitrokey-sys Delete subrepo nitrokey/:nitrokey Delete subrepo rand/:rand
Diffstat (limited to 'nitrokey-sys/build.rs')
-rw-r--r--nitrokey-sys/build.rs94
1 files changed, 0 insertions, 94 deletions
diff --git a/nitrokey-sys/build.rs b/nitrokey-sys/build.rs
deleted file mode 100644
index a9d0778..0000000
--- a/nitrokey-sys/build.rs
+++ /dev/null
@@ -1,94 +0,0 @@
-use std::env;
-use std::fs;
-use std::io;
-use std::io::{Read, Write};
-use std::path;
-use std::string;
-
-use cc;
-
-#[derive(Clone, Copy, Debug, PartialEq)]
-struct Version {
- major: u32,
- minor: u32,
- patch: Option<u32>,
-}
-
-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),
- }
- }
-}
-
-const LIBNITROKEY_VERSION: Version = Version {
- major: 3,
- minor: 5,
- patch: None,
-};
-
-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.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())?;
-
- Ok(out)
-}
-
-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 sources = [
- "DeviceCommunicationExceptions.cpp",
- "NK_C_API.cc",
- "NitrokeyManager.cc",
- "command_id.cc",
- "device.cc",
- "log.cc",
- "misc.cc",
- ];
- let library_dir = format!("libnitrokey-{}", LIBNITROKEY_VERSION.to_string());
- let library_path = path::Path::new(&library_dir);
-
- 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");
-
- let hidapi_library_name = if cfg!(target_os = "linux") {
- "hidapi-libusb"
- } else {
- "hidapi"
- };
- println!("cargo:rustc-link-lib={}", hidapi_library_name);
-}