Skip to content

Commit cfdfbdb

Browse files
committed
feat(hpsvm-fixture): add version export for Agave runtime in fixture report
1 parent 09ecca3 commit cfdfbdb

4 files changed

Lines changed: 68 additions & 13 deletions

File tree

Justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ bench-baseline-compare:
8686
check:
8787
cargo check --all-targets --all-features
8888

89-
# Publish all crates to crates.io (dry run)
89+
# Verify all workspace crates package and compile from their published layout
9090
publish-check:
91-
cargo publish --workspace --dry-run --allow-dirty
91+
cargo package --workspace --allow-dirty
9292

9393
# Publish all crates to crates.io
9494
publish:

crates/hpsvm-fixture/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ solana-transaction-error.workspace = true
2828
thiserror.workspace = true
2929

3030
[dev-dependencies]
31+
agave-feature-set.workspace = true
3132
solana-account.workspace = true
3233
solana-keypair.workspace = true
3334
solana-message.workspace = true

crates/hpsvm-fixture/build.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! Exports the packaged Agave runtime version for fixture report metadata.
2+
3+
use std::{
4+
env, fs,
5+
path::{Path, PathBuf},
6+
};
7+
8+
const AGAVE_FEATURE_SET_DEPENDENCY: &str = "agave-feature-set";
9+
const VERSION_ENV: &str = "HPSVM_AGAVE_FEATURE_SET_VERSION";
10+
11+
fn main() {
12+
let manifest_dir =
13+
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR must be set"));
14+
let crate_manifest = manifest_dir.join("Cargo.toml");
15+
let workspace_manifest = manifest_dir.join("..").join("..").join("Cargo.toml");
16+
17+
println!("cargo:rerun-if-changed={}", crate_manifest.display());
18+
if workspace_manifest.exists() {
19+
println!("cargo:rerun-if-changed={}", workspace_manifest.display());
20+
}
21+
22+
let version = read_dependency_version(&crate_manifest)
23+
.or_else(|| read_dependency_version(&workspace_manifest))
24+
.unwrap_or_else(|| String::from("unknown"));
25+
26+
println!("cargo:rustc-env={VERSION_ENV}={version}");
27+
}
28+
29+
fn read_dependency_version(manifest_path: &Path) -> Option<String> {
30+
fs::read_to_string(manifest_path)
31+
.ok()
32+
.and_then(|manifest| extract_dependency_version(&manifest, AGAVE_FEATURE_SET_DEPENDENCY))
33+
}
34+
35+
fn extract_dependency_version(manifest: &str, dependency_name: &str) -> Option<String> {
36+
let quoted_prefix = format!("{dependency_name} = \"");
37+
let inline_table_prefix = format!("{dependency_name} = {{");
38+
39+
manifest
40+
.lines()
41+
.map(str::trim)
42+
.filter(|line| !line.is_empty() && !line.starts_with('#'))
43+
.find_map(|line| {
44+
line.strip_prefix(&quoted_prefix)
45+
.and_then(|value| value.split('"').next())
46+
.map(str::to_owned)
47+
.or_else(|| {
48+
line.strip_prefix(&inline_table_prefix)
49+
.and_then(|_| line.split("version = \"").nth(1))
50+
.and_then(|value| value.split('"').next())
51+
.map(str::to_owned)
52+
})
53+
})
54+
}

crates/hpsvm-fixture/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ pub use crate::{
4242

4343
pub type FixtureBenchCase<'a> = (&'a str, &'a Fixture);
4444

45-
const WORKSPACE_MANIFEST: &str = include_str!("../../../Cargo.toml");
46-
4745
pub(crate) const BUILTIN_VARIANT_NAME: &str = "builtin";
4846

4947
pub(crate) fn generated_at_string() -> String {
@@ -53,15 +51,7 @@ pub(crate) fn generated_at_string() -> String {
5351
}
5452

5553
pub(crate) fn solana_runtime_version_string() -> String {
56-
WORKSPACE_MANIFEST
57-
.lines()
58-
.map(str::trim)
59-
.find_map(|line| {
60-
line.strip_prefix("agave-feature-set = \"")
61-
.and_then(|value| value.strip_suffix('"'))
62-
.map(String::from)
63-
})
64-
.unwrap_or_else(|| String::from("unknown"))
54+
option_env!("HPSVM_AGAVE_FEATURE_SET_VERSION").unwrap_or("unknown").to_owned()
6555
}
6656

6757
impl Fixture {
@@ -135,3 +125,13 @@ fn fixture_format_for_path(path: &std::path::Path) -> Result<FixtureFormat, Fixt
135125
_ => Err(FixtureError::UnsupportedFormat { path: path.display().to_string() }),
136126
}
137127
}
128+
129+
#[cfg(test)]
130+
mod tests {
131+
use super::solana_runtime_version_string;
132+
133+
#[test]
134+
fn solana_runtime_version_string_is_known() {
135+
assert_ne!(solana_runtime_version_string(), "unknown");
136+
}
137+
}

0 commit comments

Comments
 (0)