Allow building from local
This commit is contained in:
parent
d223325646
commit
e3c47ba16b
|
@ -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
|
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
|
### Todo
|
||||||
|
|
31
build.rs
31
build.rs
|
@ -7,6 +7,7 @@ use hex_literal::hex;
|
||||||
use sha2::{Digest, Sha512};
|
use sha2::{Digest, Sha512};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
// Do not fetch lib on docs.rs as it cannot, build will fail, docs won't build
|
// Do not fetch lib on docs.rs as it cannot, build will fail, docs won't build
|
||||||
// https://docs.rs/about/builds
|
// https://docs.rs/about/builds
|
||||||
if std::env::var("DOCS_RS").is_err() {
|
if std::env::var("DOCS_RS").is_err() {
|
||||||
|
@ -18,20 +19,24 @@ fn main() {
|
||||||
println!("cargo:rerun-if-changed=libCwtch.h");
|
println!("cargo:rerun-if-changed=libCwtch.h");
|
||||||
|
|
||||||
let lib_cwtch_path = Path::new(&out_dir).join("libCwtch.so");
|
let lib_cwtch_path = Path::new(&out_dir).join("libCwtch.so");
|
||||||
// https://git.openprivacy.ca/cwtch.im/libcwtch-go/releases v1.7.1
|
if std::env::var("LCG_DIR").is_err() {
|
||||||
Command::new("wget")
|
// https://git.openprivacy.ca/cwtch.im/libcwtch-go/releases v1.7.1
|
||||||
.arg("https://git.openprivacy.ca/attachments/98184e9c-1dc7-431a-9601-91a9e763e8fc")
|
Command::new("wget")
|
||||||
.arg("-O")
|
.arg("https://git.openprivacy.ca/attachments/98184e9c-1dc7-431a-9601-91a9e763e8fc")
|
||||||
.arg(lib_cwtch_path)
|
.arg("-O")
|
||||||
.output()
|
.arg(lib_cwtch_path.clone())
|
||||||
.expect("failed to download libCwtch.so");
|
.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 hasher = Sha512::new();
|
let mut file = fs::File::open(&lib_cwtch_path).expect("could not open lib to hash");
|
||||||
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");
|
||||||
io::copy(&mut file, &mut hasher).expect("failed to copy file into hasher");
|
let hash_bytes = hasher.finalize();
|
||||||
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue