From 2227d5ada7a02f9406a7fb0cb290e55bea3e30e5 Mon Sep 17 00:00:00 2001 From: Gregory Roussac Date: Wed, 28 Aug 2024 15:01:51 +0200 Subject: [PATCH] Remove vergen dep on feat-track-2.0 for cargo audit (#185) * Add feat-track-node-2.0 to CI * Port from dev to feat-track-2.0 of #149 #175 Part of #144 Enable CI CD check on feat-track-2.0 * clippy/test/build with no default features not yet working * Clippy * Commenting out ci/cd for --no-default-features --- .github/workflows/ci-casper-client-rs.yml | 46 +++++++++++++++++++---- Cargo.toml | 34 +++++++---------- build.rs | 36 ++++++++++++++++-- lib/cli/tests.rs | 16 ++++---- rust-toolchain.toml | 2 + src/main.rs | 4 +- 6 files changed, 96 insertions(+), 42 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/ci-casper-client-rs.yml b/.github/workflows/ci-casper-client-rs.yml index b3c1330f..ad5a69fa 100644 --- a/.github/workflows/ci-casper-client-rs.yml +++ b/.github/workflows/ci-casper-client-rs.yml @@ -3,12 +3,12 @@ name: ci-casper-client-rs on: push: - branches: [main, dev, release-2.0.0] + branches: [main, dev, release-2.0.0, feat-track-node-2.0] paths-ignore: - '**.md' pull_request: - branches: [main, dev, release-2.0.0] + branches: [main, dev, release-2.0.0, feat-track-node-2.0] paths-ignore: - '**.md' @@ -22,11 +22,19 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - components: rustfmt, clippy + + - name: Get stable from rust-toolchain.toml + id: stable-toolchain + run: | + VER=$(sed -nr 's/channel\s+=\s+\"(.*)\"/\1/p' rust-toolchain.toml) + echo "RUST_CHANNEL=$VER" >> $GITHUB_ENV + + - name: Install Toolchain - Stable + run: | + rustup update --no-self-update ${{ env.RUST_CHANNEL }} + rustup component add --toolchain ${{ env.RUST_CHANNEL }} rustfmt rust-src clippy + rustup default ${{ env.RUST_CHANNEL }} + rustup target add wasm32-unknown-unknown - name: Fmt uses: actions-rs/cargo@v1 @@ -45,6 +53,12 @@ jobs: command: clippy args: --all-targets + # - name: Clippy with no features + # uses: actions-rs/cargo@v1 + # with: + # command: clippy + # args: --all-targets --no-default-features + - name: Doc uses: actions-rs/cargo@v1 with: @@ -55,3 +69,21 @@ jobs: uses: actions-rs/cargo@v1 with: command: test + + # - name: Test with no features + # uses: actions-rs/cargo@v1 + # with: + # command: test + # args: --no-default-features + + - name: Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --all-targets + + # - name: Build lib for Wasm with no features + # uses: actions-rs/cargo@v1 + # with: + # command: build + # args: --lib --target wasm32-unknown-unknown --no-default-features diff --git a/Cargo.toml b/Cargo.toml index ef3378e8..a6ece943 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,11 @@ [package] name = "casper-client" version = "2.0.0" # when updating, also update 'html_root_url' in lib.rs -authors = ["Marc Brinkmann ", "Fraser Hutchison ", "Zachary Showalter "] +authors = [ + "Marc Brinkmann ", + "Fraser Hutchison ", + "Zachary Showalter ", +] edition = "2021" description = "A client library and binary for interacting with the Casper network" documentation = "https://docs.rs/casper-client" @@ -18,21 +22,18 @@ path = "lib/lib.rs" name = "casper-client" path = "src/main.rs" doc = false +required-features = ["async-trait", "clap", "clap_complete", "std-fs-io"] [features] -default = ["async-trait", "clap", "clap_complete", "tokio", "std-fs-io"] +default = ["async-trait", "clap", "clap_complete", "std-fs-io"] std-fs-io = ["casper-types/std-fs-io"] [dependencies] async-trait = { version = "0.1.59", default-features = false, optional = true } base16 = "0.2.1" casper-types = { version = "5.0.0", features = ["std"] } -clap = { version = "4", features = [ - "cargo", - "deprecated", - "wrap_help", -], optional = true } -clap_complete = { version = "4", default-features = false, optional = true } +clap = { version = "~4.4", features = ["cargo", "deprecated"], optional = true } +clap_complete = { version = "~4.4", default-features = false, optional = true } hex-buffer-serde = "0.4.0" humantime = "2" itertools = "0.11.0" @@ -40,34 +41,25 @@ jsonrpc-lite = "0.6.0" num-traits = "0.2.15" once_cell = "1" rand = "0.8.5" -reqwest = { version = "0.11.13", features = ["json"] } +reqwest = { version = "0.12.5", features = ["json"] } schemars = "0.8.13" serde = { version = "1", default-features = false, features = ["derive"] } serde-map-to-array = "1.1.1" serde_json = { version = "1", features = ["preserve_order"] } -thiserror = "1.0.34" -tokio = { version = "1.23.0", features = [ - "macros", - "net", - "rt-multi-thread", - "sync", - "time", -], optional = true } +thiserror = "1" +tokio = { version = "1.38.0", features = ["macros", "rt", "sync", "time"] } uint = "0.9.4" [dev-dependencies] tempfile = "3.7.1" -[build-dependencies] -vergen = { version = "7", default-features = false, features = ["git"] } - [patch.crates-io] casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" } [package.metadata.deb] features = ["vendored-openssl"] revision = "0" -assets = [["./target/release/casper-client", "/usr/bin/casper-client", "755"], ] +assets = [["./target/release/casper-client", "/usr/bin/casper-client", "755"]] extended-description = """ Package for Casper Client to connect to Casper Node. diff --git a/build.rs b/build.rs index c8dd712c..bc0d703b 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,35 @@ -use vergen::{Config, ShaKind}; +use std::io; +use std::process::Command; + +const GIT_HASH_ENV_VAR: &str = "GIT_SHA_SHORT"; fn main() { - let mut config = Config::default(); - *config.git_mut().sha_kind_mut() = ShaKind::Short; - let _ = vergen::vergen(config); + match get_git_commit_hash() { + // If the git commit hash is retrieved successfully, set the environment variable + Ok(git_hash) => { + println!("cargo:rustc-env={GIT_HASH_ENV_VAR}={git_hash}"); + } + // If there's an error retrieving the git commit hash, print a note and set the environment variable to "unknown" + Err(e) => { + println!("cargo:warning=Note: Failed to get git commit hash: {}", e); + println!("cargo:rustc-env={GIT_HASH_ENV_VAR}=unknown"); + } + } +} + +fn get_git_commit_hash() -> Result { + // Build the command to retrieve the short git commit hash + let output = Command::new("git") + .arg("rev-parse") + .arg("--short") + .arg("HEAD") + .output()?; + + if output.status.success() { + // Parse the raw output into a string and trim the newline character + Ok(String::from_utf8_lossy(&output.stdout).trim().to_string()) + } else { + // Return an error if the command failed + Err(io::Error::new(io::ErrorKind::Other, "Git command failed")) + } } diff --git a/lib/cli/tests.rs b/lib/cli/tests.rs index d1bf138f..93fb5700 100644 --- a/lib/cli/tests.rs +++ b/lib/cli/tests.rs @@ -585,8 +585,8 @@ mod transaction { let validator_public_key = PublicKey::from(&validator_secret_key); let amount = U512::from(2000); - let delegator_public_key_cl = &CLValue::from_t(&delegator_public_key).unwrap(); - let validator_public_key_cl = &CLValue::from_t(&validator_public_key).unwrap(); + let delegator_public_key_cl = &CLValue::from_t(delegator_public_key).unwrap(); + let validator_public_key_cl = &CLValue::from_t(validator_public_key).unwrap(); let amount_cl = &CLValue::from_t(amount).unwrap(); let transaction_string_params = TransactionStrParams { @@ -699,8 +699,8 @@ mod transaction { let validator_public_key = PublicKey::from(&validator_secret_key); let amount_cl = &CLValue::from_t(amount).unwrap(); - let delegator_public_key_cl = &CLValue::from_t(&delegator_public_key).unwrap(); - let validator_public_key_cl = &CLValue::from_t(&validator_public_key).unwrap(); + let delegator_public_key_cl = &CLValue::from_t(delegator_public_key).unwrap(); + let validator_public_key_cl = &CLValue::from_t(validator_public_key).unwrap(); let transaction_string_params = TransactionStrParams { secret_key: "", @@ -764,9 +764,9 @@ mod transaction { let new_validator_public_key = PublicKey::from(&new_validator_secret_key); let amount = U512::from(5000); - let delegator_public_key_cl = &CLValue::from_t(&delegator_public_key).unwrap(); - let validator_public_key_cl = &CLValue::from_t(&validator_public_key).unwrap(); - let new_validator_public_key_cl = &CLValue::from_t(&new_validator_public_key).unwrap(); + let delegator_public_key_cl = &CLValue::from_t(delegator_public_key).unwrap(); + let validator_public_key_cl = &CLValue::from_t(validator_public_key).unwrap(); + let new_validator_public_key_cl = &CLValue::from_t(new_validator_public_key).unwrap(); let amount_cl = &CLValue::from_t(amount).unwrap(); let transaction_string_params = TransactionStrParams { @@ -1053,7 +1053,7 @@ mod transaction { let maybe_source = Some(source_uref); let source_uref_cl = &CLValue::from_t(Some(&source_uref)).unwrap(); - let target_uref_cl = &CLValue::from_t(&target_uref).unwrap(); + let target_uref_cl = &CLValue::from_t(target_uref).unwrap(); let transaction_string_params = TransactionStrParams { secret_key: "", diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..8142c301 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.73.0" diff --git a/src/main.rs b/src/main.rs index 942ca628..7ce0a05d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,7 @@ const APP_NAME: &str = "Casper client"; static VERSION: Lazy = Lazy::new( - || match option_env!("VERGEN_GIT_SHA_SHORT").map(|sha| sha.to_lowercase()) { + || match option_env!("GIT_SHA_SHORT").map(|sha| sha.to_lowercase()) { None => crate_version!().to_string(), Some(git_sha_short) => { if git_sha_short.to_lowercase() == "unknown" { @@ -175,7 +175,7 @@ fn cli() -> Command { )) } -#[tokio::main] +#[tokio::main(flavor = "current_thread")] async fn main() { let arg_matches = cli().get_matches(); let (subcommand_name, matches) = arg_matches.subcommand().unwrap_or_else(|| {