Skip to content

Commit 1511a98

Browse files
authored
Merge pull request #2036 from mintlayer/add_version_response_to_binaries
App-version-related improvements
2 parents f99ef5f + f969d3e commit 1511a98

File tree

52 files changed

+689
-122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+689
-122
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ members = [
6363
"test-utils", # Various utilities for tests.
6464
"tokens-accounting", # Tokens accounting
6565
"utils", # Various utilities.
66+
"utils/build_utils", # Build-related utilities.
6667
"utils/networking", # Various async/tokio utilities.
6768
"utxo", # Utxo and related utilities (cache, undo, etc.).
6869
"wallet", # Wallet primitives.
@@ -251,6 +252,7 @@ socket2 = "0.5"
251252
sscanf = "0.4"
252253
static_assertions = "1.1"
253254
strum = { version = "0.26", default-features = false, features = ["derive"] }
255+
substrate-build-script-utils = "11.0"
254256
syn = "2.0"
255257
tap = "1.0"
256258
tempfile = "3.3"

api-server/scanner-daemon/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ utils-networking = { path = "../../utils/networking" }
1919
clap = { workspace = true, features = ["derive"] }
2020
thiserror.workspace = true
2121
tokio = { workspace = true, features = ["full"] }
22+
23+
[build-dependencies]
24+
build_utils = { path = "../../utils/build_utils" }

api-server/scanner-daemon/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2026 RBB S.r.l
2+
// opensource@mintlayer.org
3+
// SPDX-License-Identifier: MIT
4+
// Licensed under the MIT License;
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
fn main() {
17+
build_utils::emit_git_env_vars();
18+
}

api-server/scanner-daemon/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
use clap::Parser;
1717

1818
use api_server_common::{Network, PostgresConfig};
19-
use utils::clap_utils;
19+
use utils::{app_version_with_git_info, clap_utils};
2020
use utils_networking::NetworkAddressWithPort;
2121

2222
#[derive(Parser, Debug)]
2323
#[clap(mut_args(clap_utils::env_adder("API_SCANNER_DAEMON")))]
24+
#[clap(version(app_version_with_git_info!().to_pretty_string()))]
2425
pub struct ApiServerScannerArgs {
2526
/// Network
2627
#[arg(long, value_enum, default_value_t = Network::Mainnet)]

api-server/web-server/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ serde_json.workspace = true
2727
thiserror.workspace = true
2828
tokio = { workspace = true }
2929
tower-http = { workspace = true, features = ["cors"] }
30+
31+
[build-dependencies]
32+
build_utils = { path = "../../utils/build_utils" }

api-server/web-server/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2026 RBB S.r.l
2+
// opensource@mintlayer.org
3+
// SPDX-License-Identifier: MIT
4+
// Licensed under the MIT License;
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
fn main() {
17+
build_utils::emit_git_env_vars();
18+
}

api-server/web-server/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ use clap::Parser;
1919

2020
use api_server_common::{Network, PostgresConfig};
2121
use tokio::net::TcpListener;
22-
use utils::clap_utils;
22+
use utils::{app_version_with_git_info, clap_utils};
2323
use utils_networking::NetworkAddressWithPort;
2424

2525
const LISTEN_ADDRESS: &str = "127.0.0.1:3000";
2626

2727
#[derive(Debug, Parser)]
2828
#[clap(mut_args(clap_utils::env_adder("API_WEB_SRV")))]
29+
#[clap(version(app_version_with_git_info!().to_pretty_string()))]
2930
pub struct ApiServerWebServerConfig {
3031
/// Network
3132
/// Default: `testnet`

build-tools/codecheck/codecheck.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import fnmatch
55
import itertools
66
import os
7+
import pathlib
78
import re
89
import sys
910
import tomllib
1011

12+
PROJECT_ROOT_DIR = pathlib.Path(__file__).resolve().parent.parent.parent
13+
1114
SCALECODEC_RE = r'\bparity_scale_codec(_derive)?::'
1215
JSONRPSEE_RE = r'\bjsonrpsee[_a-z0-9]*::'
1316

@@ -145,6 +148,32 @@ def check_workspace_and_package_versions_equal():
145148
return result
146149

147150

151+
# Ensure that each crate's Cargo.toml has a version field and it's always "version.workspace = true".
152+
def check_crate_version_inherits_workspace_version():
153+
print("==== Ensuring that each crate's version inherits its value from the workspace")
154+
155+
result = True
156+
157+
for path in cargo_config_files():
158+
path = pathlib.Path(path).resolve()
159+
if path.name == "Cargo.toml" and not path.parent == PROJECT_ROOT_DIR:
160+
with open(path, "rb") as file:
161+
rel_path = path.relative_to(PROJECT_ROOT_DIR)
162+
toml_file = tomllib.load(file)
163+
version = toml_file["package"].get("version")
164+
165+
if version is None:
166+
print(f"{rel_path}: missing 'package.version', the version defaults to 0.0.0")
167+
result = False
168+
elif not isinstance(version, dict) or version.get("workspace") != True:
169+
print(f"{rel_path}: the package version must be inherited from the workspace (use 'version.workspace = true')")
170+
result = False
171+
172+
print()
173+
174+
return result
175+
176+
148177
# Retrieve an item from arbitrarily nested dicts given a list of keys.
149178
# E.g. get_from_nested_dicts({'a': {'b': 1, 'c': 2}}, ['a', 'b']) will
150179
# return 1.
@@ -385,6 +414,7 @@ def run_checks():
385414
check_local_licenses(),
386415
check_crate_versions(),
387416
check_workspace_and_package_versions_equal(),
417+
check_crate_version_inherits_workspace_version(),
388418
check_dependency_versions_patch_version(),
389419
check_todos(),
390420
check_trailing_whitespaces(),
@@ -393,5 +423,8 @@ def run_checks():
393423

394424

395425
if __name__ == '__main__':
426+
# Note: this script expects the current directory to be the project root.
427+
os.chdir(PROJECT_ROOT_DIR)
428+
396429
if not run_checks():
397430
sys.exit(1)

common/src/primitives/semver.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ use std::str::FromStr;
1818
use serde::Serialize;
1919
use serialization::{Decode, Encode};
2020

21+
// Note: this is not a real "semantic version" because it lacks the prerelease and build metadata
22+
// parts. However it's not easy to change, since it's part of the p2p protocol, namely the Hello
23+
// and HelloAck messages (also, it's probably not a good idea to send the additional info over
24+
// the network anyway).
25+
// TODO: perhaps it should be renamed at least.
2126
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Encode, Decode, Copy, Clone, Serialize)]
2227
pub struct SemVer {
2328
pub major: u8,

0 commit comments

Comments
 (0)