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

feat(katana): build version #2590

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion bin/katana/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ mod node;
use anyhow::Result;
use clap::{Args, CommandFactory, Parser, Subcommand};
use clap_complete::Shell;
use katana_node::version::VERSION;

#[derive(Parser)]
#[command(name = "katana", author, version, about, long_about = None)]
#[command(name = "katana", author, version = VERSION, about, long_about = None)]
pub struct Cli {
#[command(subcommand)]
commands: Option<Commands>,
Expand Down
5 changes: 5 additions & 0 deletions crates/katana/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ tracing.workspace = true

strum.workspace = true
strum_macros.workspace = true
const_format = "0.2.33"

[build-dependencies]
vergen = { version = "9.0.0", features = [ "build", "cargo", "emit_and_set" ] }
vergen-gitcl = { version = "1.0.0", features = [ "build", "cargo", "rustc", "si" ] }

[features]
starknet-messaging = [ "katana-core/starknet-messaging" ]
26 changes: 26 additions & 0 deletions crates/katana/node/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::env;
use std::error::Error;

use vergen::{BuildBuilder, Emitter};
use vergen_gitcl::GitclBuilder;

fn main() -> Result<(), Box<dyn Error>> {
let build = BuildBuilder::default().build_timestamp(true).build()?;
let gitcl =
GitclBuilder::default().describe(true, false, None).dirty(true).sha(true).build()?;

// Emit the instructions
Emitter::default().add_instructions(&build)?.add_instructions(&gitcl)?.emit_and_set()?;
kariy marked this conversation as resolved.
Show resolved Hide resolved

let sha = dbg!(env::var("VERGEN_GIT_SHA"))?;
kariy marked this conversation as resolved.
Show resolved Hide resolved
kariy marked this conversation as resolved.
Show resolved Hide resolved
let is_dirty = env::var("VERGEN_GIT_DIRTY")? == "true";

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove debug print statement, sensei!

The dbg! macro should be removed from production code.

-    let sha = dbg!(env::var("VERGEN_GIT_SHA"))?;
+    let sha = env::var("VERGEN_GIT_SHA")?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let sha = dbg!(env::var("VERGEN_GIT_SHA"))?;
let is_dirty = env::var("VERGEN_GIT_DIRTY")? == "true";
let sha = env::var("VERGEN_GIT_SHA")?;
let is_dirty = env::var("VERGEN_GIT_DIRTY")? == "true";

// > git describe --always --tags
// if not on a tag: v0.2.0-beta.3-82-g1939939b
// if on a tag: v0.2.0-beta.3
let not_on_tag = env::var("VERGEN_GIT_DESCRIBE")?.ends_with(&format!("-g{sha}"));
let is_dev = is_dirty || not_on_tag;
println!("cargo:rustc-env=DEV_BUILD_SUFFIX={}", if is_dev { "-dev" } else { "" });
kariy marked this conversation as resolved.
Show resolved Hide resolved

Ok(())
}
1 change: 1 addition & 0 deletions crates/katana/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod config;
pub mod exit;
pub mod version;

use std::future::IntoFuture;
use std::net::SocketAddr;
Expand Down
15 changes: 15 additions & 0 deletions crates/katana/node/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// The latest version from Cargo.toml.
pub const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");

/// The SHA of the latest commit.
pub const VERGEN_GIT_SHA: &str = env!("VERGEN_GIT_SHA");

// > 1.0.0-alpha.19 (77d4800)
// > if on dev (ie dirty): 1.0.0-alpha.19-dev (77d4800)
pub const VERSION: &str = const_format::concatcp!(
env!("CARGO_PKG_VERSION"),
env!("DEV_BUILD_SUFFIX"),
" (",
VERGEN_GIT_SHA,
")"
);
Loading