-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
35 lines (30 loc) · 944 Bytes
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use {cargo_lock::Lockfile, std::collections::HashSet};
fn main() -> anyhow::Result<()> {
vergen::Emitter::default()
.add_instructions(&vergen::BuildBuilder::all_build()?)?
.add_instructions(&vergen::RustcBuilder::all_rustc()?)?
.emit()?;
// vergen git version does not looks cool
println!(
"cargo:rustc-env=GIT_VERSION={}",
git_version::git_version!()
);
// Extract Solana version
let lockfile = Lockfile::load("Cargo.lock")?;
println!(
"cargo:rustc-env=SOLANA_SDK_VERSION={}",
get_pkg_version(&lockfile, "solana-sdk")
);
Ok(())
}
fn get_pkg_version(lockfile: &Lockfile, pkg_name: &str) -> String {
lockfile
.packages
.iter()
.filter(|pkg| pkg.name.as_str() == pkg_name)
.map(|pkg| pkg.version.to_string())
.collect::<HashSet<_>>()
.into_iter()
.collect::<Vec<_>>()
.join(",")
}