diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 206af61..6e6d5b1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,10 +23,10 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 15 env: - # warn when test takes more than 3s, kill after 6s - RUST_TEST_TIME_UNIT: "3000,6000" - RUST_TEST_TIME_INTEGRATION: "3000,6000" - RUST_TEST_TIME_DOCTEST: "3000,6000" + # warn when test takes more than 5s, kill after 10s + RUST_TEST_TIME_UNIT: "5000,10000" + RUST_TEST_TIME_INTEGRATION: "5000,10000" + RUST_TEST_TIME_DOCTEST: "5000,10000" steps: - uses: actions/checkout@v3 - uses: ./.github/actions/deps diff --git a/proto-compiler/src/functions.rs b/proto-compiler/src/functions.rs index 33b6a56..59bc118 100644 --- a/proto-compiler/src/functions.rs +++ b/proto-compiler/src/functions.rs @@ -247,6 +247,7 @@ pub fn generate_tenderdash_lib( tenderdash_lib_target: &Path, abci_ver: &str, td_ver: &str, + module_name: &str, ) { let mut file_names = WalkDir::new(prost_dir) .into_iter() @@ -276,11 +277,7 @@ pub fn generate_tenderdash_lib( let mut tab_count = parts.len(); - let mut inner_content = format!( - "{}include!(\"prost/{}\");", - tab.repeat(tab_count), - file_name - ); + let mut inner_content = format!("{}include!(\"./{}\");", tab.repeat(tab_count), file_name); for part in parts { tab_count -= 1; @@ -304,6 +301,8 @@ pub mod meta {{ pub const ABCI_VERSION: &str = \"{}\"; /// Version of Tenderdash server used to generate protobuf configs pub const TENDERDASH_VERSION: &str = \"{}\"; + /// Name of module where generated files are stored; used to distinguish between std and no-std version + pub const TENDERDASH_MODULE_NAME: &str = \"{}\"; }} ", content, @@ -311,6 +310,7 @@ pub mod meta {{ tenderdash_commitish(), abci_ver, td_ver, + module_name, ); let mut file = @@ -348,10 +348,12 @@ pub(crate) fn save_state(dir: &Path, commitish: &str) { pub(crate) fn check_state(dir: &Path, commitish: &str) -> bool { let state_file = PathBuf::from(&dir).join("download.state"); + let expected = commitish.to_string(); + match read_to_string(state_file) { Ok(content) => { - println!("[info] => Detected Tenderdash version: {}.", content.trim()); - content.eq(commitish) + println!("[info] => Detected Tenderdash version: {}.", content); + content == expected }, Err(_) => false, } diff --git a/proto-compiler/src/lib.rs b/proto-compiler/src/lib.rs index 483ec25..4d02afa 100644 --- a/proto-compiler/src/lib.rs +++ b/proto-compiler/src/lib.rs @@ -18,16 +18,15 @@ use crate::functions::{check_state, save_state}; /// Checkouts tenderdash repository to ../target/tenderdash and generates /// Rust protobuf definitions in ../proto/src/prost/ and /// ../proto/src/tenderdash.rs -pub fn proto_compile() { +/// +/// # Arguments +/// +/// * `module_name` - name of module to put generated files into +pub fn proto_compile(module_name: &str) { let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let tenderdash_lib_target = root - .join("..") - .join("proto") - .join("src") - .join("tenderdash.rs"); - - let prost_out_dir = root.join("..").join("proto").join("src").join("prost"); + let prost_out_dir = root.join("..").join("proto").join("src").join(module_name); + let tenderdash_lib_target = prost_out_dir.join("mod.rs"); let out_dir = var("OUT_DIR") .map(PathBuf::from) @@ -121,7 +120,13 @@ pub fn proto_compile() { println!("[info] => Removing old structs and copying new structs."); copy_files(&out_dir, &prost_out_dir); // This panics if it fails. - generate_tenderdash_lib(&out_dir, &tenderdash_lib_target, &abci_ver, &tenderdash_ver); + generate_tenderdash_lib( + &out_dir, + &tenderdash_lib_target, + &abci_ver, + &tenderdash_ver, + module_name, + ); save_state(&prost_out_dir, &commitish); println!("[info] => Done!"); diff --git a/proto/build.rs b/proto/build.rs index 8ddf011..0e6b055 100644 --- a/proto/build.rs +++ b/proto/build.rs @@ -11,7 +11,10 @@ fn main() { env::set_var("TENDERDASH_COMMITISH", DEFAULT_VERSION); } - tenderdash_proto_compiler::proto_compile(); + #[cfg(feature = "std")] + tenderdash_proto_compiler::proto_compile("tenderdash_std"); + #[cfg(not(feature = "std"))] + tenderdash_proto_compiler::proto_compile("tenderdash_nostd"); println!("cargo:rerun-if-changed=../proto-compiler/src"); println!("cargo:rerun-if-changed=Cargo.toml"); diff --git a/proto/src/.gitignore b/proto/src/.gitignore index 3cc990e..2a145fb 100644 --- a/proto/src/.gitignore +++ b/proto/src/.gitignore @@ -1,2 +1,6 @@ +tenderdash_nostd/ +tenderdash_std/ + +# prost/ and tenderdash.rs are deprecated and can be removed in the future prost/ tenderdash.rs diff --git a/proto/src/lib.rs b/proto/src/lib.rs index ca3ad64..f62ca63 100644 --- a/proto/src/lib.rs +++ b/proto/src/lib.rs @@ -20,8 +20,6 @@ pub mod google { } mod error; -#[allow(warnings)] -mod tenderdash; #[cfg(not(feature = "std"))] use core::{ @@ -34,12 +32,22 @@ use std::fmt::Display; use bytes::{Buf, BufMut}; pub use error::Error; use prost::{encoding::encoded_len_varint, Message}; -pub use tenderdash::*; +#[cfg(not(feature = "std"))] +#[rustfmt::skip] +pub mod tenderdash_nostd; +#[cfg(not(feature = "std"))] +pub use tenderdash_nostd::*; + +#[cfg(feature = "std")] +#[rustfmt::skip] +pub mod tenderdash_std; +#[cfg(feature = "std")] +pub use tenderdash_std::*; pub mod serializers; +pub use meta::ABCI_VERSION; use prelude::*; -pub use tenderdash::meta::ABCI_VERSION; #[cfg(feature = "grpc")] pub use tonic;