Skip to content

Commit

Permalink
chore: remove const_format
Browse files Browse the repository at this point in the history
  • Loading branch information
KolbyML committed Jan 17, 2025
1 parent eef1184 commit 6d1857f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 54 deletions.
37 changes: 0 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/ethportal-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ base64 = "0.13.0"
bimap = "0.6.3"
bytes.workspace = true
c-kzg = "1.0.0"
const_format = {version = "0.2.0", features = ["rust_1_64"]}
discv5.workspace = true
eth_trie.workspace = true
ethereum_hashing.workspace = true
Expand Down
38 changes: 36 additions & 2 deletions crates/ethportal-api/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::error::Error;
use std::{env, error::Error};

use vergen::EmitBuilder;

Expand All @@ -10,6 +10,40 @@ fn main() -> Result<(), Box<dyn Error>> {
.rustc_semver()
.cargo_features()
.cargo_target_triple()
.emit()?;
.emit_and_set()?;

// Set short SHA
let sha = env::var("VERGEN_GIT_SHA")?;
let short_sha = &sha[0..7];
println!("cargo:rustc-env=VERGEN_GIT_SHA_SHORT={short_sha}");

// Trin's version is the same as the git tag.
let git_describe = env::var("VERGEN_GIT_DESCRIBE")?;
let trin_version = git_describe.split('-').collect::<Vec<&str>>()[0];
println!("cargo:rustc-env=TRIN_VERSION={}", trin_version);

let cargo_target_triple = env::var("VERGEN_CARGO_TARGET_TRIPLE")?;
let target_triple = cargo_target_triple.split('-').collect::<Vec<&str>>();
let build_architecture = target_triple[0];
let build_operating_system = target_triple[2];

// The operating system of the build, linux, macos, windows etc.
println!("cargo:rustc-env=TRIN_BUILD_OPERATING_SYSTEM={build_operating_system}");

// The architecture of the build, x86_64, aarch64, etc.
println!("cargo:rustc-env=TRIN_BUILD_ARCHITECTURE={build_architecture}");

println!(
"cargo:rustc-env=TRIN_FULL_VERSION={}",
format_args!(
"{version}-{hash} {build_os}-{build_arch} rustc{rust_version}",
version = trin_version,
hash = short_sha,
build_os = build_operating_system,
build_arch = build_architecture,
rust_version = env::var("VERGEN_RUSTC_SEMVER")?
)
);

Ok(())
}
21 changes: 7 additions & 14 deletions crates/ethportal-api/src/version.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
use std::env;

/// The latest git commit hash of the build.
pub const TRIN_FULL_COMMIT: &str = env!("VERGEN_GIT_SHA");
pub const TRIN_SHORT_COMMIT: &str = const_format::str_index!(TRIN_FULL_COMMIT, ..8);
pub const TRIN_SHORT_COMMIT: &str = env!("VERGEN_GIT_SHA_SHORT");

/// Trin's version is the same as the git tag.
pub const TRIN_VERSION: &str = const_format::str_split!(env!("VERGEN_GIT_DESCRIBE"), '-')[0];
pub const TRIN_VERSION: &str = env!("TRIN_VERSION");

/// The operating system of the build, linux, macos, windows etc.
pub const BUILD_OPERATING_SYSTEM: &str =
const_format::str_split!(env!("VERGEN_CARGO_TARGET_TRIPLE"), "-")[2];
pub const BUILD_OPERATING_SYSTEM: &str = env!("TRIN_BUILD_OPERATING_SYSTEM");

/// The architecture of the build, x86_64, aarch64, etc.
pub const BUILD_ARCHITECTURE: &str =
const_format::str_split!(env!("VERGEN_CARGO_TARGET_TRIPLE"), "-")[0];
pub const BUILD_ARCHITECTURE: &str = env!("TRIN_BUILD_ARCHITECTURE");

// /// The version of the programming language used to build the binary.
pub const PROGRAMMING_LANGUAGE_VERSION: &str = env!("VERGEN_RUSTC_SEMVER");

pub const FULL_VERSION: &str = const_format::formatcp!(
"{version}-{hash} {build_os}-{build_arch} rustc{rust_version}",
version = TRIN_VERSION,
hash = TRIN_SHORT_COMMIT,
build_os = BUILD_OPERATING_SYSTEM,
build_arch = BUILD_ARCHITECTURE,
rust_version = PROGRAMMING_LANGUAGE_VERSION
);
pub const FULL_VERSION: &str = env!("TRIN_FULL_VERSION");

/// Returns the trin version and git revision.
pub const fn get_trin_version() -> &'static str {
Expand Down

0 comments on commit 6d1857f

Please sign in to comment.