use std::fs; use std::path::Path; use std::process::Command; use std::{env, io}; use hex_literal::hex; use sha2::{Digest, Sha512}; fn main() { 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"); // https://git.openprivacy.ca/cwtch.im/libcwtch-go/releases v1.7.0 Command::new("wget") .arg("https://git.openprivacy.ca/attachments/390d383b-ab02-489b-b5c9-e62267d8b3fd") .arg("-O") .arg(lib_cwtch_path) .output() .expect("failed to download libCwtch.so"); let lib_cwtch_path = Path::new(&out_dir).join("libCwtch.so"); 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!("271c281bad59696fc4ea5e559b5d3fe5c1949384c26dd891dde91b0af0a012e30bdbc3b16781ec5de795d2945e2f42415a8985451b49394b3c85c412ab4769d3")[..]); }