Allow building from local

This commit is contained in:
Sarah Jamie Lewis 2022-04-27 13:03:10 -07:00
parent d223325646
commit e3c47ba16b
2 changed files with 23 additions and 13 deletions

View File

@ -20,4 +20,9 @@ but that we don't want to create rust bindings for (like importing stdlib.h). Th
bindgen libCwtch.h -o src/cwtchlib_go/bindings.rs
```
While developing you can use the `LCG_DIR` environment variable to specify the directory containing a local `libCwtch.so`
library to override the default one.
This is useful in cases where you are adding or updating APIs prior to a release.
### Todo

View File

@ -7,6 +7,7 @@ use hex_literal::hex;
use sha2::{Digest, Sha512};
fn main() {
// 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() {
@ -18,20 +19,24 @@ fn main() {
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.1
Command::new("wget")
.arg("https://git.openprivacy.ca/attachments/98184e9c-1dc7-431a-9601-91a9e763e8fc")
.arg("-O")
.arg(lib_cwtch_path)
.output()
.expect("failed to download libCwtch.so");
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/98184e9c-1dc7-431a-9601-91a9e763e8fc")
.arg("-O")
.arg(lib_cwtch_path.clone())
.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();
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!("cb4368d72a46f8046261c50e6e9ecf170d8e606871d5de2c1e9e34303533c344f92f5d946d7e12614581dfa3ae8e638512af7f4623ed91b1ceb1570de14bf192")[..]);
assert_eq!(hash_bytes[..], hex!("cb4368d72a46f8046261c50e6e9ecf170d8e606871d5de2c1e9e34303533c344f92f5d946d7e12614581dfa3ae8e638512af7f4623ed91b1ceb1570de14bf192")[..]);
} 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");
}
}
}