Skip to content

Commit 33dd37d

Browse files
feat: expose resvg version (#113)
1 parent 145caf8 commit 33dd37d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

build.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use std::fs;
2+
3+
fn main() {
4+
let lock = fs::read_to_string("Cargo.lock").unwrap();
5+
6+
let mut lines = lock.lines();
7+
while let Some(line) = lines.next() {
8+
if line.trim() == "name = \"resvg\"" {
9+
if let Some(version_line) = lines.find(|l| l.trim().starts_with("version")) {
10+
let version = version_line
11+
.split('=')
12+
.nth(1)
13+
.unwrap()
14+
.trim()
15+
.trim_matches('"');
16+
17+
println!("cargo:rustc-env=DEP_RESVG_VERSION={version}");
18+
break;
19+
}
20+
}
21+
}
22+
}

src/rust/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,20 @@ fn get_author() -> &'static str {
446446
env!("CARGO_PKG_AUTHORS").to_owned()
447447
})
448448
}
449+
fn get_resvg_version() -> &'static str{
450+
static RESVG_VERSION : std::sync::OnceLock<String> =std::sync::OnceLock::new();
451+
452+
RESVG_VERSION.get_or_init(||{
453+
env!("DEP_RESVG_VERSION").to_owned()
454+
})
455+
}
449456

450457
/// A Python module implemented in Rust.
451458
#[pymodule]
452459
fn resvg_py(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
453460
m.add("__version__", get_version())?;
454461
m.add("__author__", get_author())?;
462+
m.add("__resvg_version__", get_resvg_version())?;
455463
m.add_function(wrap_pyfunction!(svg_to_bytes, m)?)?;
456464
Ok(())
457465
}

0 commit comments

Comments
 (0)