Skip to content

Commit

Permalink
Merge pull request #295 from athenavm/remove-helper-crate
Browse files Browse the repository at this point in the history
remove `athena-helper` crate
  • Loading branch information
poszu authored Jan 3, 2025
2 parents 4fbcdef + 7cb478a commit 9af534b
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 79 deletions.
20 changes: 8 additions & 12 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ members = [
"ffi/athcon/bindings/rust/athcon-sys",
"ffi/athcon/bindings/rust/athcon-vm",
"ffi/vmlib",
"helper",
"interface",
"runner",
"sdk",
Expand Down
3 changes: 1 addition & 2 deletions builder/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# athena-builder

Lightweight crate used to build Athena programs. Internal crate that is exposed to users via `athena-cli` and
`athena-helper`.
A crate used to build Athena programs. It can be used directly or via the `athena-cli`.

Exposes `build_program`, which builds an Athena program in the local environment or in a docker container with the
specified parameters from `BuildArgs`.
Expand Down
5 changes: 3 additions & 2 deletions helper/src/lib.rs → builder/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pub use athena_builder::BuildArgs;
use cargo_metadata::Metadata;
use std::path::Path;

use crate::BuildArgs;

/// Re-run the cargo command if the Cargo.toml or Cargo.lock file changes.
fn cargo_rerun_if_changed(metadata: &Metadata, program_dir: &Path) {
// Tell cargo to rerun the script only if program/{src, bin, build.rs, Cargo.toml} changes
Expand Down Expand Up @@ -51,7 +52,7 @@ fn execute_build_cmd(program_dir: &impl AsRef<std::path::Path>, args: Option<Bui
return;
}

athena_builder::build_program(
crate::build_program(
&args.unwrap_or_default(),
Some(program_dir.as_ref().to_path_buf()),
)
Expand Down
4 changes: 2 additions & 2 deletions builder/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod build;
mod docker;

use clap::Parser;
Expand Down Expand Up @@ -259,8 +260,7 @@ fn copy_elf_to_output_dir(
Ok(result_elf_path)
}

/// Build a program with the specified [`BuildArgs`]. The `program_dir` is specified as an argument when
/// the program is built via `build_program` in athena-helper.
/// Build a program with the specified [`BuildArgs`].
///
/// # Arguments
///
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ debug = []
unittest = []

[build-dependencies]
athena-helper = { path = "../helper" }
athena-builder = { path = "../builder/" }
6 changes: 1 addition & 5 deletions core/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
#[cfg(feature = "unittest")]
fn build_programs_for_tests() {
use athena_helper::build_program;
use athena_builder::build::build_program;

build_program("../examples/fibonacci/program");
build_program("../examples/hello_world/program");
build_program("../examples/io/program");
build_program("../examples/wallet/program");
build_program("../tests/host");
build_program("../tests/panic");
}

Expand Down
20 changes: 6 additions & 14 deletions examples/Cargo.lock

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

4 changes: 2 additions & 2 deletions examples/fibonacci/program/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub fn main() {
athena_vm::io::write(&n);

// Compute the n'th fibonacci number, using normal Rust code.
let mut a = 0;
let mut b = 1;
let mut a = 0u32;
let mut b = 1u32;
for _ in 0..n {
let mut c = a + b;
c %= 7919; // Modulus to prevent overflow.
Expand Down
2 changes: 1 addition & 1 deletion examples/fibonacci/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ athena-sdk = { path = "../../../sdk" }
tracing-subscriber = "0.3.18"

[build-dependencies]
athena-helper = { path = "../../../helper" }
athena-builder = { path = "../../../builder" }

[[bin]]
name = "fibonacci-script"
Expand Down
2 changes: 1 addition & 1 deletion examples/fibonacci/script/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
athena_helper::build_program(&format!("{}/../program", env!("CARGO_MANIFEST_DIR")));
athena_builder::build::build_program(&format!("{}/../program", env!("CARGO_MANIFEST_DIR")));
}
2 changes: 1 addition & 1 deletion examples/hello_world/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ athena-sdk = { path = "../../../sdk" }
tracing-subscriber = "0.3.18"

[build-dependencies]
athena-helper = { path = "../../../helper" }
athena-builder = { path = "../../../builder" }
2 changes: 1 addition & 1 deletion examples/hello_world/script/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
athena_helper::build_program(&format!("{}/../program", env!("CARGO_MANIFEST_DIR")));
athena_builder::build::build_program(&format!("{}/../program", env!("CARGO_MANIFEST_DIR")));
}
2 changes: 1 addition & 1 deletion examples/io/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ athena-sdk = { path = "../../../sdk" }
tracing-subscriber = "0.3.18"

[build-dependencies]
athena-helper = { path = "../../../helper" }
athena-builder = { path = "../../../builder" }
2 changes: 1 addition & 1 deletion examples/io/script/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
athena_helper::build_program(&format!("{}/../program", env!("CARGO_MANIFEST_DIR")));
athena_builder::build::build_program(&format!("{}/../program", env!("CARGO_MANIFEST_DIR")));
}
2 changes: 1 addition & 1 deletion examples/wallet/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ ed25519-dalek = { version = "2.1.1", features = ["rand_core"] }
rand = "0.8.5"

[build-dependencies]
athena-helper = { path = "../../../helper" }
athena-builder = { path = "../../../builder" }
4 changes: 1 addition & 3 deletions examples/wallet/script/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use athena_helper::build_program;

fn main() {
build_program("../program")
athena_builder::build::build_program("../program")
}
9 changes: 9 additions & 0 deletions ffi/vmlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ athena-runner = { path = "../../runner" }
athcon-sys = { path = "../athcon/bindings/rust/athcon-sys" }
athcon-vm = { path = "../athcon/bindings/rust/athcon-vm" }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }

[dev-dependencies]
athena-vmlib = { path = ".", features = ["unittest"] }

[build-dependencies]
athena-builder = { path = "../../builder" }

[features]
unittest = []
3 changes: 3 additions & 0 deletions ffi/vmlib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ fn main() {
println!("cargo:rustc-link-arg=-undefined");
println!("cargo:rustc-link-arg=dynamic_lookup");
}

#[cfg(feature = "unittest")]
athena_builder::build::build_program("../../examples/hello_world/program");
}
12 changes: 0 additions & 12 deletions helper/Cargo.toml

