Skip to content

Commit 6651b31

Browse files
authored
Merge pull request #5399 from stacks-network/feat/update-cargo-versions
Add default version to `version_string` function
2 parents 1408ef9 + c6c38ee commit 6651b31

File tree

14 files changed

+67
-27
lines changed

14 files changed

+67
-27
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/release-process.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to
6464
- Add cherry-picked commits to the `feat/X.Y.Z.A.n-pr_number` branch
6565
- Merge `feat/X.Y.Z.A.n-pr_number` into `release/X.Y.Z.A.n`.
6666

67-
4. Open a PR to update the [CHANGELOG](../CHANGELOG.md) file in the `release/X.Y.Z.A.n` branch.
67+
4. Open a PR to update the [CHANGELOG](../CHANGELOG.md) in the `release/X.Y.Z.A.n` branch.
6868

6969
- Create a chore branch from `release/X.Y.Z.A.n`, ex: `chore/X.Y.Z.A.n-changelog`.
7070
- Add summaries of all Pull Requests to the `Added`, `Changed` and `Fixed` sections.
71+
- Update the `stacks_node_version` string in [versions.toml](../versions.toml) to match this release.
7172

7273
- 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).
7374

libsigner/src/libsigner.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use blockstack_lib::version_string;
5353
use clarity::codec::StacksMessageCodec;
5454
use clarity::vm::types::QualifiedContractIdentifier;
5555
use lazy_static::lazy_static;
56+
use stacks_common::versions::STACKS_SIGNER_VERSION;
5657

