Skip to content

Commit

Permalink
feat(cli): create ios/android template (#245)
Browse files Browse the repository at this point in the history
* feat(cli): create ios template

* feat(cli): init android template

* feat(cli): complete android cli script

* chore(cli): move print messages, update readme

* chore(cli): copy keys from test-vectors

* fix(cli): fix naming

* fix: fix Cargo.lock

* chore: seperate inputs, output anyhow result, add cli tests

* chore: lint
  • Loading branch information
vivianjeng authored Oct 30, 2024
1 parent 33dfb9b commit dc5609b
Show file tree
Hide file tree
Showing 76 changed files with 2,549 additions and 315 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ jobs:
- uses: actions/checkout@v4
- name: Check formatting
run: cargo fmt --all -- --check

cli:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
steps:
- uses: actions/checkout@v4
- name: Install cli
run: |
cd cli
cargo install --path .
mopro --help
test-ffi-halo2:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

241 changes: 0 additions & 241 deletions cli/Cargo.lock

This file was deleted.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ fs_extra = "1.2.0"
include_dir = "0.7"
dialoguer = "0.10"
console = "0.15.8"
anyhow = "1.0.86"
6 changes: 6 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ mopro init
```sh
mopro build
```

## Create templates

```sh
mopro create
```
30 changes: 17 additions & 13 deletions cli/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
use crate::style::{self, blue_bold, print_green_bold};
use dialoguer::{theme::ColorfulTheme, MultiSelect, Select};
use std::{env, error::Error};
use crate::print::print_build_success_message;
use crate::style;
use crate::style::blue_bold;
use crate::style::print_green_bold;
use dialoguer::theme::ColorfulTheme;
use dialoguer::MultiSelect;
use dialoguer::Select;
use std::env;

const MODES: [&str; 2] = ["debug", "release"];
const PLATFORMS: [&str; 2] = ["ios", "android"];

pub fn build_project(
arg_mode: &Option<String>,
arg_platforms: &Option<Vec<String>>,
) -> Result<(), Box<dyn Error>> {
) -> anyhow::Result<()> {
let mode: String = match arg_mode.as_deref() {
None => select_mode()?,
Some(m) => {
Expand Down Expand Up @@ -63,7 +68,10 @@ pub fn build_project(

if !status.success() {
// Return a custom error if the command fails
return Err(format!("Output with status code {}", status.code().unwrap()).into());
return Err(anyhow::anyhow!(
"Output with status code {}",
status.code().unwrap()
));
}
}

Expand All @@ -73,7 +81,7 @@ pub fn build_project(
Ok(())
}

fn select_mode() -> Result<String, Box<dyn Error>> {
fn select_mode() -> anyhow::Result<String> {
let idx = Select::with_theme(&ColorfulTheme::default())
.with_prompt("Build mode")
.items(&MODES)
Expand All @@ -82,7 +90,7 @@ fn select_mode() -> Result<String, Box<dyn Error>> {
Ok(MODES[idx].to_owned())
}

fn select_platforms() -> Result<Vec<String>, Box<dyn Error>> {
fn select_platforms() -> anyhow::Result<Vec<String>> {
let selected_platforms = MultiSelect::with_theme(&ColorfulTheme::default())
.with_prompt("Select platform(s) to build for (multiple selection with space)")
.items(&PLATFORMS)
Expand All @@ -94,7 +102,7 @@ fn select_platforms() -> Result<Vec<String>, Box<dyn Error>> {
.collect())
}

fn print_binding_message(platforms: Vec<String>) -> Result<(), Box<dyn Error>> {
fn print_binding_message(platforms: Vec<String>) -> anyhow::Result<()> {
let current_dir = env::current_dir()?;
print_green_bold("✨ Bindings Built Successfully! ✨".to_string());
println!("The Mopro bindings have been successfully generated and are available in the following directories:\n");
Expand All @@ -109,10 +117,6 @@ fn print_binding_message(platforms: Vec<String>) -> Result<(), Box<dyn Error>> {
);
println!("{}", blue_bold(text.to_string()));
}
println!();
println!(
"📚 To learn more about mopro, visit: {}",
style::blue_bold("https://zkmopro.org".to_string())
);
print_build_success_message();
Ok(())
}
Loading

0 comments on commit dc5609b

Please sign in to comment.