libcwtch-rs/build.rs

43 lines
1.7 KiB
Rust
Raw Normal View History

use std::{env, io};
use std::fs;
use std::path::Path;
2022-01-16 19:06:30 +00:00
use std::process::Command;
use hex_literal::hex;
use sha2::{Digest, Sha512};
fn main() {
2022-04-27 20:03:10 +00:00
// Do not fetch lib on docs.rs as it cannot, build will fail, docs won't build
// https://docs.rs/about/builds
if std::env::var("DOCS_RS").is_err() {
let out_dir = env::var_os("OUT_DIR").unwrap();
println!("cargo:rustc-flags=-L {}", out_dir.to_str().unwrap());
println!("cargo:rustc-link-lib=Cwtch");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=libCwtch.h");
let lib_cwtch_path = Path::new(&out_dir).join("libCwtch.so");
2022-04-27 20:03:10 +00:00
if std::env::var("LCG_DIR").is_err() {
// https://git.openprivacy.ca/cwtch.im/libcwtch-go/releases v1.7.1
Command::new("wget")
.arg("https://git.openprivacy.ca/attachments/5fa8e7f5-13c2-4634-b531-0398cd7c6353")
2022-04-27 20:03:10 +00:00
.arg("-O")
.arg(lib_cwtch_path.clone())
.output()
.expect("failed to download libCwtch.so");
2022-04-27 20:03:10 +00:00
let mut hasher = Sha512::new();
let mut file = fs::File::open(&lib_cwtch_path).expect("could not open lib to hash");
io::copy(&mut file, &mut hasher).expect("failed to copy file into hasher");
let hash_bytes = hasher.finalize();
assert_eq!(hash_bytes[..], hex!("dc53eb4948357128a72f740cf48402e966e886c60bc150bd26d10d3c98dda64c3658322c15f3b93781365d40dd4315b1056fb9aa6ee3a56f8968d4bff1bc8f0d")[..]);
2022-04-27 20:03:10 +00:00
} else {
let local_lcg = Path::new(std::env::var("LCG_DIR").unwrap().as_str()).join("libCwtch.so");
fs::copy(local_lcg, lib_cwtch_path).expect("could not find local lcg");
}
}
2022-01-16 19:06:30 +00:00
}