mirror of
https://github.com/zkonduit/ezkl.git
synced 2026-01-07 21:43:54 -05:00
chore: ezkl self update (#809)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1878,6 +1878,7 @@ dependencies = [
|
||||
"rand 0.8.5",
|
||||
"regex",
|
||||
"reqwest",
|
||||
"semver 1.0.22",
|
||||
"seq-macro",
|
||||
"serde",
|
||||
"serde-wasm-bindgen",
|
||||
|
||||
@@ -45,6 +45,7 @@ num = "0.4.1"
|
||||
portable-atomic = "1.6.0"
|
||||
tosubcommand = { git = "https://github.com/zkonduit/enum_to_subcommand", package = "tosubcommand" }
|
||||
metal = { git = "https://github.com/gfx-rs/metal-rs", optional = true }
|
||||
semver = "1.0.22"
|
||||
|
||||
# evm related deps
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
|
||||
@@ -99,6 +99,10 @@ fi
|
||||
echo "Removing old ezkl binary if it exists"
|
||||
[ -e file ] && rm file
|
||||
|
||||
# echo platform and architecture
|
||||
echo "Platform: $PLATFORM"
|
||||
echo "Architecture: $ARCHITECTURE"
|
||||
|
||||
# download the release and unpack the right tarball
|
||||
if [ "$PLATFORM" == "windows-msvc" ]; then
|
||||
JSON_RESPONSE=$(curl -s "$RELEASE_URL")
|
||||
|
||||
@@ -17,17 +17,14 @@ use rand::prelude::SliceRandom;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[cfg(feature = "icicle")]
|
||||
use std::env;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use std::error::Error;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub async fn main() -> Result<(), Box<dyn Error>> {
|
||||
pub async fn main() {
|
||||
let args = Cli::parse();
|
||||
|
||||
if let Some(generator) = args.generator {
|
||||
ezkl::commands::print_completions(generator, &mut Cli::command());
|
||||
Ok(())
|
||||
} else if let Some(command) = args.command {
|
||||
init_logger();
|
||||
#[cfg(not(any(target_arch = "wasm32", feature = "no-banner")))]
|
||||
@@ -38,15 +35,17 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
|
||||
} else {
|
||||
info!("Running with CPU");
|
||||
}
|
||||
info!("command: \n {}", &command.as_json().to_colored_json_auto()?);
|
||||
info!(
|
||||
"command: \n {}",
|
||||
&command.as_json().to_colored_json_auto().unwrap()
|
||||
);
|
||||
let res = run(command).await;
|
||||
match &res {
|
||||
Ok(_) => info!("succeeded"),
|
||||
Err(e) => error!("failed: {}", e),
|
||||
};
|
||||
res.map(|_| ())
|
||||
} else {
|
||||
Err("No command provided".into())
|
||||
error!("no command provided");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -868,6 +868,12 @@ pub enum Commands {
|
||||
#[arg(long, value_hint = clap::ValueHint::Other)]
|
||||
addr_vk: Option<H160Flag>,
|
||||
},
|
||||
/// Updates ezkl binary to version specified (or latest if not specified)
|
||||
Update {
|
||||
/// The version to update to
|
||||
#[arg(value_hint = clap::ValueHint::Other, short='v', long)]
|
||||
version: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -502,6 +502,52 @@ pub async fn run(command: Commands) -> Result<String, Box<dyn Error>> {
|
||||
)
|
||||
.await
|
||||
}
|
||||
Commands::Update { version } => update_ezkl_binary(&version).map(|e| e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Assert that the version is valid
|
||||
fn assert_version_is_valid(version: &str) -> Result<(), Box<dyn Error>> {
|
||||
let err_string = "Invalid version string. Must be in the format v0.0.0";
|
||||
if version.is_empty() {
|
||||
return Err(err_string.into());
|
||||
}
|
||||
// safe to unwrap since we know the length is not 0
|
||||
if version.chars().nth(0).unwrap() != 'v' {
|
||||
return Err(err_string.into());
|
||||
}
|
||||
|
||||
semver::Version::parse(&version[1..])
|
||||
.map_err(|_| "Invalid version string. Must be in the format v0.0.0")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
const INSTALL_BYTES: &[u8] = include_bytes!("../install_ezkl_cli.sh");
|
||||
|
||||
fn update_ezkl_binary(version: &Option<String>) -> Result<String, Box<dyn Error>> {
|
||||
// run the install script with the version
|
||||
let install_script = std::str::from_utf8(INSTALL_BYTES)?;
|
||||
// now run as sh script with the version as an argument
|
||||
let mut command = std::process::Command::new("sh");
|
||||
let mut command = command.arg("-c").arg(install_script);
|
||||
|
||||
if let Some(version) = version {
|
||||
assert_version_is_valid(version)?;
|
||||
command = command.arg(version)
|
||||
};
|
||||
let output = command.output()?;
|
||||
|
||||
if output.status.success() {
|
||||
info!("updated binary");
|
||||
Ok("".to_string())
|
||||
} else {
|
||||
Err(format!(
|
||||
"failed to update binary: {}, {}",
|
||||
std::str::from_utf8(&output.stdout)?,
|
||||
std::str::from_utf8(&output.stderr)?
|
||||
)
|
||||
.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user