5758
pub use crate::error::{EventError, RPCError};
5859
pub use crate::events::{
@@ -80,7 +81,12 @@ pub trait SignerMessage<T: MessageSlotID>: StacksMessageCodec {
8081
lazy_static! {
8182
/// The version string for the signer
8283
pub static ref VERSION_STRING: String = {
83-
let pkg_version = option_env!("STACKS_NODE_VERSION").unwrap_or(env!("CARGO_PKG_VERSION"));
84+
let pkg_version = option_env!("STACKS_NODE_VERSION").or(Some(STACKS_SIGNER_VERSION));
8485
version_string("stacks-signer", pkg_version)
8586
};
8687
}
88+
89+
#[test]
90+
fn test_version_string() {
91+
assert!(VERSION_STRING.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str()));
92+
}

stacks-common/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ keywords = [ "stacks", "stx", "bitcoin", "crypto", "blockstack", "decentralized"
1212
readme = "README.md"
1313
resolver = "2"
1414
edition = "2021"
15+
build = "build.rs"
1516

1617
[lib]
1718
name = "stacks_common"
@@ -73,6 +74,9 @@ serde = []
7374
bech32_std = []
7475
bech32_strict = []
7576

77+
[build-dependencies]
78+
toml = "0.5.6"
79+
7680
[target.'cfg(all(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"), not(any(target_os="windows"))))'.dependencies]
7781
sha2 = { version = "0.10", features = ["asm"] }
7882

stacks-common/build.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::path::Path;
2+
use std::{env, fs};
3+
4+
use toml::Value;
5+
6+
fn main() {
7+
let toml_file = "../versions.toml";
8+
let toml_content = fs::read_to_string(toml_file).expect("Failed to read versions.toml");
9+
10+
let config: Value = toml::from_str(&toml_content).expect("Failed to parse TOML");
11+
12+
let mut rust_code = String::from("// Auto-generated code from versions.toml\n\n");
13+
14+
let Value::Table(table) = config else {
15+
panic!("Invalid value type in versions.toml: {config:?}");
16+
};
17+
for (key, val) in table {
18+
let Value::String(s) = val else {
19+
panic!("Invalid value type in versions.toml: {val:?}");
20+
};
21+
rust_code.push_str(&format!(
22+
"pub const {}: &str = {s:?};\n",
23+
key.to_uppercase()
24+
));
25+
}
26+
27+
let out_dir = env::var_os("OUT_DIR").unwrap();
28+
let dest_path = Path::new(&out_dir).join("versions.rs");
29+
fs::write(&dest_path, rust_code).expect("Failed to write generated code");
30+
31+
// Tell Cargo to rerun this script if the TOML file changes
32+
println!("cargo:rerun-if-changed={toml_file}");
33+
}

stacks-common/src/libcommon.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ pub mod consts {
9797
pub const MICROSTACKS_PER_STACKS: u32 = 1_000_000;
9898
}
9999

100+
pub mod versions {
101+
include!(concat!(env!("OUT_DIR"), "/versions.rs"));
102+
}
103+
100104
/// This test asserts that the constant above doesn't change.
101105
/// This exists because the constant above is used by Epoch 2.5 instantiation code.
102106
///

stacks-signer/release-process.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to
6363
- Add cherry-picked commits to the `feat/signer-X.Y.Z.A.n.x-pr_number` branch
6464
- Merge `feat/signer-X.Y.Z.A.n.x-pr_number` into `release/signer-X.Y.Z.A.n.x`.
6565

66-
4. Open a PR to update the [CHANGELOG](./CHANGELOG.md) file in the `release/signer-X.Y.Z.A.n.x` branch.
66+
4. Open a PR to update the [CHANGELOG](./CHANGELOG.md) in the `release/signer-X.Y.Z.A.n.x` branch.
6767

6868
- Create a chore branch from `release/signer-X.Y.Z.A.n.x`, ex: `chore/signer-X.Y.Z.A.n.x-changelog`.
6969
- Add summaries of all Pull Requests to the `Added`, `Changed` and `Fixed` sections.
70+
- Update the `stacks_signer_version` string in [versions.toml](../versions.toml) to match this release.
7071

7172
- 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).
7273

stackslib/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ extern crate stacks_common;
4545
#[macro_use]
4646
pub extern crate clarity;
4747

48+
use stacks_common::versions::STACKS_NODE_VERSION;
4849
pub use stacks_common::{address, codec, types, util};
4950

5051
#[macro_use]
@@ -79,16 +80,17 @@ const BUILD_TYPE: &str = "debug";
7980
#[cfg(not(debug_assertions))]
8081
const BUILD_TYPE: &str = "release";
8182

82-
pub fn version_string(pkg_name: &str, pkg_version: &str) -> String {
83-
let git_branch = GIT_BRANCH.map(String::from).unwrap_or("".to_string());
83+
pub fn version_string(pkg_name: &str, pkg_version: Option<&str>) -> String {
84+
let pkg_version = pkg_version.unwrap_or(STACKS_NODE_VERSION);
85+
let git_branch = GIT_BRANCH.unwrap_or("");
8486
let git_commit = GIT_COMMIT.unwrap_or("");
8587
let git_tree_clean = GIT_TREE_CLEAN.unwrap_or("");
8688

8789
format!(
8890
"{} {} ({}:{}{}, {} build, {} [{}])",
8991
pkg_name,
9092
pkg_version,
91-
&git_branch,
93+
git_branch,
9294
git_commit,
9395
git_tree_clean,
9496
BUILD_TYPE,

stackslib/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ fn main() {
316316
"{}",
317317
&blockstack_lib::version_string(
318318
option_env!("CARGO_PKG_NAME").unwrap_or(&argv[0]),
319-
option_env!("CARGO_PKG_VERSION").unwrap_or("0.0.0.0")
319+
option_env!("STACKS_NODE_VERSION")
320320
)
321321
);
322322
process::exit(0);

stackslib/src/net/api/getinfo.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,7 @@ impl RPCPeerInfoData {
111111
coinbase_height: u64,
112112
ibd: bool,
113113
) -> RPCPeerInfoData {
114-
let server_version = version_string(
115-
"stacks-node",
116-
option_env!("STACKS_NODE_VERSION")
117-
.or(option_env!("CARGO_PKG_VERSION"))
118-
.unwrap_or("0.0.0.0"),
119-
);
114+
let server_version = version_string("stacks-node", option_env!("STACKS_NODE_VERSION"));
120115
let (unconfirmed_tip, unconfirmed_seq) = match chainstate.unconfirmed_state {
121116
Some(ref unconfirmed) => {
122117
if unconfirmed.num_mined_txs() > 0 {

0 commit comments

Comments
 (0)