diff --git a/crates/build/src/build.rs b/crates/build/src/build.rs index 37ee7392ac..03858133e3 100644 --- a/crates/build/src/build.rs +++ b/crates/build/src/build.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use anyhow::Result; use cargo_metadata::camino::Utf8PathBuf; @@ -54,9 +54,9 @@ pub fn execute_build_program( } /// Internal helper function to build the program with or without arguments. -pub(crate) fn build_program_internal(path: &str, args: Option) { +pub(crate) fn build_program_internal(path: impl AsRef, args: Option) { // Get the root package name and metadata. - let program_dir = std::path::Path::new(path); + let program_dir = path.as_ref().to_path_buf(); let metadata_file = program_dir.join("Cargo.toml"); let mut metadata_cmd = cargo_metadata::MetadataCommand::new(); let metadata = metadata_cmd.manifest_path(metadata_file).exec().unwrap(); @@ -83,7 +83,7 @@ pub(crate) fn build_program_internal(path: &str, args: Option) { } // Activate the build command if the dependencies change. - cargo_rerun_if_changed(&metadata, program_dir); + cargo_rerun_if_changed(&metadata, &program_dir); // Check if RUSTC_WORKSPACE_WRAPPER is set to clippy-driver (i.e. if `cargo clippy` is the // current compiler). If so, don't execute `cargo prove build` because it breaks diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index 1dbbec1347..d90c153033 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -4,6 +4,8 @@ mod utils; use build::build_program_internal; pub use build::{execute_build_program, generate_elf_paths}; +use std::path::Path; + use clap::Parser; const BUILD_TARGET: &str = "riscv32im-succinct-zkvm-elf"; @@ -104,13 +106,19 @@ impl Default for BuildArgs { /// /// # Arguments /// -/// * `path` - A string slice that holds the path to the program directory. +/// * `path` - A path to the guest program directory, if not absolute, assumed to be relative to +/// the caller manifest directory. /// /// This function is useful for automatically rebuilding the program during development /// when changes are made to the source code or its dependencies. /// /// Set the `SP1_SKIP_PROGRAM_BUILD` environment variable to `true` to skip building the program. -pub fn build_program(path: &str) { +/// +/// +/// ## Note: Using this function without an absolute path is not recommended. +/// Try using the `build_program_from_path!` macro instead. +#[deprecated(note = "Please use `build_program_from_path!` macro instead.")] +pub fn build_program(path: impl AsRef) { build_program_internal(path, None) } @@ -119,14 +127,63 @@ pub fn build_program(path: &str) { /// /// # Arguments /// -/// * `path` - A string slice that holds the path to the program directory. +/// * `path` - A path to the guest program directory. +/// /// * `args` - A [`BuildArgs`] struct that contains various build configuration options. /// /// Set the `SP1_SKIP_PROGRAM_BUILD` environment variable to `true` to skip building the program. -pub fn build_program_with_args(path: &str, args: BuildArgs) { +/// +/// ## Note: Using this function without an absolute path is not recommended. +/// Try using the `build_program_from_path!` macro instead. +#[deprecated(note = "Please use `build_program_from_path!` macro instead.")] +pub fn build_program_with_args(path: impl AsRef, args: BuildArgs) { build_program_internal(path, Some(args)) } +/// Builds the program with the given arguments if the program at path, or one of its dependencies, +/// +/// ### Note: +/// This function is only exposed to support the `build_program_from_path!` macro. +/// It is not recommended to use this function directly. +#[doc(hidden)] +pub fn build_program_with_maybe_args(path: impl AsRef, args: Option) { + build_program_internal(path, args) +} + +/// Build a program at the given path. +/// +/// # Arguments +/// * `path` - A path to the guest program directory, if not absolute, assumed to be relative to +/// the callers manifest directory. +/// +/// `args` - A [`BuildArgs`] struct that contains various build configuration options. +/// If not provided, the default options are used. +#[macro_export] +macro_rules! build_program_from_path { + ($path:expr, $args:expr) => { + // Scope to avoid polluting the macro namespace. + { + // Inline this crates manifest path at compile time. + const MANIFEST: &str = std::env!("CARGO_MANIFEST_DIR"); + + // Adjust the path to be relative to the manifest directory, unless its absolute. + fn ___adjust_path(p: impl AsRef<::std::path::Path>) -> ::std::path::PathBuf { + let p = p.as_ref(); + if p.is_absolute() { + p.to_path_buf() + } else { + ::std::path::Path::new(MANIFEST).join(p) + } + } + + ::sp1_build::build_program_with_maybe_args(___adjust_path($path), $args) + } + }; + ($path:expr) => { + ::sp1_build::build_program_from_path!($path, None) + }; +} + /// Returns the raw ELF bytes by the zkVM program target name. /// /// Note that this only works when using `sp1_build::build_program` or diff --git a/examples/Cargo.lock b/examples/Cargo.lock index 53dd96cfd5..eae6798d95 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -219,7 +219,7 @@ dependencies = [ "alloy-sol-types", "serde", "serde_json", - "thiserror", + "thiserror 1.0.68", "tracing", ] @@ -241,7 +241,7 @@ dependencies = [ "async-trait", "auto_impl", "futures-utils-wasm", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -426,7 +426,7 @@ dependencies = [ "auto_impl", "elliptic-curve", "k256", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -442,7 +442,7 @@ dependencies = [ "async-trait", "k256", "rand 0.8.5", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -1155,7 +1155,7 @@ dependencies = [ "semver 1.0.23", "serde", "serde_json", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -1377,6 +1377,15 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-deque" version = "0.8.5" @@ -1834,7 +1843,7 @@ dependencies = [ "rand_core 0.6.4", "serde", "sha2 0.9.9", - "thiserror", + "thiserror 1.0.68", "zeroize", ] @@ -3846,7 +3855,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442" dependencies = [ "memchr", - "thiserror", + "thiserror 1.0.68", "ucd-trie", ] @@ -4106,7 +4115,7 @@ dependencies = [ "rustc-hash 2.0.0", "rustls", "socket2", - "thiserror", + "thiserror 1.0.68", "tokio", "tracing", ] @@ -4123,7 +4132,7 @@ dependencies = [ "rustc-hash 2.0.0", "rustls", "slab", - "thiserror", + "thiserror 1.0.68", "tinyvec", "tracing", ] @@ -4289,7 +4298,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -4407,7 +4416,7 @@ dependencies = [ "http", "reqwest", "serde", - "thiserror", + "thiserror 1.0.68", "tower-service", ] @@ -4420,7 +4429,7 @@ dependencies = [ "reth-execution-errors", "reth-primitives", "reth-storage-errors", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -4514,7 +4523,7 @@ dependencies = [ "reth-execution-errors", "reth-fs-util", "reth-storage-errors", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -4598,7 +4607,7 @@ dependencies = [ "reth-revm", "revm", "revm-primitives", - "thiserror", + "thiserror 1.0.68", "tracing", ] @@ -4637,7 +4646,7 @@ source = "git+https://github.com/sp1-patches/reth?tag=rsp-20240830#260c7ed2c9374 dependencies = [ "serde", "serde_json", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -4649,7 +4658,7 @@ dependencies = [ "alloy-rlp", "enr", "serde_with", - "thiserror", + "thiserror 1.0.68", "url", ] @@ -4706,7 +4715,7 @@ dependencies = [ "reth-trie-common", "revm-primitives", "serde", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -4741,7 +4750,7 @@ dependencies = [ "modular-bitfield", "reth-codecs", "serde", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -5090,7 +5099,7 @@ dependencies = [ "rlp", "rsp-primitives", "serde", - "thiserror", + "thiserror 1.0.68", ] [[package]] @@ -5713,7 +5722,7 @@ dependencies = [ "sp1-stark", "strum", "strum_macros", - "thiserror", + "thiserror 1.0.68", "tiny-keccak", "tracing", "typenum", @@ -5758,7 +5767,7 @@ dependencies = [ "strum", "strum_macros", "tempfile", - "thiserror", + "thiserror 1.0.68", "tracing", "tracing-forest", "tracing-subscriber", @@ -5888,8 +5897,9 @@ dependencies = [ "sp1-recursion-core", "sp1-recursion-gnark-ffi", "sp1-stark", - "thiserror", + "thiserror 1.0.68", "tracing", + "tracing-appender", "tracing-subscriber", ] @@ -5973,7 +5983,7 @@ dependencies = [ "sp1-primitives", "sp1-stark", "static_assertions", - "thiserror", + "thiserror 1.0.68", "tracing", "vec_map", "zkhash", @@ -6046,7 +6056,7 @@ dependencies = [ "strum", "strum_macros", "tempfile", - "thiserror", + "thiserror 1.0.68", "tokio", "tracing", "twirp-rs", @@ -6093,7 +6103,7 @@ dependencies = [ "lazy_static", "sha2 0.10.8", "substrate-bn-succinct", - "thiserror-no-std", + "thiserror 2.0.3", ] [[package]] @@ -6488,7 +6498,16 @@ version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.68", +] + +[[package]] +name = "thiserror" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +dependencies = [ + "thiserror-impl 2.0.3", ] [[package]] @@ -6502,6 +6521,17 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "thiserror-impl" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "thiserror-impl-no-std" version = "2.0.2" @@ -6729,6 +6759,18 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-appender" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf" +dependencies = [ + "crossbeam-channel", + "thiserror 1.0.68", + "time", + "tracing-subscriber", +] + [[package]] name = "tracing-attributes" version = "0.1.27" @@ -6758,7 +6800,7 @@ checksum = "ee40835db14ddd1e3ba414292272eddde9dad04d3d4b65509656414d1c42592f" dependencies = [ "ansi_term", "smallvec", - "thiserror", + "thiserror 1.0.68", "tracing", "tracing-subscriber", ] @@ -6814,7 +6856,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "thiserror", + "thiserror 1.0.68", "tokio", "tower", "url", diff --git a/examples/aggregation/script/build.rs b/examples/aggregation/script/build.rs index 7e10aecc5a..0afcda6871 100644 --- a/examples/aggregation/script/build.rs +++ b/examples/aggregation/script/build.rs @@ -1,4 +1,4 @@ fn main() { - sp1_build::build_program("../program"); - sp1_build::build_program("../../fibonacci/program"); + sp1_build::build_program_from_path!("../program"); + sp1_build::build_program_from_path!("../../fibonacci/program"); } diff --git a/examples/bls12381/script/build.rs b/examples/bls12381/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/bls12381/script/build.rs +++ b/examples/bls12381/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/bn254/script/build.rs b/examples/bn254/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/bn254/script/build.rs +++ b/examples/bn254/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/chess/script/build.rs b/examples/chess/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/chess/script/build.rs +++ b/examples/chess/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/cycle-tracking/script/build.rs b/examples/cycle-tracking/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/cycle-tracking/script/build.rs +++ b/examples/cycle-tracking/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/fibonacci/script/build.rs b/examples/fibonacci/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/fibonacci/script/build.rs +++ b/examples/fibonacci/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/groth16/script/build.rs b/examples/groth16/script/build.rs index 7e10aecc5a..0afcda6871 100644 --- a/examples/groth16/script/build.rs +++ b/examples/groth16/script/build.rs @@ -1,4 +1,4 @@ fn main() { - sp1_build::build_program("../program"); - sp1_build::build_program("../../fibonacci/program"); + sp1_build::build_program_from_path!("../program"); + sp1_build::build_program_from_path!("../../fibonacci/program"); } diff --git a/examples/io/script/build.rs b/examples/io/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/io/script/build.rs +++ b/examples/io/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/is-prime/script/build.rs b/examples/is-prime/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/is-prime/script/build.rs +++ b/examples/is-prime/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/json/script/build.rs b/examples/json/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/json/script/build.rs +++ b/examples/json/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/patch-testing/script/build.rs b/examples/patch-testing/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/patch-testing/script/build.rs +++ b/examples/patch-testing/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/regex/script/build.rs b/examples/regex/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/regex/script/build.rs +++ b/examples/regex/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/rsa/script/build.rs b/examples/rsa/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/rsa/script/build.rs +++ b/examples/rsa/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/rsp/script/build.rs b/examples/rsp/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/rsp/script/build.rs +++ b/examples/rsp/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/ssz-withdrawals/script/build.rs b/examples/ssz-withdrawals/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/ssz-withdrawals/script/build.rs +++ b/examples/ssz-withdrawals/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); } diff --git a/examples/tendermint/script/build.rs b/examples/tendermint/script/build.rs index 7ecab5512f..a5fdee8011 100644 --- a/examples/tendermint/script/build.rs +++ b/examples/tendermint/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program("../program"); + sp1_build::build_program_from_path!("../program"); }