From 361428f21f426ccbeee293d7972bce3860a6772d Mon Sep 17 00:00:00 2001 From: nhtyy Date: Mon, 25 Nov 2024 13:50:29 -0800 Subject: [PATCH 01/10] fix: not absoulte paths are relative to the build manifest --- crates/build/src/build.rs | 18 ++++++++++++++---- crates/build/src/lib.rs | 6 ++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/crates/build/src/build.rs b/crates/build/src/build.rs index 37ee7392ac..ff2137a778 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,19 @@ 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) { +/// +/// If the path is not absolute, it is assumed to be relative to the `CARGO_MANIFEST_DIR`. +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); + // + // Note: + // You _MUST_ read the `CARGO_MANIFEST_DIR` at runtime (`std::env::var` as opposed to `env!`). + // Othewise it will be the manifest dir of this crate, not the caller. + let mut program_dir = path.as_ref().to_path_buf(); + if program_dir.is_relative() { + program_dir = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).join(program_dir); + } + 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 +93,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..6106ce28a8 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"; @@ -110,7 +112,7 @@ impl Default for BuildArgs { /// 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) { +pub fn build_program(path: impl AsRef) { build_program_internal(path, None) } @@ -123,7 +125,7 @@ pub fn build_program(path: &str) { /// * `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) { +pub fn build_program_with_args(path: impl AsRef, args: BuildArgs) { build_program_internal(path, Some(args)) } From 40846e608849d4d1c1e0e9e771f50f5c0a197147 Mon Sep 17 00:00:00 2001 From: nhtyy Date: Mon, 25 Nov 2024 13:54:42 -0800 Subject: [PATCH 02/10] chore: comments --- crates/build/src/build.rs | 2 +- crates/build/src/lib.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/crates/build/src/build.rs b/crates/build/src/build.rs index ff2137a778..6e25ecc0f1 100644 --- a/crates/build/src/build.rs +++ b/crates/build/src/build.rs @@ -61,7 +61,7 @@ pub(crate) fn build_program_internal(path: impl AsRef, args: Option) { /// /// # 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. +/// /// * `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. From fa3129e262ab65908445669e317b8df7ad40535f Mon Sep 17 00:00:00 2001 From: nhtyy Date: Mon, 25 Nov 2024 14:45:11 -0800 Subject: [PATCH 03/10] fix: build macro --- crates/build/src/build.rs | 12 +----------- crates/build/src/lib.rs | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/crates/build/src/build.rs b/crates/build/src/build.rs index 6e25ecc0f1..03858133e3 100644 --- a/crates/build/src/build.rs +++ b/crates/build/src/build.rs @@ -54,19 +54,9 @@ pub fn execute_build_program( } /// Internal helper function to build the program with or without arguments. -/// -/// If the path is not absolute, it is assumed to be relative to the `CARGO_MANIFEST_DIR`. pub(crate) fn build_program_internal(path: impl AsRef, args: Option) { // Get the root package name and metadata. - // - // Note: - // You _MUST_ read the `CARGO_MANIFEST_DIR` at runtime (`std::env::var` as opposed to `env!`). - // Otherwise it will be the manifest dir of this crate, not the caller. - let mut program_dir = path.as_ref().to_path_buf(); - if program_dir.is_relative() { - program_dir = Path::new(&std::env::var("CARGO_MANIFEST_DIR").unwrap()).join(program_dir); - } - + 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(); diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index 74ebfdaf94..2415b72ad6 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -132,6 +132,43 @@ 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. +pub fn build_program_with_maybe_args(path: impl AsRef, args: Option) { + build_program_internal(path, args) +} + +/// Build a program with the given _RELATIVE_ path. +/// +/// # Arguments +/// * `path` - A path to the guest program directory, if not absolute, assumed to be relative to +/// the caller 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) => { + const MANIFEST: &str = std::env!("CARGO_MANIFEST_DIR"); + + 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 From 1821023df0aa20db5f89e42d0262bcedafda5197 Mon Sep 17 00:00:00 2001 From: nhtyy Date: Mon, 25 Nov 2024 14:58:26 -0800 Subject: [PATCH 04/10] fix: comments --- crates/build/src/lib.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index 2415b72ad6..6c86315bb5 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -113,6 +113,10 @@ impl Default for BuildArgs { /// 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. +/// +/// +/// ## Note: Using this function without an absolute path is not recommended. +/// Try using the `build_program_from_path!` macro instead. pub fn build_program(path: impl AsRef) { build_program_internal(path, None) } @@ -122,12 +126,14 @@ pub fn build_program(path: impl AsRef) { /// /// # Arguments /// -/// * `path` - A path to the guest program directory, if not absolute, assumed to be relative to -/// the caller manifest 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. +/// +/// ## Note: Using this function without an absolute path is not recommended. +/// Try using the `build_program_from_path!` macro instead. pub fn build_program_with_args(path: impl AsRef, args: BuildArgs) { build_program_internal(path, Some(args)) } @@ -140,11 +146,11 @@ pub fn build_program_with_maybe_args(path: impl AsRef, args: Option { const MANIFEST: &str = std::env!("CARGO_MANIFEST_DIR"); - fn adjust_path(p: impl AsRef<::std::path::Path>) -> ::std::path::PathBuf { + 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() @@ -166,7 +172,7 @@ macro_rules! build_program_from_path { }; ($path:expr) => { ::sp1_build::build_program_from_path!($path, None) - } + }; } /// Returns the raw ELF bytes by the zkVM program target name. From 31ea7878aa506751ab09525ba50751efa06ab6a4 Mon Sep 17 00:00:00 2001 From: nhtyy Date: Mon, 25 Nov 2024 14:59:32 -0800 Subject: [PATCH 05/10] fix: potential for namespace collisions --- crates/build/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index 6c86315bb5..026b7be963 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -159,7 +159,7 @@ macro_rules! build_program_from_path { ($path:expr, $args:expr) => { const MANIFEST: &str = std::env!("CARGO_MANIFEST_DIR"); - fn adjust_path(p: impl AsRef<::std::path::Path>) -> ::std::path::PathBuf { + 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() @@ -168,7 +168,7 @@ macro_rules! build_program_from_path { } } - ::sp1_build::build_program_with_maybe_args(adjust_path($path), $args) + ::sp1_build::build_program_with_maybe_args(___adjust_path($path), $args) }; ($path:expr) => { ::sp1_build::build_program_from_path!($path, None) From 12eb5108a2118c51afa9cb60917feca1afbb5a0c Mon Sep 17 00:00:00 2001 From: nhtyy Date: Mon, 25 Nov 2024 15:38:15 -0800 Subject: [PATCH 06/10] fix: cargo thinks its a doc test --- crates/build/src/lib.rs | 5 +- examples/Cargo.lock | 98 +++++++++++++++++++++--------- examples/fibonacci/script/build.rs | 2 +- 3 files changed, 74 insertions(+), 31 deletions(-) diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index 026b7be963..a929f84c82 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -140,8 +140,9 @@ pub fn build_program_with_args(path: impl AsRef, args: BuildArgs) { /// 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. +/// ### Note: +/// This function is only exposed to support the `build_program_from_path!` macro. +/// It is not recommended to use this function directly. pub fn build_program_with_maybe_args(path: impl AsRef, args: Option) { build_program_internal(path, args) } 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/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"); } From 447ce437893f09f5b376477243d18653e78de5a0 Mon Sep 17 00:00:00 2001 From: nhtyy Date: Mon, 25 Nov 2024 15:40:06 -0800 Subject: [PATCH 07/10] fix: restore examples to dev --- examples/Cargo.lock | 98 +++++++++--------------------- examples/fibonacci/script/build.rs | 2 +- 2 files changed, 29 insertions(+), 71 deletions(-) diff --git a/examples/Cargo.lock b/examples/Cargo.lock index eae6798d95..53dd96cfd5 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -219,7 +219,7 @@ dependencies = [ "alloy-sol-types", "serde", "serde_json", - "thiserror 1.0.68", + "thiserror", "tracing", ] @@ -241,7 +241,7 @@ dependencies = [ "async-trait", "auto_impl", "futures-utils-wasm", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -426,7 +426,7 @@ dependencies = [ "auto_impl", "elliptic-curve", "k256", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -442,7 +442,7 @@ dependencies = [ "async-trait", "k256", "rand 0.8.5", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -1155,7 +1155,7 @@ dependencies = [ "semver 1.0.23", "serde", "serde_json", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -1377,15 +1377,6 @@ 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" @@ -1843,7 +1834,7 @@ dependencies = [ "rand_core 0.6.4", "serde", "sha2 0.9.9", - "thiserror 1.0.68", + "thiserror", "zeroize", ] @@ -3855,7 +3846,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "879952a81a83930934cbf1786752d6dedc3b1f29e8f8fb2ad1d0a36f377cf442" dependencies = [ "memchr", - "thiserror 1.0.68", + "thiserror", "ucd-trie", ] @@ -4115,7 +4106,7 @@ dependencies = [ "rustc-hash 2.0.0", "rustls", "socket2", - "thiserror 1.0.68", + "thiserror", "tokio", "tracing", ] @@ -4132,7 +4123,7 @@ dependencies = [ "rustc-hash 2.0.0", "rustls", "slab", - "thiserror 1.0.68", + "thiserror", "tinyvec", "tracing", ] @@ -4298,7 +4289,7 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -4416,7 +4407,7 @@ dependencies = [ "http", "reqwest", "serde", - "thiserror 1.0.68", + "thiserror", "tower-service", ] @@ -4429,7 +4420,7 @@ dependencies = [ "reth-execution-errors", "reth-primitives", "reth-storage-errors", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -4523,7 +4514,7 @@ dependencies = [ "reth-execution-errors", "reth-fs-util", "reth-storage-errors", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -4607,7 +4598,7 @@ dependencies = [ "reth-revm", "revm", "revm-primitives", - "thiserror 1.0.68", + "thiserror", "tracing", ] @@ -4646,7 +4637,7 @@ source = "git+https://github.com/sp1-patches/reth?tag=rsp-20240830#260c7ed2c9374 dependencies = [ "serde", "serde_json", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -4658,7 +4649,7 @@ dependencies = [ "alloy-rlp", "enr", "serde_with", - "thiserror 1.0.68", + "thiserror", "url", ] @@ -4715,7 +4706,7 @@ dependencies = [ "reth-trie-common", "revm-primitives", "serde", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -4750,7 +4741,7 @@ dependencies = [ "modular-bitfield", "reth-codecs", "serde", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -5099,7 +5090,7 @@ dependencies = [ "rlp", "rsp-primitives", "serde", - "thiserror 1.0.68", + "thiserror", ] [[package]] @@ -5722,7 +5713,7 @@ dependencies = [ "sp1-stark", "strum", "strum_macros", - "thiserror 1.0.68", + "thiserror", "tiny-keccak", "tracing", "typenum", @@ -5767,7 +5758,7 @@ dependencies = [ "strum", "strum_macros", "tempfile", - "thiserror 1.0.68", + "thiserror", "tracing", "tracing-forest", "tracing-subscriber", @@ -5897,9 +5888,8 @@ dependencies = [ "sp1-recursion-core", "sp1-recursion-gnark-ffi", "sp1-stark", - "thiserror 1.0.68", + "thiserror", "tracing", - "tracing-appender", "tracing-subscriber", ] @@ -5983,7 +5973,7 @@ dependencies = [ "sp1-primitives", "sp1-stark", "static_assertions", - "thiserror 1.0.68", + "thiserror", "tracing", "vec_map", "zkhash", @@ -6056,7 +6046,7 @@ dependencies = [ "strum", "strum_macros", "tempfile", - "thiserror 1.0.68", + "thiserror", "tokio", "tracing", "twirp-rs", @@ -6103,7 +6093,7 @@ dependencies = [ "lazy_static", "sha2 0.10.8", "substrate-bn-succinct", - "thiserror 2.0.3", + "thiserror-no-std", ] [[package]] @@ -6498,16 +6488,7 @@ version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" dependencies = [ - "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", + "thiserror-impl", ] [[package]] @@ -6521,17 +6502,6 @@ 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" @@ -6759,18 +6729,6 @@ 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" @@ -6800,7 +6758,7 @@ checksum = "ee40835db14ddd1e3ba414292272eddde9dad04d3d4b65509656414d1c42592f" dependencies = [ "ansi_term", "smallvec", - "thiserror 1.0.68", + "thiserror", "tracing", "tracing-subscriber", ] @@ -6856,7 +6814,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "thiserror 1.0.68", + "thiserror", "tokio", "tower", "url", diff --git a/examples/fibonacci/script/build.rs b/examples/fibonacci/script/build.rs index a5fdee8011..7ecab5512f 100644 --- a/examples/fibonacci/script/build.rs +++ b/examples/fibonacci/script/build.rs @@ -1,3 +1,3 @@ fn main() { - sp1_build::build_program_from_path!("../program"); + sp1_build::build_program("../program"); } From bb9618c3dfe7b3dc390f433573892c59d843b7ad Mon Sep 17 00:00:00 2001 From: nhtyy Date: Mon, 25 Nov 2024 17:55:33 -0800 Subject: [PATCH 08/10] chore: examples use build macro --- crates/build/src/lib.rs | 25 ++++++++++++++---------- examples/aggregation/script/build.rs | 4 ++-- examples/bls12381/script/build.rs | 2 +- examples/bn254/script/build.rs | 2 +- examples/chess/script/build.rs | 2 +- examples/cycle-tracking/script/build.rs | 2 +- examples/fibonacci/script/build.rs | 2 +- examples/groth16/script/build.rs | 4 ++-- examples/io/script/build.rs | 2 +- examples/is-prime/script/build.rs | 2 +- examples/json/script/build.rs | 2 +- examples/patch-testing/script/build.rs | 2 +- examples/regex/script/build.rs | 2 +- examples/rsa/script/build.rs | 2 +- examples/rsp/script/build.rs | 2 +- examples/ssz-withdrawals/script/build.rs | 2 +- examples/tendermint/script/build.rs | 2 +- 17 files changed, 33 insertions(+), 28 deletions(-) diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index a929f84c82..376c8b6f9d 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -158,18 +158,23 @@ pub fn build_program_with_maybe_args(path: impl AsRef, args: Option { - const MANIFEST: &str = std::env!("CARGO_MANIFEST_DIR"); - - 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) + // 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) + ::sp1_build::build_program_with_maybe_args(___adjust_path($path), $args) + } }; ($path:expr) => { ::sp1_build::build_program_from_path!($path, None) 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"); } From 5b12300e64cf1caf560b2df8cb249a8704273231 Mon Sep 17 00:00:00 2001 From: nhtyy Date: Mon, 25 Nov 2024 17:59:22 -0800 Subject: [PATCH 09/10] fix: fmt + punc --- crates/build/src/lib.rs | 4 +- examples/Cargo.lock | 98 +++++++++++++++++++++++++++++------------ 2 files changed, 72 insertions(+), 30 deletions(-) diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index 376c8b6f9d..44005f76f7 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -126,7 +126,7 @@ pub fn build_program(path: impl AsRef) { /// /// # Arguments /// -/// * `path` - A path to the guest program directory +/// * `path` - A path to the guest program directory. /// /// * `args` - A [`BuildArgs`] struct that contains various build configuration options. /// @@ -162,7 +162,7 @@ macro_rules! build_program_from_path { { // 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(); 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", From 7a72ce2e0ed24e7f6cbdd4acffb3804f8d36d081 Mon Sep 17 00:00:00 2001 From: N Date: Tue, 26 Nov 2024 21:02:43 -0800 Subject: [PATCH 10/10] fix: deprecate old build fns --- crates/build/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/build/src/lib.rs b/crates/build/src/lib.rs index 44005f76f7..d90c153033 100644 --- a/crates/build/src/lib.rs +++ b/crates/build/src/lib.rs @@ -117,6 +117,7 @@ impl Default for 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(path: impl AsRef) { build_program_internal(path, None) } @@ -134,6 +135,7 @@ pub fn build_program(path: impl AsRef) { /// /// ## 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)) } @@ -143,6 +145,7 @@ pub fn build_program_with_args(path: impl AsRef, args: BuildArgs) { /// ### 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) }