This file was deleted.

2 changes: 1 addition & 1 deletion runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ athena-runner = { path = ".", features = ["unittest"] }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }

[build-dependencies]
athena-helper = { path = "../helper" }
athena-builder = { path = "../builder" }

[features]
unittest = []
3 changes: 2 additions & 1 deletion runner/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#[cfg(feature = "unittest")]
fn build_programs_for_tests() {
use athena_helper::build_program;
use athena_builder::build::build_program;
build_program("../tests/entrypoint");
build_program("../tests/recursive_call");
}

fn main() {
Expand Down
6 changes: 5 additions & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ athena-core = { path = "../core" }
athena-interface = { path = "../interface" }

[build-dependencies]
anyhow = "1.0.95"
athena-builder = { path = "../builder" }
vergen-git2 = { version = "1.0.2", default-features = false, features = [
"build",
] }

[dev-dependencies]
athena-sdk = { path = ".", features = ["unittest"] }
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }

[features]
unittest = []
16 changes: 13 additions & 3 deletions sdk/build.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
use anyhow::Result;
use vergen_git2::{BuildBuilder, Emitter, Git2Builder};

fn main() -> Result<()> {
fn main() -> Result<(), Box<dyn std::error::Error>> {
let build = BuildBuilder::default().build_timestamp(true).build()?;
let git2 = Git2Builder::default().sha(true).build()?;

Emitter::default()
.add_instructions(&build)?
.add_instructions(&git2)?
.emit()?;
.emit()
.unwrap();

#[cfg(feature = "unittest")]
build_programs_for_tests();

Ok(())
}

#[cfg(feature = "unittest")]
fn build_programs_for_tests() {
athena_builder::build::build_program("../examples/fibonacci/program");
athena_builder::build::build_program("../tests/panic");
}
Loading

0 comments on commit 9af534b

Please sign in to comment.