Skip to content

Commit 2cfcb5c

Browse files
Nikola HristovNikola Hristov
authored andcommitted
1 parent 7f18917 commit 2cfcb5c

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ rayon = "1.8.1"
2828
serde = { version = "1.0.197", features = ["derive"] }
2929
serde_json = "1.0.114"
3030
toml = "0.8.10"
31+
32+
[build-dependencies]
33+
serde = { version = "1.0.215", features = ["derive"] }
34+
toml = "0.8.19"

build.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
use std::fs;
1+
#[derive(Deserialize)]
2+
struct Toml {
3+
package:Package,
4+
}
5+
6+
#[derive(Deserialize)]
7+
struct Package {
8+
version:String,
9+
}
210

311
fn main() {
412
println!("cargo:rerun-if-changed=Cargo.toml");
513

614
println!(
715
"cargo:rustc-env=CARGO_PKG_VERSION={}",
8-
fs::read_to_string("Cargo.toml")
9-
.expect("Failed to read Cargo.toml.")
10-
.lines()
11-
.find(|line| line.starts_with("version"))
12-
.unwrap()
13-
.split('=')
14-
.nth(1)
15-
.expect("Invalid version line format.")
16-
.trim()
17-
.trim_matches('"')
16+
toml::from_str::<Toml>(&std::fs::read_to_string("Cargo.toml").expect("Cannot Cargo.toml."))
17+
.expect("Cannot toml.")
18+
.package
19+
.version
1820
);
1921
}
22+
23+
use serde::Deserialize;

0 commit comments

Comments
 (0)