2

How can I obtain the Polkadot release version in Rust that my node was compiled against? I want to log it at node startup. e.g. Polkadot-0.9.42

1 Answer 1

1

This doesn't seem like a substrate-specific question but rather a rust/dependency question. You're asking, if I am not mistaken, a way to pull in the string from branch= in the following:

polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.42" }

Firstly, why not embed the polkadot version directly into your node like so?

log::info!("this node was compiled against polkadot-v0.9.42");

This has the advantage of being a simple solution, and since you're updating your polkadot/substrate dependencies anyways, might as well update this loc as a part of the process.

AFAIK, this is not possible to do inside a rust program, but you can use cargo metadata to check what dependencies your program is using, and then maybe use some fancy regex to pull in the specific string, such as match something along the lines of cargo metadata | rg 'release-v0.*'

Now with that said you can certainly run this command inside rust using Command :

use std::process::Command;

    let output = Command::new("cargo")
        .arg("metadata")
        .output()
        .expect("Failed to execute command");

    if output.status.success() {
        let stdout = String::from_utf8_lossy(&output.stdout);
        // -- do pattern matching here --
        println!("Command executed successfully:\n{}", stdout);
    } else {
        let stderr = String::from_utf8_lossy(&output.stderr);
        println!("Command failed:\n{}", stderr);
    }

But again, this rabbit hole goes deep into writing a rust program just for something very simple to just open up and look.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.