From 5fab2208d88dc7e6edad57359c9d973fb758c4cc Mon Sep 17 00:00:00 2001 From: Hank Stoever Date: Tue, 29 Oct 2024 10:13:29 -0700 Subject: [PATCH 1/8] feat: add default version to `version_string` function --- docs/release-process.md | 3 ++- libsigner/src/libsigner.rs | 14 +++++++++++++- stacks-signer/release-process.md | 3 ++- stackslib/src/lib.rs | 6 +++++- stackslib/src/main.rs | 2 +- stackslib/src/net/api/getinfo.rs | 7 +------ stackslib/src/net/api/getstxtransfercost.rs | 1 - testnet/stacks-node/src/main.rs | 9 ++------- testnet/stacks-node/src/neon_node.rs | 7 +------ 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/docs/release-process.md b/docs/release-process.md index b96d3d2beb..00dcd2c3da 100644 --- a/docs/release-process.md +++ b/docs/release-process.md @@ -64,10 +64,11 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to - Add cherry-picked commits to the `feat/X.Y.Z.A.n-pr_number` branch - Merge `feat/X.Y.Z.A.n-pr_number` into `release/X.Y.Z.A.n`. -4. Open a PR to update the [CHANGELOG](../CHANGELOG.md) file in the `release/X.Y.Z.A.n` branch. +4. Open a PR to update the [CHANGELOG](../CHANGELOG.md) and [stackslib/src/lib.rs](../stackslib/src/lib.rs) files in the `release/X.Y.Z.A.n` branch. - Create a chore branch from `release/X.Y.Z.A.n`, ex: `chore/X.Y.Z.A.n-changelog`. - Add summaries of all Pull Requests to the `Added`, `Changed` and `Fixed` sections. + - Update the `STACKS_VERSION` string in [stackslib/src/lib.rs](../stackslib/src/lib.rs) to match this release. - Pull requests merged into `develop` can be found [here](https://github.com/stacks-network/stacks-core/pulls?q=is%3Apr+is%3Aclosed+base%3Adevelop+sort%3Aupdated-desc). diff --git a/libsigner/src/libsigner.rs b/libsigner/src/libsigner.rs index b1b760af6d..4e6e5871dc 100644 --- a/libsigner/src/libsigner.rs +++ b/libsigner/src/libsigner.rs @@ -63,6 +63,9 @@ pub use crate::runloop::{RunningSigner, Signer, SignerRunLoop}; pub use crate::session::{SignerSession, StackerDBSession}; pub use crate::signer_set::{Error as ParseSignerEntriesError, SignerEntries}; +/// The version string for the signer +pub const SIGNER_VERSION: &str = "3.0.0.0.0.1"; + /// A trait for message slots used for signer communication pub trait MessageSlotID: Sized + Eq + Hash + Debug + Copy { /// The contract identifier for the message slot in stacker db @@ -80,7 +83,16 @@ pub trait SignerMessage: StacksMessageCodec { lazy_static! { /// The version string for the signer pub static ref VERSION_STRING: String = { - let pkg_version = option_env!("STACKS_NODE_VERSION").unwrap_or(env!("CARGO_PKG_VERSION")); + let pkg_version = option_env!("STACKS_NODE_VERSION").or(Some(SIGNER_VERSION)); version_string("stacks-signer", pkg_version) }; } + +#[test] +fn test_version_string() { + let version = VERSION_STRING.to_string(); + assert_eq!( + version.contains(format!("stacks-signer {}", SIGNER_VERSION).as_str()), + true + ); +} diff --git a/stacks-signer/release-process.md b/stacks-signer/release-process.md index 71d47a3e26..6954019684 100644 --- a/stacks-signer/release-process.md +++ b/stacks-signer/release-process.md @@ -63,10 +63,11 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to - Add cherry-picked commits to the `feat/signer-X.Y.Z.A.n.x-pr_number` branch - Merge `feat/signer-X.Y.Z.A.n.x-pr_number` into `release/signer-X.Y.Z.A.n.x`. -4. Open a PR to update the [CHANGELOG](./CHANGELOG.md) file in the `release/signer-X.Y.Z.A.n.x` branch. +4. Open a PR to update the [CHANGELOG](./CHANGELOG.md) and [libsigner/src/libsigner.rs](../libsigner/src/libsigner.rs) files in the `release/signer-X.Y.Z.A.n.x` branch. - Create a chore branch from `release/signer-X.Y.Z.A.n.x`, ex: `chore/signer-X.Y.Z.A.n.x-changelog`. - Add summaries of all Pull Requests to the `Added`, `Changed` and `Fixed` sections. + - Update the `SIGNER_VERSION` string in [libsigner/src/libsigner.rs](../libsigner/src/libsigner.rs) to match this release. - Pull requests merged into `develop` can be found [here](https://github.com/stacks-network/stacks-core/pulls?q=is%3Apr+is%3Aclosed+base%3Adevelop+sort%3Aupdated-desc). diff --git a/stackslib/src/lib.rs b/stackslib/src/lib.rs index 31f97628a6..124166415d 100644 --- a/stackslib/src/lib.rs +++ b/stackslib/src/lib.rs @@ -78,7 +78,11 @@ const BUILD_TYPE: &'static str = "debug"; #[cfg(not(debug_assertions))] const BUILD_TYPE: &'static str = "release"; -pub fn version_string(pkg_name: &str, pkg_version: &str) -> String { +/// The version string for the stackslib +pub const STACKS_VERSION: &str = "3.0.0.0.0"; + +pub fn version_string(pkg_name: &str, pkg_version: Option<&str>) -> String { + let pkg_version = pkg_version.unwrap_or(STACKS_VERSION); let git_branch = GIT_BRANCH .map(|x| format!("{}", x)) .unwrap_or("".to_string()); diff --git a/stackslib/src/main.rs b/stackslib/src/main.rs index 98315cffa8..fe21d18df6 100644 --- a/stackslib/src/main.rs +++ b/stackslib/src/main.rs @@ -260,7 +260,7 @@ fn main() { "{}", &blockstack_lib::version_string( option_env!("CARGO_PKG_NAME").unwrap_or(&argv[0]), - option_env!("CARGO_PKG_VERSION").unwrap_or("0.0.0.0") + option_env!("STACKS_NODE_VERSION") ) ); process::exit(0); diff --git a/stackslib/src/net/api/getinfo.rs b/stackslib/src/net/api/getinfo.rs index d95b94803a..02251480f6 100644 --- a/stackslib/src/net/api/getinfo.rs +++ b/stackslib/src/net/api/getinfo.rs @@ -111,12 +111,7 @@ impl RPCPeerInfoData { coinbase_height: u64, ibd: bool, ) -> RPCPeerInfoData { - let server_version = version_string( - "stacks-node", - option_env!("STACKS_NODE_VERSION") - .or(option_env!("CARGO_PKG_VERSION")) - .unwrap_or("0.0.0.0"), - ); + let server_version = version_string("stacks-node", option_env!("STACKS_NODE_VERSION")); let (unconfirmed_tip, unconfirmed_seq) = match chainstate.unconfirmed_state { Some(ref unconfirmed) => { if unconfirmed.num_mined_txs() > 0 { diff --git a/stackslib/src/net/api/getstxtransfercost.rs b/stackslib/src/net/api/getstxtransfercost.rs index b8801e7d7c..3222c2c57b 100644 --- a/stackslib/src/net/api/getstxtransfercost.rs +++ b/stackslib/src/net/api/getstxtransfercost.rs @@ -42,7 +42,6 @@ use crate::net::httpcore::{ }; use crate::net::p2p::PeerNetwork; use crate::net::{Error as NetError, HttpServerError, StacksNodeState}; -use crate::version_string; pub(crate) const SINGLESIG_TX_TRANSFER_LEN: u64 = 180; diff --git a/testnet/stacks-node/src/main.rs b/testnet/stacks-node/src/main.rs index fcdc9f5847..7024ddd445 100644 --- a/testnet/stacks-node/src/main.rs +++ b/testnet/stacks-node/src/main.rs @@ -444,12 +444,7 @@ fn main() { } fn version() -> String { - stacks::version_string( - "stacks-node", - option_env!("STACKS_NODE_VERSION") - .or(option_env!("CARGO_PKG_VERSION")) - .unwrap_or("0.0.0.0"), - ) + stacks::version_string("stacks-node", option_env!("STACKS_NODE_VERSION")) } fn print_help() { @@ -467,7 +462,7 @@ SUBCOMMANDS: mainnet\t\tStart a node that will join and stream blocks from the public mainnet. -mocknet\t\tStart a node based on a fast local setup emulating a burnchain. Ideal for smart contract development. +mocknet\t\tStart a node based on a fast local setup emulating a burnchain. Ideal for smart contract development. helium\t\tStart a node based on a local setup relying on a local instance of bitcoind. \t\tThe following bitcoin.conf is expected: diff --git a/testnet/stacks-node/src/neon_node.rs b/testnet/stacks-node/src/neon_node.rs index dcfa855c9b..35f0cef5c0 100644 --- a/testnet/stacks-node/src/neon_node.rs +++ b/testnet/stacks-node/src/neon_node.rs @@ -2249,12 +2249,7 @@ impl BlockMinerThread { /// Only used in mock signing to generate a peer info view fn generate_peer_info(&self) -> PeerInfo { // Create a peer info view of the current state - let server_version = version_string( - "stacks-node", - option_env!("STACKS_NODE_VERSION") - .or(option_env!("CARGO_PKG_VERSION")) - .unwrap_or("0.0.0.0"), - ); + let server_version = version_string("stacks-node", option_env!("STACKS_NODE_VERSION")); let stacks_tip_height = self.burn_block.canonical_stacks_tip_height; let stacks_tip = self.burn_block.canonical_stacks_tip_hash; let stacks_tip_consensus_hash = self.burn_block.canonical_stacks_tip_consensus_hash; From 8363f574a46eb60c234660375006b4c67d01fe8e Mon Sep 17 00:00:00 2001 From: Hank Stoever Date: Fri, 15 Nov 2024 05:38:21 -0800 Subject: [PATCH 2/8] feat: use versions.yaml with a build script --- Cargo.lock | 1 + docs/release-process.md | 2 +- libsigner/src/libsigner.rs | 8 ++-- stacks-common/Cargo.toml | 4 ++ stacks-common/build.rs | 71 ++++++++++++++++++++++++++++++++ stacks-common/src/libcommon.rs | 4 ++ stacks-signer/release-process.md | 2 +- stackslib/src/lib.rs | 6 +-- versions.toml | 4 ++ 9 files changed, 91 insertions(+), 11 deletions(-) create mode 100644 stacks-common/build.rs create mode 100644 versions.toml diff --git a/Cargo.lock b/Cargo.lock index 227cd9d768..d1b628b18d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3292,6 +3292,7 @@ dependencies = [ "slog-json", "slog-term", "time 0.2.27", + "toml", "winapi 0.3.9", ] diff --git a/docs/release-process.md b/docs/release-process.md index 00dcd2c3da..fdedbe0f72 100644 --- a/docs/release-process.md +++ b/docs/release-process.md @@ -68,7 +68,7 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to - Create a chore branch from `release/X.Y.Z.A.n`, ex: `chore/X.Y.Z.A.n-changelog`. - Add summaries of all Pull Requests to the `Added`, `Changed` and `Fixed` sections. - - Update the `STACKS_VERSION` string in [stackslib/src/lib.rs](../stackslib/src/lib.rs) to match this release. + - Update the `stacks_node_version` string in [versions.toml](../versions.toml) to match this release. - Pull requests merged into `develop` can be found [here](https://github.com/stacks-network/stacks-core/pulls?q=is%3Apr+is%3Aclosed+base%3Adevelop+sort%3Aupdated-desc). diff --git a/libsigner/src/libsigner.rs b/libsigner/src/libsigner.rs index 4e6e5871dc..2eb0fa850a 100644 --- a/libsigner/src/libsigner.rs +++ b/libsigner/src/libsigner.rs @@ -53,6 +53,7 @@ use blockstack_lib::version_string; use clarity::codec::StacksMessageCodec; use clarity::vm::types::QualifiedContractIdentifier; use lazy_static::lazy_static; +use stacks_common::versions::STACKS_SIGNER_VERSION; pub use crate::error::{EventError, RPCError}; pub use crate::events::{ @@ -63,9 +64,6 @@ pub use crate::runloop::{RunningSigner, Signer, SignerRunLoop}; pub use crate::session::{SignerSession, StackerDBSession}; pub use crate::signer_set::{Error as ParseSignerEntriesError, SignerEntries}; -/// The version string for the signer -pub const SIGNER_VERSION: &str = "3.0.0.0.0.1"; - /// A trait for message slots used for signer communication pub trait MessageSlotID: Sized + Eq + Hash + Debug + Copy { /// The contract identifier for the message slot in stacker db @@ -83,7 +81,7 @@ pub trait SignerMessage: StacksMessageCodec { lazy_static! { /// The version string for the signer pub static ref VERSION_STRING: String = { - let pkg_version = option_env!("STACKS_NODE_VERSION").or(Some(SIGNER_VERSION)); + let pkg_version = option_env!("STACKS_NODE_VERSION").or(Some(STACKS_SIGNER_VERSION)); version_string("stacks-signer", pkg_version) }; } @@ -92,7 +90,7 @@ lazy_static! { fn test_version_string() { let version = VERSION_STRING.to_string(); assert_eq!( - version.contains(format!("stacks-signer {}", SIGNER_VERSION).as_str()), + version.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str()), true ); } diff --git a/stacks-common/Cargo.toml b/stacks-common/Cargo.toml index 81b4326d4c..661b61be29 100644 --- a/stacks-common/Cargo.toml +++ b/stacks-common/Cargo.toml @@ -12,6 +12,7 @@ keywords = [ "stacks", "stx", "bitcoin", "crypto", "blockstack", "decentralized" readme = "README.md" resolver = "2" edition = "2021" +build = "build.rs" [lib] name = "stacks_common" @@ -79,6 +80,9 @@ bech32_std = [] bech32_strict = [] strason = [] +[build-dependencies] +toml = "0.5.6" + [target.'cfg(all(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"), not(any(target_os="windows"))))'.dependencies] sha2 = { version = "0.10", features = ["asm"] } diff --git a/stacks-common/build.rs b/stacks-common/build.rs new file mode 100644 index 0000000000..d91c95f196 --- /dev/null +++ b/stacks-common/build.rs @@ -0,0 +1,71 @@ +use std::path::Path; +use std::{env, fs}; +use toml::Value; + +fn main() { + let toml_content = + fs::read_to_string("../versions.toml").expect("Failed to read versions.toml"); + + let config: Value = toml::from_str(&toml_content).expect("Failed to parse TOML"); + + let mut rust_code = String::from("// Auto-generated code from versions.toml\n\n"); + + fn generate_constants(value: &Value, prefix: &str, code: &mut String) { + match value { + Value::Table(table) => { + for (key, val) in table { + let new_prefix = if prefix.is_empty() { + key.to_string() + } else { + format!("{}_{}", prefix, key) + }; + generate_constants(val, &new_prefix, code); + } + } + Value::Array(arr) => { + code.push_str(&format!( + "pub const {}: &[&str] = &[{}];\n", + prefix.to_uppercase(), + arr.iter() + .map(|v| format!("\"{}\"", v.as_str().unwrap_or(""))) + .collect::>() + .join(", ") + )); + } + _ => { + let const_value = match value { + Value::String(s) => format!("\"{}\"", s), + Value::Integer(n) => n.to_string(), + Value::Float(f) => f.to_string(), + Value::Boolean(b) => b.to_string(), + _ => "\"\"".to_string(), + }; + code.push_str(&format!( + "pub const {}: {} = {};\n", + prefix.to_uppercase(), + if value.is_str() { + "&str" + } else if value.is_integer() { + "i64" + } else if value.is_float() { + "f64" + } else if value.is_bool() { + "bool" + } else { + "&str" + }, + const_value + )); + } + } + } + + generate_constants(&config, "", &mut rust_code); + + let out_dir = env::var_os("OUT_DIR").unwrap(); + let dest_path = Path::new(&out_dir).join("versions.rs"); + fs::write(&dest_path, rust_code).expect("Failed to write generated code"); + + // Tell Cargo to rerun this script if the TOML file changes + println!("cargo:rerun-if-changed=../versions.toml"); +} diff --git a/stacks-common/src/libcommon.rs b/stacks-common/src/libcommon.rs index 1a13aa02ed..6227c2128f 100644 --- a/stacks-common/src/libcommon.rs +++ b/stacks-common/src/libcommon.rs @@ -95,6 +95,10 @@ pub mod consts { pub const NETWORK_ID_TESTNET: u32 = 0xff000000; } +pub mod versions { + include!(concat!(env!("OUT_DIR"), "/versions.rs")); +} + /// This test asserts that the constant above doesn't change. /// This exists because the constant above is used by Epoch 2.5 instantiation code. /// diff --git a/stacks-signer/release-process.md b/stacks-signer/release-process.md index 6954019684..798263d7e6 100644 --- a/stacks-signer/release-process.md +++ b/stacks-signer/release-process.md @@ -67,7 +67,7 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to - Create a chore branch from `release/signer-X.Y.Z.A.n.x`, ex: `chore/signer-X.Y.Z.A.n.x-changelog`. - Add summaries of all Pull Requests to the `Added`, `Changed` and `Fixed` sections. - - Update the `SIGNER_VERSION` string in [libsigner/src/libsigner.rs](../libsigner/src/libsigner.rs) to match this release. + - Update the `stacks_signer_version` string in [versions.toml](../versions.toml) to match this release. - Pull requests merged into `develop` can be found [here](https://github.com/stacks-network/stacks-core/pulls?q=is%3Apr+is%3Aclosed+base%3Adevelop+sort%3Aupdated-desc). diff --git a/stackslib/src/lib.rs b/stackslib/src/lib.rs index 124166415d..6480c9391a 100644 --- a/stackslib/src/lib.rs +++ b/stackslib/src/lib.rs @@ -45,6 +45,7 @@ extern crate stacks_common; #[macro_use] pub extern crate clarity; +use stacks_common::versions::STACKS_NODE_VERSION; pub use stacks_common::{address, codec, types, util}; #[macro_use] @@ -78,11 +79,8 @@ const BUILD_TYPE: &'static str = "debug"; #[cfg(not(debug_assertions))] const BUILD_TYPE: &'static str = "release"; -/// The version string for the stackslib -pub const STACKS_VERSION: &str = "3.0.0.0.0"; - pub fn version_string(pkg_name: &str, pkg_version: Option<&str>) -> String { - let pkg_version = pkg_version.unwrap_or(STACKS_VERSION); + let pkg_version = pkg_version.unwrap_or(STACKS_NODE_VERSION); let git_branch = GIT_BRANCH .map(|x| format!("{}", x)) .unwrap_or("".to_string()); diff --git a/versions.toml b/versions.toml new file mode 100644 index 0000000000..c2d76301f6 --- /dev/null +++ b/versions.toml @@ -0,0 +1,4 @@ +# Update these values when a new release is created. +# `stacks-common/build.rs` will automatically update `versions.rs` with these values. +stacks_node_version = "3.0.0.0.2" +stacks_signer_version = "3.0.0.0.2.0" From d963ea495d6c1c6de9f2d7693ef333a089ec54f4 Mon Sep 17 00:00:00 2001 From: Hank Stoever Date: Fri, 15 Nov 2024 05:41:11 -0800 Subject: [PATCH 3/8] fix: formatting --- stacks-common/build.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/stacks-common/build.rs b/stacks-common/build.rs index d91c95f196..cce9ce8b1b 100644 --- a/stacks-common/build.rs +++ b/stacks-common/build.rs @@ -1,5 +1,6 @@ use std::path::Path; use std::{env, fs}; + use toml::Value; fn main() { From 6478e919de3cc4de2d44961a2069d7ea8d102be5 Mon Sep 17 00:00:00 2001 From: Hank Stoever Date: Mon, 16 Dec 2024 14:54:18 -0800 Subject: [PATCH 4/8] fix: remove old release-process.md instructions --- docs/release-process.md | 2 +- stacks-signer/release-process.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/release-process.md b/docs/release-process.md index fdedbe0f72..3d7d32545c 100644 --- a/docs/release-process.md +++ b/docs/release-process.md @@ -64,7 +64,7 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to - Add cherry-picked commits to the `feat/X.Y.Z.A.n-pr_number` branch - Merge `feat/X.Y.Z.A.n-pr_number` into `release/X.Y.Z.A.n`. -4. Open a PR to update the [CHANGELOG](../CHANGELOG.md) and [stackslib/src/lib.rs](../stackslib/src/lib.rs) files in the `release/X.Y.Z.A.n` branch. +4. Open a PR to update the [CHANGELOG](../CHANGELOG.md) in the `release/X.Y.Z.A.n` branch. - Create a chore branch from `release/X.Y.Z.A.n`, ex: `chore/X.Y.Z.A.n-changelog`. - Add summaries of all Pull Requests to the `Added`, `Changed` and `Fixed` sections. diff --git a/stacks-signer/release-process.md b/stacks-signer/release-process.md index 798263d7e6..54bebafad0 100644 --- a/stacks-signer/release-process.md +++ b/stacks-signer/release-process.md @@ -63,7 +63,7 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to - Add cherry-picked commits to the `feat/signer-X.Y.Z.A.n.x-pr_number` branch - Merge `feat/signer-X.Y.Z.A.n.x-pr_number` into `release/signer-X.Y.Z.A.n.x`. -4. Open a PR to update the [CHANGELOG](./CHANGELOG.md) and [libsigner/src/libsigner.rs](../libsigner/src/libsigner.rs) files in the `release/signer-X.Y.Z.A.n.x` branch. +4. Open a PR to update the [CHANGELOG](./CHANGELOG.md) in the `release/signer-X.Y.Z.A.n.x` branch. - Create a chore branch from `release/signer-X.Y.Z.A.n.x`, ex: `chore/signer-X.Y.Z.A.n.x-changelog`. - Add summaries of all Pull Requests to the `Added`, `Changed` and `Fixed` sections. From 40440bb46d34af1c5e16f5fa9b02b44c4787d596 Mon Sep 17 00:00:00 2001 From: Hank Stoever Date: Mon, 16 Dec 2024 14:55:15 -0800 Subject: [PATCH 5/8] fix: update versions.toml --- versions.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/versions.toml b/versions.toml index c2d76301f6..3e8150cc95 100644 --- a/versions.toml +++ b/versions.toml @@ -1,4 +1,4 @@ # Update these values when a new release is created. # `stacks-common/build.rs` will automatically update `versions.rs` with these values. -stacks_node_version = "3.0.0.0.2" -stacks_signer_version = "3.0.0.0.2.0" +stacks_node_version = "3.1.0.0.2" +stacks_signer_version = "3.1.0.0.2.0" From be946b62a87423038e226e91acaa9fed0c283f74 Mon Sep 17 00:00:00 2001 From: Hank Stoever Date: Mon, 16 Dec 2024 15:06:44 -0800 Subject: [PATCH 6/8] fix: simplify versions.toml to consts code --- stacks-common/build.rs | 65 ++++++++++++------------------------------ 1 file changed, 18 insertions(+), 47 deletions(-) diff --git a/stacks-common/build.rs b/stacks-common/build.rs index cce9ce8b1b..00db6c24db 100644 --- a/stacks-common/build.rs +++ b/stacks-common/build.rs @@ -11,58 +11,29 @@ fn main() { let mut rust_code = String::from("// Auto-generated code from versions.toml\n\n"); - fn generate_constants(value: &Value, prefix: &str, code: &mut String) { - match value { - Value::Table(table) => { - for (key, val) in table { - let new_prefix = if prefix.is_empty() { - key.to_string() - } else { - format!("{}_{}", prefix, key) - }; - generate_constants(val, &new_prefix, code); - } - } - Value::Array(arr) => { - code.push_str(&format!( - "pub const {}: &[&str] = &[{}];\n", - prefix.to_uppercase(), - arr.iter() - .map(|v| format!("\"{}\"", v.as_str().unwrap_or(""))) - .collect::>() - .join(", ") - )); - } - _ => { - let const_value = match value { - Value::String(s) => format!("\"{}\"", s), - Value::Integer(n) => n.to_string(), - Value::Float(f) => f.to_string(), - Value::Boolean(b) => b.to_string(), - _ => "\"\"".to_string(), + match config { + Value::Table(table) => { + for (key, val) in table { + match val { + Value::String(s) => { + let const_value = format!("\"{}\"", s); + rust_code.push_str(&format!( + "pub const {}: &str = {};\n", + key.to_uppercase(), + const_value + )); + } + _ => { + panic!("Invalid value type in versions.toml: {:?}", val); + } }; - code.push_str(&format!( - "pub const {}: {} = {};\n", - prefix.to_uppercase(), - if value.is_str() { - "&str" - } else if value.is_integer() { - "i64" - } else if value.is_float() { - "f64" - } else if value.is_bool() { - "bool" - } else { - "&str" - }, - const_value - )); } } + _ => { + panic!("Invalid value type in versions.toml: {:?}", config); + } } - generate_constants(&config, "", &mut rust_code); - let out_dir = env::var_os("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("versions.rs"); fs::write(&dest_path, rust_code).expect("Failed to write generated code"); From 99e81cd4b4e2e1f9afd606971bcd238ed50f1362 Mon Sep 17 00:00:00 2001 From: Hank Stoever Date: Wed, 29 Jan 2025 12:57:54 -0800 Subject: [PATCH 7/8] fix: simplify & improve build script code --- libsigner/src/libsigner.rs | 5 +---- stacks-common/build.rs | 38 ++++++++++++++------------------------ versions.toml | 4 ++-- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/libsigner/src/libsigner.rs b/libsigner/src/libsigner.rs index 2eb0fa850a..c24cb2b209 100644 --- a/libsigner/src/libsigner.rs +++ b/libsigner/src/libsigner.rs @@ -89,8 +89,5 @@ lazy_static! { #[test] fn test_version_string() { let version = VERSION_STRING.to_string(); - assert_eq!( - version.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str()), - true - ); + assert!(version.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str())); } diff --git a/stacks-common/build.rs b/stacks-common/build.rs index 00db6c24db..00d79f0710 100644 --- a/stacks-common/build.rs +++ b/stacks-common/build.rs @@ -4,34 +4,24 @@ use std::{env, fs}; use toml::Value; fn main() { - let toml_content = - fs::read_to_string("../versions.toml").expect("Failed to read versions.toml"); + let toml_file = "../versions.toml"; + let toml_content = fs::read_to_string(toml_file).expect("Failed to read versions.toml"); let config: Value = toml::from_str(&toml_content).expect("Failed to parse TOML"); let mut rust_code = String::from("// Auto-generated code from versions.toml\n\n"); - match config { - Value::Table(table) => { - for (key, val) in table { - match val { - Value::String(s) => { - let const_value = format!("\"{}\"", s); - rust_code.push_str(&format!( - "pub const {}: &str = {};\n", - key.to_uppercase(), - const_value - )); - } - _ => { - panic!("Invalid value type in versions.toml: {:?}", val); - } - }; - } - } - _ => { - panic!("Invalid value type in versions.toml: {:?}", config); - } + let Value::Table(table) = config else { + panic!("Invalid value type in versions.toml: {config:?}"); + }; + for (key, val) in table { + let Value::String(s) = val else { + panic!("Invalid value type in versions.toml: {val:?}"); + }; + rust_code.push_str(&format!( + "pub const {}: &str = {s:?};\n", + key.to_uppercase() + )); } let out_dir = env::var_os("OUT_DIR").unwrap(); @@ -39,5 +29,5 @@ fn main() { fs::write(&dest_path, rust_code).expect("Failed to write generated code"); // Tell Cargo to rerun this script if the TOML file changes - println!("cargo:rerun-if-changed=../versions.toml"); + println!("cargo:rerun-if-changed={toml_file}"); } diff --git a/versions.toml b/versions.toml index 3e8150cc95..72ea8cb6fe 100644 --- a/versions.toml +++ b/versions.toml @@ -1,4 +1,4 @@ # Update these values when a new release is created. # `stacks-common/build.rs` will automatically update `versions.rs` with these values. -stacks_node_version = "3.1.0.0.2" -stacks_signer_version = "3.1.0.0.2.0" +stacks_node_version = "3.1.0.0.4" +stacks_signer_version = "3.1.0.0.4.0" From dcb36a257bc9f2c9bc788f2adca75733f667d86d Mon Sep 17 00:00:00 2001 From: Hank Stoever Date: Fri, 31 Jan 2025 07:20:32 -0800 Subject: [PATCH 8/8] fix: remove unnecessary var --- libsigner/src/libsigner.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libsigner/src/libsigner.rs b/libsigner/src/libsigner.rs index c24cb2b209..90cee5e4c3 100644 --- a/libsigner/src/libsigner.rs +++ b/libsigner/src/libsigner.rs @@ -88,6 +88,5 @@ lazy_static! { #[test] fn test_version_string() { - let version = VERSION_STRING.to_string(); - assert!(version.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str())); + assert!(VERSION_STRING.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str())); }