-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
26 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,33 @@ | ||
#[cfg(feature = "grovedbg")] | ||
fn main() { | ||
use std::{ | ||
env, | ||
path::PathBuf, | ||
process::{Command, ExitStatus, Output}, | ||
}; | ||
use std::{env, fs::File, io::Cursor, path::PathBuf}; | ||
|
||
use hex_literal::hex; | ||
use sha2::{digest::FixedOutput, Digest, Sha256}; | ||
|
||
const GROVEDBG_SHA256: [u8; 32] = | ||
hex!("206d865949e7f12b843c342cea3b172d4c78d4eb754b80d272164d59f62a2276"); | ||
const GROVEDBG_VERSION: &str = "v1.0.0-rc.3"; | ||
|
||
let out_dir = PathBuf::from(&env::var_os("OUT_DIR").unwrap()); | ||
let grovedbg_zip_path = out_dir.join("grovedbg.zip"); | ||
|
||
if !grovedbg_zip_path.exists() { | ||
let response = reqwest::blocking::get(&format!("https://github.com/dashpay/grovedbg/releases/download/{GROVEDBG_VERSION}/grovedbg-{GROVEDBG_VERSION}.zip")) | ||
Check warning on line 16 in grovedb/build.rs GitHub Actions / clippythe borrowed expression implements the required traits
|
||
.expect("can't download GroveDBG artifact"); | ||
|
||
let Output { | ||
status, | ||
stdout, | ||
stderr, | ||
} = Command::new("trunk") | ||
.arg("build") | ||
.arg("--release") | ||
.arg("--dist") | ||
.arg(&out_dir) | ||
.arg("grovedbg/index.html") | ||
.output() | ||
.expect("cannot start trunk process"); | ||
|
||
if !status.success() { | ||
let stdout_msg = String::from_utf8_lossy(&stdout); | ||
let stderr_msg = String::from_utf8_lossy(&stderr); | ||
let bindgen_version = env::var_os("TRUNK_TOOLS_WASM_BINDGEN").unwrap_or_default(); | ||
panic!("Error running `trunk build --release`\nbindgen version:{bindgen_version:?}\n{stdout_msg}\n{stderr_msg}"); | ||
let mut grovedbg_zip = File::create(&grovedbg_zip_path).unwrap(); | ||
let mut content = Cursor::new(response.bytes().unwrap()); | ||
std::io::copy(&mut content, &mut grovedbg_zip).unwrap(); | ||
} | ||
|
||
let zip_file = out_dir.join("grovedbg.zip"); | ||
zip_extensions::write::zip_create_from_directory(&zip_file, &out_dir) | ||
.expect("can't create a grovedbg zip archive"); | ||
let mut grovedbg_zip = File::open(&grovedbg_zip_path).unwrap(); | ||
|
||
let mut sha256 = Sha256::new(); | ||
std::io::copy(&mut grovedbg_zip, &mut sha256).unwrap(); | ||
let hash = sha256.finalize_fixed(); | ||
|
||
assert_eq!(hash.as_slice(), GROVEDBG_SHA256); | ||
} | ||
|
||
#[cfg(not(feature = "grovedbg"))] | ||
|