Skip to content

Commit

Permalink
feat: add commit hash to generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Dec 11, 2022
1 parent d550b41 commit fcf4cb5
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 0 deletions.
201 changes: 201 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ edition = "2021"
description = """
Tool for generating the StarkNet JSON-RPC code used in starknet-rs
"""
build = "src/build.rs"

[dependencies]
anyhow = "1.0.66"
indexmap = { version = "1.9.2", features = ["serde"] }
regex = "1.7.0"
serde = { version = "1.0.149", features = ["derive"] }
serde_json = "1.0.89"

[build-dependencies]
built = { version = "0.5.2", features = ["git2"] }
3 changes: 3 additions & 0 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
built::write_built_file().expect("Failed to acquire build-time information")
}
13 changes: 13 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use crate::spec::*;

mod spec;

mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

const MAX_LINE_LENGTH: usize = 100;

const TARGET_VERSION: SpecVersion = SpecVersion::V0_2_1;
Expand Down Expand Up @@ -601,6 +605,15 @@ fn main() {
println!("// To change the code generated, modify the codegen tool instead:");
println!("// https://github.com/xJonathanLEI/starknet-jsonrpc-codegen");
println!();
println!("// Code generated with version:");
match built_info::GIT_COMMIT_HASH {
Some(commit_hash) => println!(
"// https://github.com/xJonathanLEI/starknet-jsonrpc-codegen#{}",
commit_hash
),
None => println!(" <Unable to determine Git commit hash>"),
}
println!();

if !profile.ignore_types.is_empty() {
println!("// These types are ignored from code generation. Implement them manually:");
Expand Down

0 comments on commit fcf4cb5

Please sign in to comment.