Skip to content

Commit 8363f57

Browse files
committed
feat: use versions.yaml with a build script
1 parent 5fab220 commit 8363f57

File tree

9 files changed

+91
-11
lines changed

9 files changed

+91
-11
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to
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_VERSION` string in [stackslib/src/lib.rs](../stackslib/src/lib.rs) to match this release.
71+
- Update the `stacks_node_version` string in [versions.toml](../versions.toml) to match this release.
7272

7373
- 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).
7474

libsigner/src/libsigner.rs

Lines changed: 3 additions & 5 deletions
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::{
@@ -63,9 +64,6 @@ pub use crate::runloop::{RunningSigner, Signer, SignerRunLoop};
6364
pub use crate::session::{SignerSession, StackerDBSession};
6465
pub use crate::signer_set::{Error as ParseSignerEntriesError, SignerEntries};
6566

66-
/// The version string for the signer
67-
pub const SIGNER_VERSION: &str = "3.0.0.0.0.1";
68-
6967
/// A trait for message slots used for signer communication
7068
pub trait MessageSlotID: Sized + Eq + Hash + Debug + Copy {
7169
/// The contract identifier for the message slot in stacker db
@@ -83,7 +81,7 @@ pub trait SignerMessage<T: MessageSlotID>: StacksMessageCodec {
8381
lazy_static! {
8482
/// The version string for the signer
8583
pub static ref VERSION_STRING: String = {
86-
let pkg_version = option_env!("STACKS_NODE_VERSION").or(Some(SIGNER_VERSION));
84+
let pkg_version = option_env!("STACKS_NODE_VERSION").or(Some(STACKS_SIGNER_VERSION));
8785
version_string("stacks-signer", pkg_version)
8886
};
8987
}
@@ -92,7 +90,7 @@ lazy_static! {
9290
fn test_version_string() {
9391
let version = VERSION_STRING.to_string();
9492
assert_eq!(
95-
version.contains(format!("stacks-signer {}", SIGNER_VERSION).as_str()),
93+
version.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str()),
9694
true
9795
);
9896
}

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"
@@ -79,6 +80,9 @@ bech32_std = []
7980
bech32_strict = []
8081
strason = []
8182

83+
[build-dependencies]
84+
toml = "0.5.6"
85+
8286
[target.'cfg(all(any(target_arch = "x86_64", target_arch = "x86", target_arch = "aarch64"), not(any(target_os="windows"))))'.dependencies]
8387
sha2 = { version = "0.10", features = ["asm"] }
8488

stacks-common/build.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use std::path::Path;
2+
use std::{env, fs};
3+
use toml::Value;
4+
5+
fn main() {
6+
let toml_content =
7+
fs::read_to_string("../versions.toml").expect("Failed to read versions.toml");
8+
9+
let config: Value = toml::from_str(&toml_content).expect("Failed to parse TOML");
10+
11+
let mut rust_code = String::from("// Auto-generated code from versions.toml\n\n");
12+
13+
fn generate_constants(value: &Value, prefix: &str, code: &mut String) {
14+
match value {
15+
Value::Table(table) => {
16+
for (key, val) in table {
17+
let new_prefix = if prefix.is_empty() {
18+
key.to_string()
19+
} else {
20+
format!("{}_{}", prefix, key)
21+
};
22+
generate_constants(val, &new_prefix, code);
23+
}
24+
}
25+
Value::Array(arr) => {
26+
code.push_str(&format!(
27+
"pub const {}: &[&str] = &[{}];\n",
28+
prefix.to_uppercase(),
29+
arr.iter()
30+
.map(|v| format!("\"{}\"", v.as_str().unwrap_or("")))
31+
.collect::<Vec<_>>()
32+
.join(", ")
33+
));
34+
}
35+
_ => {
36+
let const_value = match value {
37+
Value::String(s) => format!("\"{}\"", s),
38+
Value::Integer(n) => n.to_string(),
39+
Value::Float(f) => f.to_string(),
40+
Value::Boolean(b) => b.to_string(),
41+
_ => "\"\"".to_string(),
42+
};
43+
code.push_str(&format!(
44+
"pub const {}: {} = {};\n",
45+
prefix.to_uppercase(),
46+
if value.is_str() {
47+
"&str"
48+
} else if value.is_integer() {
49+
"i64"
50+
} else if value.is_float() {
51+
"f64"
52+
} else if value.is_bool() {
53+
"bool"
54+
} else {
55+
"&str"
56+
},
57+
const_value
58+
));
59+
}
60+
}
61+
}
62+
63+
generate_constants(&config, "", &mut rust_code);
64+
65+
let out_dir = env::var_os("OUT_DIR").unwrap();
66+
let dest_path = Path::new(&out_dir).join("versions.rs");
67+
fs::write(&dest_path, rust_code).expect("Failed to write generated code");
68+
69+
// Tell Cargo to rerun this script if the TOML file changes
70+
println!("cargo:rerun-if-changed=../versions.toml");
71+
}

stacks-common/src/libcommon.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ pub mod consts {
9595
pub const NETWORK_ID_TESTNET: u32 = 0xff000000;
9696
}
9797

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

stacks-signer/release-process.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The timing of the next Stacking cycle can be found [here](https://stx.eco/dao/to
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 `SIGNER_VERSION` string in [libsigner/src/libsigner.rs](../libsigner/src/libsigner.rs) to match this release.
70+
- Update the `stacks_signer_version` string in [versions.toml](../versions.toml) to match this release.
7171

7272
- 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).
7373

stackslib/src/lib.rs

Lines changed: 2 additions & 4 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]
@@ -78,11 +79,8 @@ const BUILD_TYPE: &'static str = "debug";
7879
#[cfg(not(debug_assertions))]
7980
const BUILD_TYPE: &'static str = "release";
8081

81-
/// The version string for the stackslib
82-
pub const STACKS_VERSION: &str = "3.0.0.0.0";
83-
8482
pub fn version_string(pkg_name: &str, pkg_version: Option<&str>) -> String {
85-
let pkg_version = pkg_version.unwrap_or(STACKS_VERSION);
83+
let pkg_version = pkg_version.unwrap_or(STACKS_NODE_VERSION);
8684
let git_branch = GIT_BRANCH
8785
.map(|x| format!("{}", x))
8886
.unwrap_or("".to_string());

versions.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Update these values when a new release is created.
2+
# `stacks-common/build.rs` will automatically update `versions.rs` with these values.
3+
stacks_node_version = "3.0.0.0.2"
4+
stacks_signer_version = "3.0.0.0.2.0"

0 commit comments

Comments
 (0)