From ecf49298ce0fa3c42f78a80276af2b3b884feeeb Mon Sep 17 00:00:00 2001 From: Sergei Blinov Date: Sun, 28 Jan 2024 23:23:11 +0100 Subject: [PATCH] remove common submodule + refactoring + fmt rules + ci --- .github/workflows/rust.yaml | 23 +++++++++++++++++++++++ .gitmodules | 4 ---- Cargo.toml | 24 ++++++++++++------------ build.rs | 24 ++++++++++++++++++++++++ common | 1 - rustfmt.toml | 26 ++++++++++++++++++++++++++ src/lib.rs | 4 +++- 7 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/rust.yaml delete mode 100644 .gitmodules create mode 100644 build.rs delete mode 160000 common create mode 100644 rustfmt.toml diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml new file mode 100644 index 0000000..c04296b --- /dev/null +++ b/.github/workflows/rust.yaml @@ -0,0 +1,23 @@ +on: [push, pull_request] + +name: Lint and Test + +jobs: + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly + with: + components: clippy, rustfmt + - run: cargo fmt --all -- --check + - run: cargo clippy -- -D warnings + + test: + name: Test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: cargo test --all-features diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 3827b53..0000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "common"] - path = common - url = https://github.com/tvmlabs/common - branch = main diff --git a/Cargo.toml b/Cargo.toml index c38a956..21fc9c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,23 @@ [package] -build = 'common/build/build.rs' -edition = '2021' -name = 'tvm_executor' -version = '1.16.99' +edition = "2021" +name = "tvm_executor" +rust-version = "1.75.0" +version = "2.0.0" [dependencies] -failure = '0.1.6' -lazy_static = '1.4' -log = '0.4' -tvm_block = { git = 'https://github.com/tvmlabs/tvm-block.git', branch = "main" } -tvm_types = { git = 'https://github.com/tvmlabs/tvm-types.git', branch = "main" } -tvm_vm = { git = 'https://github.com/tvmlabs/tvm-vm.git', branch = "main" } +failure = "0.1.6" +lazy_static = "1.4" +log = "0.4" +tvm_block = { git = "https://github.com/tvmlabs/tvm-block", branch = "main" } +tvm_types = { git = "https://github.com/tvmlabs/tvm-types", branch = "main" } +tvm_vm = { git = "https://github.com/tvmlabs/tvm-vm", branch = "main" } [features] -signature_with_id = [ 'tvm_block/signature_with_id', 'tvm_vm/signature_with_id' ] +signature_with_id = [ "tvm_block/signature_with_id", "tvm_vm/signature_with_id" ] [[bench]] harness = false -name = 'benchmarks' +name = "benchmarks" [lib] bench = false diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..20670f8 --- /dev/null +++ b/build.rs @@ -0,0 +1,24 @@ +use std::process::Command; + +fn get_value(cmd: &str, args: &[&str]) -> String { + if let Ok(result) = Command::new(cmd).args(args).output() { + if let Ok(result) = String::from_utf8(result.stdout) { + return result; + } + } + "Unknown".to_string() +} + +fn main() { + let git_branch = get_value("git", &["rev-parse", "--abbrev-ref", "HEAD"]); + let git_commit = get_value("git", &["rev-parse", "HEAD"]); + let commit_date = get_value("git", &["log", "-1", "--date=iso", "--pretty=format:%cd"]); + let build_time = get_value("date", &["+%Y-%m-%d %T %z"]); + let rust_version = get_value("rustc", &["--version"]); + + println!("cargo:rustc-env=BUILD_GIT_BRANCH={}", git_branch); + println!("cargo:rustc-env=BUILD_GIT_COMMIT={}", git_commit); + println!("cargo:rustc-env=BUILD_GIT_DATE={}", commit_date); + println!("cargo:rustc-env=BUILD_TIME={}", build_time); + println!("cargo:rustc-env=BUILD_RUST_VERSION={}", rust_version); +} diff --git a/common b/common deleted file mode 160000 index 91a06eb..0000000 --- a/common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 91a06ebfa107351264dd36e4cace9d0a7c54eb82 diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..eb2aed9 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,26 @@ +# I can't rely on contributors using .editorconfig +newline_style = "Unix" +# require the shorthand instead of it being optional +use_field_init_shorthand = true +# outdated default — `?` was unstable at the time +# additionally the `try!` macro is deprecated now +use_try_shorthand = true +# Max to use the 100 char width for everything or Default. See https://rust-lang.github.io/rustfmt/?version=v1.4.38&search=#use_small_heuristics +use_small_heuristics = "Max" + + +version = "Two" +unstable_features = true + +# better grepping +imports_granularity = "Item" +group_imports = "StdExternalCrate" + +normalize_comments = true +reorder_impl_items = true +reorder_modules = true +wrap_comments = true + +format_code_in_doc_comments = true +format_macro_bodies = true +format_macro_matchers = true diff --git a/src/lib.rs b/src/lib.rs index af4a353..81b2165 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,4 +32,6 @@ pub use vmsetup::*; pub mod blockchain_config; pub use blockchain_config::*; -include!("../common/src/info.rs"); +pub fn build_commit() -> Option<&'static str> { + std::option_env!("BUILD_GIT_COMMIT") +}