Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oneliner to set signer version at compile time with STACKS_NODE_VERSION #5016

Merged
merged 5 commits into from
Jul 30, 2024

Conversation

wileyj
Copy link
Contributor

@wileyj wileyj commented Jul 28, 2024

ref #5002

This is the minimally viable change to allow setting the signer version at build time, defaulting to CARGO_PKG_VERSION.
Since the signer already uses the same build process as stacks-core, the correct version will already be set as STACKS_NODE_VERSION, so that is why that env var is used here vs something more suited like SIGNER_VERSION.
using SIGNER_VERSION would simply require some downstream changes (mainly to CI workflows), but is trivial if that env var is desired.

I did set out to try and expose a version string like /v2/info, but due to how Clap was expecting a str, i wasn't able to get all the desired values returned correctly.

~/stacks-core$ cargo run --bin stacks-signer -- --version
warning: /home/wileyj/stacks-core/testnet/stacks-node/Cargo.toml: `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition
(in the `reqwest` dependency)
   Compiling stacks-signer v0.0.1 (/home/wileyj/stacks-core/stacks-signer)
    Finished `dev` profile [optimized + debuginfo] target(s) in 5.22s
     Running `target/debug/stacks-signer --version`
stacks-signer 0.0.1

~/stacks-core$ STACKS_NODE_VERSION=2.5.0.0.5.1 cargo run --bin stacks-signer -- --version
warning: /home/wileyj/stacks-core/testnet/stacks-node/Cargo.toml: `default_features` is deprecated in favor of `default-features` and will not work in the 2024 edition
(in the `reqwest` dependency)
   Compiling stackslib v0.0.1 (/home/wileyj/stacks-core/stackslib)
   Compiling libsigner v0.0.1 (/home/wileyj/stacks-core/libsigner)
   Compiling stacks-signer v0.0.1 (/home/wileyj/stacks-core/stacks-signer)
    Finished `dev` profile [optimized + debuginfo] target(s) in 11.66s
     Running `target/debug/stacks-signer --version`
stacks-signer 2.5.0.0.5.1

this is what i tried to emulate /v2/info with, but wasn't able to figure out how to return the full output as a str:

const GIT_BRANCH: Option<&'static str> = option_env!("GIT_BRANCH");
const GIT_COMMIT: Option<&'static str> = option_env!("GIT_COMMIT");
#[cfg(debug_assertions)]
const BUILD_TYPE: &'static str = "debug";
#[cfg(not(debug_assertions))]
const BUILD_TYPE: &'static str = "release";
fn version_string<'life>() -> &'life str {
    let pkg_version = option_env!("STACKS_NODE_VERSION").unwrap_or(env!("CARGO_PKG_VERSION"));
    let git_branch = GIT_BRANCH.unwrap_or("");
    let git_commit = GIT_COMMIT.unwrap_or("");
    let formatted = format!(
        "{} ({}:{}, {} build, {} [{}])",
        pkg_version,
        git_branch,
        git_commit,
        BUILD_TYPE,
        std::env::consts::OS,
        std::env::consts::ARCH
    );
    println!("formatted= {}", formatted);
    return formatted;
}

formatted prints the expected output:

formatted= 2.5.0.0.5.1 (release/signer-2.5.0.0.1:56eec5912, debug build, linux [x86_64])

but Clap is expecting it to be a str.

@wileyj wileyj requested a review from a team as a code owner July 29, 2024 18:08
@wileyj
Copy link
Contributor Author

wileyj commented Jul 29, 2024

with @ASuciuX help, we found a way to return the desired version output in the format that Clap was expecting.

stacks-signer/Cargo.toml Outdated Show resolved Hide resolved
@ASuciuX ASuciuX linked an issue Jul 30, 2024 that may be closed by this pull request
Copy link
Contributor

@obycode obycode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

@wileyj wileyj added this pull request to the merge queue Jul 30, 2024
Merged via the queue into develop with commit 409fb28 Jul 30, 2024
1 check passed
@wileyj wileyj deleted the feat/signer-version-env branch July 30, 2024 17:03
@blockstack-devops
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@stacks-network stacks-network locked as resolved and limited conversation to collaborators Oct 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to set signer version via env var at build time
7 participants