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

[feat] cargo axiom e2e test #1003

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
58 changes: 58 additions & 0 deletions .github/workflows/cli-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: CLI e2e test

on:
push:
branches: ["main"]
pull_request:
branches: ["**"]
paths:
- "crates/stark-backend/**"
- "crates/circuits/primitives/**"
- "crates/vm/**"
- "crates/cargo-axiom/**"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
AXIOM_FAST_TEST: "1"

jobs:
tests:
runs-on:
- runs-on=${{ github.run_id }}
- runner=32cpu-linux-arm64

steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- uses: taiki-e/install-action@nextest

- name: Install cargo-axiom
working-directory: crates/cargo-axiom
run: |
rustup component add rust-src --toolchain nightly-2024-10-30-aarch64-unknown-linux-gnu
cargo install --force --locked --path .

- name: E2E CLI test
working-directory: crates/cargo-axiom
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
Golovanov399 marked this conversation as resolved.
Show resolved Hide resolved
RUN_E2E=true
fi
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
LABELS='${{ toJson(github.event.pull_request.labels) }}'
RUN_E2E=$(echo "$LABELS" | jq 'any(.name == "run-cli-e2e")')
fi
if [ ! -z $RUN_E2E ]; then
cargo axiom build --manifest-dir ../axvm-sdk/example --transpile --transpiler-config example/app_config.toml --transpile-to /tmp/example.axvmexe
cargo axiom keygen --config example/app_config.toml --output /tmp/example.pk --vk-output /tmp/example.vk
cargo axiom run --exe /tmp/example.axvmexe --config example/app_config.toml
cargo axiom prove app --app-pk /tmp/example.pk --exe /tmp/example.axvmexe --output /tmp/example.apppf
cargo axiom verify app --app-vk /tmp/example.vk --proof /tmp/example.apppf
fi
9 changes: 7 additions & 2 deletions crates/axvm-sdk/src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
fs::{create_dir_all, write, File},
io::Write,
path::Path,
};

Expand All @@ -15,11 +16,15 @@ use crate::{
};

pub fn read_exe_from_file<P: AsRef<Path>>(path: P) -> Result<AxVmExe<F>> {
read_from_file_bson(path)
let data = std::fs::read(path)?;
let exe = bincode::serde::decode_from_slice(&data, bincode::config::standard())?.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look into if we can use one package (maybe bitcode) for everything. OK for now

Ok(exe)
}

pub fn write_exe_to_file<P: AsRef<Path>>(exe: AxVmExe<F>, path: P) -> Result<()> {
write_to_file_bson(path, exe)
let data = bincode::serde::encode_to_vec(&exe, bincode::config::standard())?;
File::create(path)?.write_all(&data)?;
Ok(())
}

pub fn read_app_pk_from_file<VC: VmConfig<F>, P: AsRef<Path>>(
Expand Down
45 changes: 27 additions & 18 deletions crates/cargo-axiom/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ use axvm_build::{
build_guest_package, find_unique_executable, get_package, GuestOptions, TargetFilter,
};
use axvm_rv32im_transpiler::{Rv32ITranspilerExtension, Rv32MTranspilerExtension};
use axvm_sdk::{fs::write_exe_to_file, Sdk};
use axvm_sdk::{
config::{AppConfig, SdkVmConfig},
fs::write_exe_to_file,
Sdk,
};
use axvm_transpiler::{axvm_platform::memory::MEM_SIZE, elf::Elf, transpiler::Transpiler};
use clap::Parser;
use eyre::Result;

use crate::util::read_to_struct_toml;

#[derive(Parser)]
#[command(name = "build", about = "Compile an axVM program")]
pub struct BuildCmd {
Expand Down Expand Up @@ -49,9 +55,13 @@ pub struct BuildArgs {
#[arg(long, default_value = "false")]
pub transpile: bool,

/// Path to the SDK config .toml file that specifies the transpiler extensions
#[arg(long)]
pub transpiler_config: Option<PathBuf>,

/// Output path for the transpiled program (default: <ELF base path>.axvmexe)
#[arg(long)]
pub transpile_path: Option<PathBuf>,
pub transpile_to: Option<PathBuf>,

/// Build profile
#[arg(long, default_value = "release")]
Expand All @@ -60,7 +70,7 @@ pub struct BuildArgs {

impl BuildArgs {
pub fn exe_path(&self, elf_path: &Path) -> PathBuf {
self.transpile_path
self.transpile_to
.clone()
.unwrap_or_else(|| elf_path.with_extension("axvmexe"))
}
Expand Down Expand Up @@ -116,7 +126,20 @@ pub(crate) fn build(build_args: &BuildArgs) -> Result<Option<PathBuf>> {
let elf_path = elf_path?;
println!("[axiom] Transpiling the package...");
let output_path = build_args.exe_path(&elf_path);
transpile(elf_path.clone(), output_path.clone())?;
let transpiler = if let Some(transpiler_config) = build_args.transpiler_config.clone() {
let app_config: AppConfig<SdkVmConfig> = read_to_struct_toml(&transpiler_config)?;
app_config.app_vm_config.transpiler()
} else {
Transpiler::default()
.with_extension(Rv32ITranspilerExtension)
.with_extension(Rv32MTranspilerExtension)
};

let data = read(elf_path.clone())?;
let elf = Elf::decode(&data, MEM_SIZE as u32)?;
let exe = Sdk.transpile(elf, transpiler)?;
write_exe_to_file(exe, &output_path)?;

println!(
"[axiom] Successfully transpiled to {}",
output_path.display()
Expand All @@ -133,17 +156,3 @@ pub(crate) fn build(build_args: &BuildArgs) -> Result<Option<PathBuf>> {
Ok(None)
}
}

fn transpile(elf_path: PathBuf, output_path: PathBuf) -> Result<()> {
let data = read(elf_path.clone())?;
let elf = Elf::decode(&data, MEM_SIZE as u32)?;
let exe = Sdk.transpile(
elf,
Transpiler::default()
.with_extension(Rv32ITranspilerExtension)
.with_extension(Rv32MTranspilerExtension),
)?;
write_exe_to_file(exe, &output_path)?;
eprintln!("Successfully transpiled to {}", output_path.display());
Ok(())
}