File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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]
452459fn 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}
You can’t perform that action at this time.
0 commit comments