Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST to JSON serialization support #246

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 60 additions & 27 deletions .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,73 @@
name: Publish binaries
on:
push:
tags:
- '*'
release:
types: [created]

env:
CARGO_TERM_COLOR: always

permissions:
contents: write

jobs:
build-and-publish:
name: Publish for ${{ matrix.os }}
runs-on: ${{ matrix.os }}
build:
name: ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
artifact_name: circom
asset_name: circom-linux-amd64
- os: windows-latest
artifact_name: circom.exe
asset_name: circom-windows-amd64.exe
- os: macos-latest
artifact_name: circom
asset_name: circom-macos-amd64

platform:
- os_name: Linux-aarch64
os: ubuntu-20.04
target: aarch64-unknown-linux-musl
bin: circom-linux-arm64
- os_name: Linux-x86_64
os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
bin: circom-linux-amd64
- os_name: Windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
bin: circom-amd64.exe
- os_name: Windows-aarch64
os: windows-latest
target: aarch64-pc-windows-msvc
bin: circom-arm64.exe
- os_name: macOS-x86_64
os: macOS-latest
target: x86_64-apple-darwin
bin: circom-darwin-amd64
- os_name: macOS-aarch64
os: macOS-latest
target: aarch64-apple-darwin
bin: circom-darwin-arm64
toolchain:
- stable
steps:
- name: Checkout project
uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: "build"
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--locked --release"
strip: true

- name: Rename binary (linux and macos)
run: mv target/${{ matrix.platform.target }}/release/circom target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
if: matrix.platform.os_name != 'Windows-x86_64' && matrix.platform.os_name != 'Windows-aarch64'

- name: Rename binary (windows)
run: mv target/${{ matrix.platform.target }}/release/circom.exe target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
if: matrix.platform.os_name == 'Windows-x86_64' || matrix.platform.os_name == 'Windows-aarch64'

- name: Build
run: cargo build --verbose --release
- name: Generate SHA-256
run: shasum -a 256 target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} | cut -d ' ' -f 1 > target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.sha256

- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
- name: Release binary and SHA-256 checksum to GitHub
uses: softprops/action-gh-release@v1
with:
file: target/release/${{ matrix.artifact_name }}
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }}
asset_name: ${{ matrix.asset_name }}
files: |
target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.sha256
41 changes: 28 additions & 13 deletions Cargo.lock

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

64 changes: 62 additions & 2 deletions circom/src/input_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ pub struct Input {
pub no_rounds: usize,
pub flag_verbose: bool,
pub prime: String,
pub link_libraries : Vec<PathBuf>
pub link_libraries : Vec<PathBuf>,
pub save_ast: bool,
pub ast_path: PathBuf,
pub dry_run: bool,
}


Expand Down Expand Up @@ -105,7 +108,10 @@ impl Input {
flag_old_heuristics: input_processing::get_flag_old_heuristics(&matches),
flag_verbose: input_processing::get_flag_verbose(&matches),
prime: input_processing::get_prime(&matches)?,
link_libraries
link_libraries,
save_ast: input_processing::get_save_ast(&matches),
ast_path: input_processing::get_ast_path(&matches)?,
dry_run: input_processing::get_dry_run(&matches),
})
}

Expand Down Expand Up @@ -319,6 +325,7 @@ mod input_processing {
pub fn get_flag_old_heuristics(matches: &ArgMatches) -> bool {
matches.is_present("flag_old_heuristics")
}

pub fn get_prime(matches: &ArgMatches) -> Result<String, ()> {

match matches.is_present("prime"){
Expand All @@ -344,6 +351,44 @@ mod input_processing {
}
}

pub fn get_save_ast(matches: &ArgMatches) -> bool {
matches.occurrences_of("save_ast") > 0
}

pub fn get_ast_path(matches: &ArgMatches) -> Result<PathBuf, ()> {
let binding = get_input(&matches)?;
let input = binding.file_stem().ok_or(())?.to_str().ok_or(())?;
let file_name = &format!("{}_ast.json", input);
let output_dir = get_output_path(&matches)?;

if matches.value_of("save_ast").ok_or(())? == "<path_to_output>/<filename>_ast.json" {
return Ok(PathBuf::from(file_name));
}

let path_str = matches.value_of("save_ast").ok_or(())?;
let mut path = PathBuf::from(path_str);

if !path.is_absolute() {
path = output_dir.join(path);
}

if path_str.ends_with("/") {
let _ = std::fs::create_dir_all(&path);
} else if let Some(parent) = path.parent() {
let _ = std::fs::create_dir_all(parent);
}

if path.is_dir() {
Ok(PathBuf::from(path.join(file_name).to_str().ok_or(())?))
} else {
Ok(PathBuf::from(path.to_str().ok_or(())?))
}
}

pub fn get_dry_run(matches: &ArgMatches) -> bool {
matches.is_present("dry_run")
}

pub fn view() -> ArgMatches<'static> {
App::new("circom compiler")
.version(VERSION)
Expand Down Expand Up @@ -509,6 +554,21 @@ mod input_processing {
.display_order(300)
.help("To choose the prime number to use to generate the circuit. Receives the name of the curve (bn128, bls12381, goldilocks, grumpkin, pallas, vesta, secq256r1)"),
)
.arg(
Arg::with_name("save_ast")
.long("save_ast")
.takes_value(true)
.default_value("<path_to_output>/<filename>_ast.json")
.display_order(990)
.help("If --save_ast is specified, the compiler will save the serialized AST of the circuit, accepts a filename or path as argument"),
)
.arg(
Arg::with_name("dry_run")
.long("dry_run")
.takes_value(false)
.display_order(1000)
.help("Does not run the compiler, only checks the input and outputs the AST if --save_ast is present"),
)
.get_matches()
}

Expand Down
4 changes: 4 additions & 0 deletions circom/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ fn start() -> Result<(), ()> {
let mut program_archive = parser_user::parse_project(&user_input)?;
type_analysis_user::analyse_project(&mut program_archive)?;

if user_input.dry_run {
return Result::Ok(());
}

let config = ExecutionConfig {
no_rounds: user_input.no_rounds(),
flag_p: user_input.parallel_simplification_flag(),
Expand Down
2 changes: 1 addition & 1 deletion circom/src/parser_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn parse_project(input_info: &Input) -> Result<ProgramArchive, ()> {
let initial_file = input_info.input_file().to_string();
//We get the prime number from the input
let prime = UsefulConstants::new(&input_info.prime()).get_p().clone();
let result_program_archive = parser::run_parser(initial_file, VERSION, input_info.get_link_libraries().to_vec(), &prime);
let result_program_archive = parser::run_parser(initial_file, VERSION, input_info.get_link_libraries().to_vec(), &prime, input_info.save_ast, input_info.ast_path.clone());
match result_program_archive {
Result::Err((file_library, report_collection)) => {
Report::print_reports(&report_collection, &file_library);
Expand Down
1 change: 1 addition & 0 deletions parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ num-bigint-dig = "0.6.0"
num-traits = "0.2.6"
serde = "1.0.82"
serde_derive = "1.0.91"
serde_json = "1.0.114"
Loading