Skip to content

Commit

Permalink
auto-install the needed tools
Browse files Browse the repository at this point in the history
  • Loading branch information
imikushin committed Dec 23, 2024
1 parent 9b614c2 commit 80b3c9a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/commands/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,35 @@ use anyhow::{ensure, Result};
use charms::app;
use std::fs;

pub fn new(name: &str) -> Result<()> {
if !std::process::Command::new("which")
.args(&["cargo-generate"])
.status()?
.success()
{
std::process::Command::new("cargo")
.args(&["install", "cargo-generate"])
.status()?;
}
let status = std::process::Command::new("cargo")
.args(&["generate", "sigma0-dev/charms-app", "--name", name])
.status()?;
ensure!(status.success());
Ok(())
}

pub fn build() -> Result<()> {
if !std::process::Command::new("which")
.args(&["cargo-prove"])
.status()?
.success()
{
std::process::Command::new("bash")
.args(&["-c", "curl -L https://sp1.succinct.xyz | bash"])
.status()?;
std::process::Command::new(format!("{}/.sp1/bin/sp1up", std::env::var("HOME")?))
.status()?;
}
let mut child = std::process::Command::new("cargo")
.args(&["prove", "build"])
.stdout(std::process::Stdio::piped())
Expand Down
8 changes: 8 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ pub enum TxCommands {

#[derive(Subcommand)]
pub enum AppCommands {
/// Create a new app
New {
/// Name of the app. Directory <NAME> will be created.
name: String,
},

/// Build the app
Build,

/// Show verification key for an app
Expand All @@ -90,5 +97,6 @@ pub enum AppCommands {
path: Option<String>,
},

/// Generate the app proof for a spell.
Prove,
}
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ fn main() -> Result<()> {
TxCommands::ShowSpell { tx } => tx::tx_show_spell(tx),
},
Commands::App { command } => match command {
AppCommands::New { name } => app::new(&name),
AppCommands::Vk { path } => app::vk(path),
AppCommands::Build => {
todo!()
}
AppCommands::Build => app::build(),
AppCommands::Prove => {
todo!()
}
Expand Down

0 comments on commit 80b3c9a

Please sign in to comment.