Skip to content

Commit

Permalink
Attempt to resolve build issue in cli (#106)
Browse files Browse the repository at this point in the history
* Attempt to resolve build issue in cli

* moved solana validator check to localnet command

Co-authored-by: mwrites <[email protected]>
  • Loading branch information
nickgarfield and mwrites authored Dec 5, 2022
1 parent 363e25f commit 210dd3d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 26 deletions.
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ clockwork-cron = { path = "../cron", version = "1.2.12" }
clockwork-utils = { path = "../utils", version = "1.3.11" }
chrono = { version = "0.4.19", default-features = false, features = ["alloc"] }
dirs-next = "2.0.0"
regex = "1.6.0"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
serde_yaml = "0.9.4"
Expand Down
34 changes: 12 additions & 22 deletions cli/build.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
use cargo_toml::{Dependency, Manifest};
use regex::Regex;
use std::process::Command;

fn main() {
let validator_version = get_validator_version();
let geyser_interface_version = get_geyser_interface_version();

println!("cargo:rustc-env=VALIDATOR_VERSION={}", validator_version);
println!(
"cargo:rustc-env=GEYSER_INTERFACE_VERSION={}",
geyser_interface_version
);
}

fn get_validator_version() -> String {
let output = Command::new("solana-test-validator")
.arg("--version")
.output()
.unwrap();
let version = String::from_utf8_lossy(&output.stdout);
let re = Regex::new(r"(\d{1}\.\d{2}\.\d{1})").unwrap();
let caps = re.captures(&version).unwrap();
caps.get(1)
.map_or("unknown (error parsing solana-validator version)", |m| {
m.as_str()
})
.into()
}

fn get_geyser_interface_version() -> String {
let plugin_manifest = Manifest::from_path("../plugin/Cargo.toml").unwrap();
let plugin_interface = plugin_manifest
.dependencies
.get("solana-geyser-plugin-interface")
.unwrap();

match plugin_interface {
let semver = match plugin_interface {
Dependency::Simple(version) => version.into(),
Dependency::Detailed(detail) => detail.version.as_ref().unwrap().into(),
_ => "unknown (error parsing Cargo.toml)".to_string(),
}
_ => "unknown (error parsing Plugin's Cargo.toml)".to_string(),
};

let re = Regex::new(r"(\d\.\d{2}\.\d)").unwrap();
re.captures(&semver)
.unwrap()
.get(1)
.map_or("unknown (error parsing solana-geyser-plugin-interface version)", |m| {
m.as_str()
})
.into()
}
26 changes: 22 additions & 4 deletions cli/src/processor/localnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use {
thread::state::{Thread, Trigger},
Client,
},
regex::Regex,
solana_sdk::{
native_token::LAMPORTS_PER_SOL,
program_pack::Pack,
Expand Down Expand Up @@ -46,8 +47,7 @@ pub fn start(client: &Client, program_infos: Vec<ProgramInfo>) -> Result<(), Cli
}

fn check_test_validator_version() {
// add link to the FAQ about solana version instead
let validator_version = env!("VALIDATOR_VERSION");
let validator_version = get_validator_version();
let clockwork_version = env!("GEYSER_INTERFACE_VERSION");

if validator_version != clockwork_version {
Expand All @@ -56,8 +56,9 @@ fn check_test_validator_version() {
let err = format!(
"Your Solana version and the Clockwork Engine's Solana version differs. \
This behavior is undefined. \
You have {} installed, but the Clockwork Engine requires {} \
We recommend you to run `solana-install init {}`\nDo you want to continue anyway?",
You have '{}' installed, but the Clockwork Engine requires {} \
We recommend you to run `solana-install init {}`\nDo you want to continue anyway? \
More info: https://github.com/clockwork-xyz/docs/blob/main/FAQ.md#clockwork-engine",
validator_version, clockwork_version, clockwork_version
);
println!("⚠️ \x1b[93m{}️\x1b[0m", err);
Expand All @@ -67,6 +68,23 @@ fn check_test_validator_version() {
}
}

fn get_validator_version() -> String {
Command::new("solana-test-validator")
.arg("--version")
.output()
.map_or("unknown".into(), |output| {
let version = String::from_utf8_lossy(&output.stdout);
let re = Regex::new(r"(\d\.\d{2}\.\d)").unwrap();
let caps = re.captures(&version).unwrap();
caps
.get(1)
.map_or("unknown (error parsing solana-validator version)", |m| {
m.as_str()
})
.into()
})
}

fn mint_clockwork_token(client: &Client) -> Result<Pubkey> {
// Calculate rent and pubkeys
let mint_keypair = Keypair::new();
Expand Down

0 comments on commit 210dd3d

Please sign in to comment.