From 213935861e44328bce28be2d01a64400a074cf95 Mon Sep 17 00:00:00 2001 From: higherordertech Date: Fri, 10 Jan 2025 19:13:10 +1100 Subject: [PATCH] feat: P-888 add cli to print the worker version --- tee-worker/Cargo.lock | 72 ++++++++++++++++++- tee-worker/Cargo.toml | 1 + tee-worker/bitacross/cli/build.rs | 20 ++++++ .../src/base_cli/commands/worker_version.rs | 57 +++++++++++++++ tee-worker/identity/cli/Cargo.toml | 4 ++ tee-worker/identity/cli/build.rs | 20 ++++++ .../identity/cli/src/base_cli/commands/mod.rs | 1 + .../src/base_cli/commands/worker_version.rs | 57 +++++++++++++++ tee-worker/identity/cli/src/base_cli/mod.rs | 5 ++ 9 files changed, 235 insertions(+), 2 deletions(-) create mode 100644 tee-worker/bitacross/cli/build.rs create mode 100644 tee-worker/bitacross/cli/src/base_cli/commands/worker_version.rs create mode 100644 tee-worker/identity/cli/build.rs create mode 100644 tee-worker/identity/cli/src/base_cli/commands/worker_version.rs diff --git a/tee-worker/Cargo.lock b/tee-worker/Cargo.lock index 727abd01a8..c0f90a353b 100644 --- a/tee-worker/Cargo.lock +++ b/tee-worker/Cargo.lock @@ -578,6 +578,18 @@ dependencies = [ "serde 1.0.210", ] +[[package]] +name = "built" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b99c4cdc7b2c2364182331055623bdf45254fcb679fea565c40c3c11c101889a" +dependencies = [ + "cargo-lock", + "chrono 0.4.26", + "git2", + "semver", +] + [[package]] name = "bumpalo" version = "3.13.0" @@ -651,6 +663,18 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "cargo-lock" +version = "9.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11c675378efb449ed3ce8de78d75d0d80542fc98487c26aba28eb3b82feac72" +dependencies = [ + "semver", + "serde 1.0.210", + "toml 0.7.8", + "url 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cargo_toml" version = "0.19.1" @@ -2255,6 +2279,19 @@ version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +[[package]] +name = "git2" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b989d6a7ca95a362cf2cfc5ad688b3a467be1f87e480b8dad07fee8c79b0044" +dependencies = [ + "bitflags 1.3.2", + "libc", + "libgit2-sys", + "log 0.4.20", + "url 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "glob" version = "0.3.1" @@ -4833,6 +4870,18 @@ version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +[[package]] +name = "libgit2-sys" +version = "0.15.2+1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a80df2e11fb4a61f4ba2ab42dbe7f74468da143f1a75c74e11dee7c813f694fa" +dependencies = [ + "cc", + "libc", + "libz-sys", + "pkg-config", +] + [[package]] name = "libloading" version = "0.8.5" @@ -4918,6 +4967,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2d16453e800a8cf6dd2fc3eb4bc99b786a9b90c663b8559a5b1a041bf89e472" dependencies = [ "cc", + "libc", "pkg-config", "vcpkg", ] @@ -4969,6 +5019,7 @@ version = "0.0.1" dependencies = [ "array-bytes 6.2.3", "base58", + "built", "chrono 0.4.26", "clap 4.1.0", "env_logger 0.10.2", @@ -7459,9 +7510,12 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.18" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +dependencies = [ + "serde 1.0.210", +] [[package]] name = "serde" @@ -8922,6 +8976,18 @@ dependencies = [ "serde 1.0.210", ] +[[package]] +name = "toml" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" +dependencies = [ + "serde 1.0.210", + "serde_spanned", + "toml_datetime", + "toml_edit 0.19.15", +] + [[package]] name = "toml" version = "0.8.2" @@ -8950,6 +9016,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ "indexmap 2.6.0", + "serde 1.0.210", + "serde_spanned", "toml_datetime", "winnow", ] diff --git a/tee-worker/Cargo.toml b/tee-worker/Cargo.toml index a4e44c4ca2..df3ffdacbc 100644 --- a/tee-worker/Cargo.toml +++ b/tee-worker/Cargo.toml @@ -133,6 +133,7 @@ yasna = { version = "0.4" } musig2 = { git = "https://github.com/kziemianek/musig2", branch = "master", features = ["k256"] } rlp = { version = "0.5", default-features = false } sha3 = { version = "0.10", default-features = false } +built = { version = "0.6.1", default-features = false } url = { git = "https://github.com/domenukk/rust-url", rev = "316c868", default-features = false, features = ["alloc", "no_std_net"] } substrate-api-client = { git = "https://github.com/Kailai-Wang/substrate-api-client", branch = "polkadot-v0.9.42-litentry", default-features = false, features = ["sync-api"] } diff --git a/tee-worker/bitacross/cli/build.rs b/tee-worker/bitacross/cli/build.rs new file mode 100644 index 0000000000..1530e9f893 --- /dev/null +++ b/tee-worker/bitacross/cli/build.rs @@ -0,0 +1,20 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +fn main() { + // generate build-time information + built::write_built_file().expect("Failed to acquire build-time information"); +} diff --git a/tee-worker/bitacross/cli/src/base_cli/commands/worker_version.rs b/tee-worker/bitacross/cli/src/base_cli/commands/worker_version.rs new file mode 100644 index 0000000000..4fc59f41a9 --- /dev/null +++ b/tee-worker/bitacross/cli/src/base_cli/commands/worker_version.rs @@ -0,0 +1,57 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +use crate::{Cli, CliResult, CliResultOk}; + +mod built_info { + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} + +// Dispnay the current worker version detail +// usage example: +// ./litentry-cli worker-version +#[derive(Parser)] +pub struct WorkerVersionCommand {} + +impl WorkerVersionCommand { + pub(crate) fn run(&self, _: &Cli) -> CliResult { + println!( + r#" +Version Information: +------------------ +Package version: {} +Target: {} +Rustc version: {} + +Git Information: +-------------- +Version: {} +Commit Hash: {} + +Build Time: +--------- +{} + "#, + built_info::PKG_VERSION, + built_info::TARGET, + built_info::RUSTC_VERSION, + built_info::GIT_VERSION.unwrap_or("unknown"), + built_info::GIT_COMMIT_HASH.unwrap_or("unknown"), + built::util::strptime(built_info::BUILT_TIME_UTC), + ); + Ok(CliResultOk::Bytes { bytes: () }) + } +} diff --git a/tee-worker/identity/cli/Cargo.toml b/tee-worker/identity/cli/Cargo.toml index c2046700ac..a8f71e0e1e 100644 --- a/tee-worker/identity/cli/Cargo.toml +++ b/tee-worker/identity/cli/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] array-bytes = { version = "6.0.0" } base58 = { workspace = true } +built = { workspace = true, features = ["git2", "chrono", "semver"] } chrono = "*" clap = { version = "=4.1.0", features = ["derive"] } codec = { package = "parity-scale-codec", workspace = true, features = ["std"] } @@ -51,6 +52,9 @@ litentry-hex-utils = { workspace = true } litentry-primitives = { workspace = true, features = ["std"] } scale-value = "0.6.0" +[build-dependencies] +built = { workspace = true, features = ["git2", "chrono", "semver"] } + [features] default = [] evm = ["ita-stf/evm", "pallet-evm"] diff --git a/tee-worker/identity/cli/build.rs b/tee-worker/identity/cli/build.rs new file mode 100644 index 0000000000..1530e9f893 --- /dev/null +++ b/tee-worker/identity/cli/build.rs @@ -0,0 +1,20 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +fn main() { + // generate build-time information + built::write_built_file().expect("Failed to acquire build-time information"); +} diff --git a/tee-worker/identity/cli/src/base_cli/commands/mod.rs b/tee-worker/identity/cli/src/base_cli/commands/mod.rs index 033b15b253..83470a2954 100644 --- a/tee-worker/identity/cli/src/base_cli/commands/mod.rs +++ b/tee-worker/identity/cli/src/base_cli/commands/mod.rs @@ -4,3 +4,4 @@ pub mod listen; pub mod litentry; pub mod register_tcb_info; pub mod transfer; +pub mod worker_version; diff --git a/tee-worker/identity/cli/src/base_cli/commands/worker_version.rs b/tee-worker/identity/cli/src/base_cli/commands/worker_version.rs new file mode 100644 index 0000000000..110a169c5d --- /dev/null +++ b/tee-worker/identity/cli/src/base_cli/commands/worker_version.rs @@ -0,0 +1,57 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . + +use crate::{Cli, CliResult, CliResultOk}; + +mod built_info { + include!(concat!(env!("OUT_DIR"), "/built.rs")); +} + +// Dispnay the current worker version detail +// usage example: +// ./litentry-cli worker-version +#[derive(Parser)] +pub struct WorkerVersionCommand {} + +impl WorkerVersionCommand { + pub(crate) fn run(&self, cli: &Cli) -> CliResult { + println!( + r#" +Version Information: +------------------ +Package version: {} +Target: {} +Rustc version: {} + +Git Information: +-------------- +Version: {} +Commit Hash: {} + +Build Time: +--------- +{} + "#, + built_info::PKG_VERSION, + built_info::TARGET, + built_info::RUSTC_VERSION, + built_info::GIT_VERSION.unwrap_or("unknown"), + built_info::GIT_COMMIT_HASH.unwrap_or("unknown"), + built::util::strptime(built_info::BUILT_TIME_UTC), + ); + Ok(CliResultOk::Bytes { bytes: () }) + } +} diff --git a/tee-worker/identity/cli/src/base_cli/mod.rs b/tee-worker/identity/cli/src/base_cli/mod.rs index 385b7f967a..a8257cd1f2 100644 --- a/tee-worker/identity/cli/src/base_cli/mod.rs +++ b/tee-worker/identity/cli/src/base_cli/mod.rs @@ -19,6 +19,7 @@ use crate::{ base_cli::commands::{ balance::BalanceCommand, faucet::FaucetCommand, listen::ListenCommand, litentry::*, register_tcb_info::RegisterTcbInfoCommand, transfer::TransferCommand, + worker_version::WorkerVersionCommand, }, command_utils::*, Cli, CliResult, CliResultOk, ED25519_KEY_TYPE, SR25519_KEY_TYPE, @@ -71,6 +72,9 @@ pub enum BaseCommand { /// Register TCB info for FMSPC RegisterTcbInfo(RegisterTcbInfoCommand), + /// Worker version + WorkerVersion(WorkerVersionCommand), + // Litentry's commands below /// query sgx-runtime metadata and print the raw (hex-encoded) metadata to stdout /// we could have added a parameter like `--raw` to `PrintSgxMetadata`, but @@ -106,6 +110,7 @@ impl BaseCommand { BaseCommand::ListWorkers => list_workers(cli), BaseCommand::Listen(cmd) => cmd.run(cli), BaseCommand::RegisterTcbInfo(cmd) => cmd.run(cli), + BaseCommand::WorkerVersion(cmd) => cmd.run(cli), // Litentry's commands below BaseCommand::PrintSgxMetadataRaw => print_sgx_metadata_raw(cli), BaseCommand::LinkIdentity(cmd) => cmd.run(cli),